Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1353313

[PATCH][perf/core] perf tools: Omit unnecessary cast in perf_pmu__parse_scale

From Jiri Olsa <jolsa@redhat.com>
Newsgroups linux.kernel
Subject [PATCH][perf/core] perf tools: Omit unnecessary cast in perf_pmu__parse_scale
Date 2016-03-08 19:50 +0100
Message-ID <rauRI-4OA-9@gated-at.bofh.it> (permalink)
References <r8yd4-550-3@gated-at.bofh.it> <r9fBo-3k0-5@gated-at.bofh.it> <rapS2-1q3-17@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[tip:perf/core] perf tools: Fix locale handling in pmu parsing tip-bot for Jiri Olsa <tipbot@zytor.com> - 2016-03-05 09:20 +0100
  Re: [tip:perf/core] perf tools: Fix locale handling in pmu parsing Ingo Molnar <mingo@kernel.org> - 2016-03-08 14:30 +0100
    [PATCH][perf/core] perf tools: Omit unnecessary cast in  perf_pmu__parse_scale Jiri Olsa <jolsa@redhat.com> - 2016-03-08 19:50 +0100
      Re: [PATCH][perf/core] perf tools: Omit unnecessary cast in  perf_pmu__parse_scale Arnaldo Carvalho de Melo <acme@redhat.com> - 2016-03-09 14:50 +0100
      [tip:perf/core] perf tools: Omit unnecessary cast in  perf_pmu__parse_scale tip-bot for Jiri Olsa <tipbot@zytor.com> - 2016-03-11 09:50 +0100

csiph-web