lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20160308184230.GB7897@krava.redhat.com>
Date:	Tue, 8 Mar 2016 19:42:30 +0100
From:	Jiri Olsa <jolsa@...hat.com>
To:	Ingo Molnar <mingo@...nel.org>
Cc:	acme@...hat.com, hpa@...or.com, jolsa@...nel.org,
	a.p.zijlstra@...llo.nl, tglx@...utronix.de, dsahern@...il.com,
	namhyung@...nel.org, linux-kernel@...r.kernel.org,
	mingo@...hat.com, linux-tip-commits@...r.kernel.org
Subject: [PATCH][perf/core] perf tools: Omit unnecessary cast in
 perf_pmu__parse_scale

On Tue, Mar 08, 2016 at 02:23:40PM +0100, Ingo Molnar wrote:
> 
> * tip-bot for Jiri Olsa <tipbot@...or.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@...nel.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ