From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751293AbcCHSmt (ORCPT ); Tue, 8 Mar 2016 13:42:49 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50023 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750747AbcCHSmj (ORCPT ); Tue, 8 Mar 2016 13:42:39 -0500 Date: Tue, 8 Mar 2016 19:42:30 +0100 From: Jiri Olsa To: Ingo Molnar 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 Message-ID: <20160308184230.GB7897@krava.redhat.com> References: <20160303095348.GA24511@krava.redhat.com> <20160308132340.GA7914@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20160308132340.GA7914@gmail.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 08, 2016 at 02:23:40PM +0100, Ingo Molnar wrote: > > * tip-bot for Jiri Olsa 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 --- 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