On Tue, Mar 08, 2016 at 02:23:40PM +0100, Ingo Molnar wrote: > > * tip-bot for Jiri Olsa <tipbot@xxxxxxxxx> 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@xxxxxxxxxx> --- 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 -- To unsubscribe from this list: send the line "unsubscribe linux-tip-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html
![]() |