Skip to content

Commit 6eeefcc

Browse files
Patrick Palkaacmel
authored andcommitted
perf bench: Fix NULL pointer dereference in "perf bench all"
The for_each_bench() macro must check that the "benchmarks" field of a collection is not NULL before dereferencing it because the "all" collection in particular has a NULL "benchmarks" field (signifying that it has no benchmarks to iterate over). This fixes this NULL pointer dereference when running "perf bench all": [root@ssdandy ~]# perf bench all <SNIP> # Running mem/memset benchmark... # Copying 1MB Bytes ... 2.453675 GB/Sec 12.056327 GB/Sec (with prefault) Segmentation fault (core dumped) [root@ssdandy ~]# Signed-off-by: Patrick Palka <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Paul Mackerras <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 0fae799 commit 6eeefcc

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

tools/perf/builtin-bench.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ static struct collection collections[] = {
7676

7777
/* Iterate over all benchmarks within a collection: */
7878
#define for_each_bench(coll, bench) \
79-
for (bench = coll->benchmarks; bench->name; bench++)
79+
for (bench = coll->benchmarks; bench && bench->name; bench++)
8080

8181
static void dump_benchmarks(struct collection *coll)
8282
{

0 commit comments

Comments
 (0)