From: Jiri Olsa <jolsa@redhat.com>
To: Ingo Molnar <mingo@kernel.org>
Cc: acme@redhat.com, hpa@zytor.com, jolsa@kernel.org,
a.p.zijlstra@chello.nl, tglx@linutronix.de, dsahern@gmail.com,
namhyung@kernel.org, linux-kernel@vger.kernel.org,
mingo@redhat.com, linux-tip-commits@vger.kernel.org
Subject: [PATCH][perf/core] perf tools: Omit unnecessary cast in perf_pmu__parse_scale
Date: Tue, 8 Mar 2016 19:42:30 +0100 [thread overview]
Message-ID: <20160308184230.GB7897@krava.redhat.com> (raw)
In-Reply-To: <20160308132340.GA7914@gmail.com>
On Tue, Mar 08, 2016 at 02:23:40PM +0100, Ingo Molnar wrote:
>
> * tip-bot for Jiri Olsa <tipbot@zytor.com> wrote:
>
> > @@ -135,6 +146,8 @@ static int perf_pmu__parse_scale(struct perf_pmu_alias *alias, char *dir, char *
> > /* restore locale */
> > setlocale(LC_NUMERIC, lc);
> >
> > + free((char *) lc);
> > +
>
> Btw., minor side note: why does 'lc' have to be case to 'char *'?
>
> In the kernel kfree() takes 'const void *':
>
> include/linux/slab.h:void kfree(const void *);
>
> which will accept all pointer types. That avoids unnecessary and fragile type
> casts.
libc free takes only non const pointers:
util/pmu.c: In function ‘perf_pmu__parse_scale’:
util/pmu.c:149:7: error: passing argument 1 of ‘free’ discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
free(lc);
^
In file included from /home/jolsa/kernel/linux-perf/tools/include/linux/kernel.h:6:0,
from /home/jolsa/kernel/linux-perf/tools/include/linux/list.h:6,
from util/pmu.c:1:
/usr/include/stdlib.h:483:13: note: expected ‘void *’ but argument is of type ‘const char *’
extern void free (void *__ptr) __THROW;
but we could actually make it char* from the beginning..
for some reason I thought setlocale returns const ptr,
and I did not check.. fix attached
jirka
---
There's no need to used const char pointer,
we can used char pointer from the beginning
and omit unnecessary cast.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
tools/perf/util/pmu.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index d8cd038baed2..adef23b1352e 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -98,7 +98,7 @@ static int perf_pmu__parse_scale(struct perf_pmu_alias *alias, char *dir, char *
char scale[128];
int fd, ret = -1;
char path[PATH_MAX];
- const char *lc;
+ char *lc;
snprintf(path, PATH_MAX, "%s/%s.scale", dir, name);
@@ -146,7 +146,7 @@ static int perf_pmu__parse_scale(struct perf_pmu_alias *alias, char *dir, char *
/* restore locale */
setlocale(LC_NUMERIC, lc);
- free((char *) lc);
+ free(lc);
ret = 0;
error:
--
2.4.3
next prev parent reply other threads:[~2016-03-08 18:42 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-29 19:21 [GIT PULL 00/11] perf/core improvements and fixes Arnaldo Carvalho de Melo
2016-02-29 19:21 ` [PATCH 01/11] perf tools: Fix python extension build Arnaldo Carvalho de Melo
2016-02-29 19:21 ` [PATCH 02/11] perf trace: Check and discard not only 'nr' but also '__syscall_nr' Arnaldo Carvalho de Melo
2016-02-29 19:21 ` [PATCH 03/11] tracing/syscalls: Rename "/format" tracepoint field name "nr" to "__syscall_nr: Arnaldo Carvalho de Melo
2016-02-29 19:22 ` [PATCH 04/11] tools lib traceevent: Split pevent_print_event() into specific functionality functions Arnaldo Carvalho de Melo
2016-02-29 19:22 ` [PATCH 05/11] perf stat: Check existence of frontend/backed stalled cycles Arnaldo Carvalho de Melo
2016-03-03 8:28 ` Ingo Molnar
2016-03-03 12:49 ` Arnaldo Carvalho de Melo
2016-03-03 12:50 ` Arnaldo Carvalho de Melo
2016-02-29 19:22 ` [PATCH 06/11] perf data: Support converting data from bpf_perf_event_output() Arnaldo Carvalho de Melo
2016-02-29 19:22 ` [PATCH 07/11] perf data: Explicitly set byte order for integer types Arnaldo Carvalho de Melo
2016-02-29 19:22 ` [PATCH 08/11] perf record: Use WARN_ONCE to replace 'if' condition Arnaldo Carvalho de Melo
2016-02-29 19:22 ` [PATCH 09/11] perf record: Extract synthesize code to record__synthesize() Arnaldo Carvalho de Melo
2016-02-29 19:22 ` [PATCH 10/11] perf record: Introduce record__finish_output() to finish a perf.data Arnaldo Carvalho de Melo
2016-02-29 19:22 ` [PATCH 11/11] perf record: Ensure return non-zero rc when mmap fail Arnaldo Carvalho de Melo
2016-03-03 8:21 ` [GIT PULL 00/11] perf/core improvements and fixes Ingo Molnar
2016-03-03 9:15 ` Jiri Olsa
2016-03-03 9:53 ` [PATCH] perf tools: Fix locale handling in pmu parsing Jiri Olsa
2016-03-03 16:20 ` Andi Kleen
2016-03-05 8:14 ` [tip:perf/core] " tip-bot for Jiri Olsa
2016-03-08 13:23 ` Ingo Molnar
2016-03-08 18:42 ` Jiri Olsa [this message]
2016-03-09 13:43 ` [PATCH][perf/core] perf tools: Omit unnecessary cast in perf_pmu__parse_scale Arnaldo Carvalho de Melo
2016-03-11 8:46 ` [tip:perf/core] " tip-bot for Jiri Olsa
2016-03-03 14:38 ` [GIT PULL 00/11] perf/core improvements and fixes Arnaldo Carvalho de Melo
2016-03-05 8:08 ` Ingo Molnar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160308184230.GB7897@krava.redhat.com \
--to=jolsa@redhat.com \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@redhat.com \
--cc=dsahern@gmail.com \
--cc=hpa@zytor.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®