2009-12-06 09:16:31

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 4/5] tools/perf/util: correct size computation

From: Julia Lawall <[email protected]>

The size argument to zalloc should be the size of desired structure,
not the pointer to it.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@expression@
expression *x;
@@

x =
<+...
-sizeof(x)
+sizeof(*x)
...+>// </smpl>

Signed-off-by: Julia Lawall <[email protected]>

---
tools/perf/util/parse-events.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff -u -p a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -197,7 +197,7 @@ struct tracepoint_path *tracepoint_id_to
if (id == config) {
closedir(evt_dir);
closedir(sys_dir);
- path = zalloc(sizeof(path));
+ path = zalloc(sizeof(*path));
path->system = malloc(MAX_EVENT_LENGTH);
if (!path->system) {
free(path);


2009-12-06 09:25:27

by Julia Lawall

[permalink] [raw]
Subject: [tip:perf/urgent] perf tools: Correct size computation in tracepoint_id_to_path()

Commit-ID: 59b4caeb797494043f5f3b98a610f5d9b75eefa3
Gitweb: http://git.kernel.org/tip/59b4caeb797494043f5f3b98a610f5d9b75eefa3
Author: Julia Lawall <[email protected]>
AuthorDate: Sun, 6 Dec 2009 10:16:30 +0100
Committer: Ingo Molnar <[email protected]>
CommitDate: Sun, 6 Dec 2009 10:21:59 +0100

perf tools: Correct size computation in tracepoint_id_to_path()

The size argument to zalloc should be the size of desired
structure, not the pointer to it.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@expression@
expression *x;
@@

x =
<+...
-sizeof(x)
+sizeof(*x)
...+>// </smpl>

Signed-off-by: Julia Lawall <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Mike Galbraith <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
LKML-Reference: <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
---
tools/perf/util/parse-events.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 9e5dbd6..448a13b 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -197,7 +197,7 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config)
if (id == config) {
closedir(evt_dir);
closedir(sys_dir);
- path = zalloc(sizeof(path));
+ path = zalloc(sizeof(*path));
path->system = malloc(MAX_EVENT_LENGTH);
if (!path->system) {
free(path);

2009-12-07 10:08:28

by walter harms

[permalink] [raw]
Subject: Re: [PATCH 4/5] tools/perf/util: correct size computation



Julia Lawall schrieb:
> From: Julia Lawall <[email protected]>
>
> The size argument to zalloc should be the size of desired structure,
> not the pointer to it.
>
> The semantic patch that makes this change is as follows:
> (http://coccinelle.lip6.fr/)
>
> // <smpl>
> @expression@
> expression *x;
> @@
>
> x =
> <+...
> -sizeof(x)
> +sizeof(*x)
> ...+>// </smpl>
>
> Signed-off-by: Julia Lawall <[email protected]>
>
> ---
> tools/perf/util/parse-events.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff -u -p a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
> --- a/tools/perf/util/parse-events.c
> +++ b/tools/perf/util/parse-events.c
> @@ -197,7 +197,7 @@ struct tracepoint_path *tracepoint_id_to
> if (id == config) {
> closedir(evt_dir);
> closedir(sys_dir);
> - path = zalloc(sizeof(path));
> + path = zalloc(sizeof(*path));
> path->system = malloc(MAX_EVENT_LENGTH);
> if (!path->system) {
> free(path);

and zalloc() can not fail ?
re,
wh