Skip to content

Commit 3e152aa

Browse files
Jin Yaoacmel
authored andcommitted
perf block-info: Fix wrong block address comparison in block_info__cmp()
Commit 6041441 ("perf block: Cleanup and refactor block info functions") introduces block_info__cmp(), which compares two blocks. But the issues are: 1. It should return the strcmp cmp value only if it's not 0. 2. When symbol names are matched, we need to compare the addresses of blocks further. But it wrongly uses the symbol addresses for comparison. 3. If the syms are both NULL, we can't consider these two blocks are matched. This patch fixes above 3 issues. Fixes: 6041441 ("perf block: Cleanup and refactor block info functions") Signed-off-by: Jin Yao <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Jin Yao <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Kan Liang <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent d942815 commit 3e152aa

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

tools/perf/util/block-info.c

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,30 +74,21 @@ int64_t block_info__cmp(struct perf_hpp_fmt *fmt __maybe_unused,
7474

7575
if (!bi_l->sym || !bi_r->sym) {
7676
if (!bi_l->sym && !bi_r->sym)
77-
return 0;
77+
return -1;
7878
else if (!bi_l->sym)
7979
return -1;
8080
else
8181
return 1;
8282
}
8383

84-
if (bi_l->sym == bi_r->sym) {
85-
if (bi_l->start == bi_r->start) {
86-
if (bi_l->end == bi_r->end)
87-
return 0;
88-
else
89-
return (int64_t)(bi_r->end - bi_l->end);
90-
} else
91-
return (int64_t)(bi_r->start - bi_l->start);
92-
} else {
93-
cmp = strcmp(bi_l->sym->name, bi_r->sym->name);
84+
cmp = strcmp(bi_l->sym->name, bi_r->sym->name);
85+
if (cmp)
9486
return cmp;
95-
}
9687

97-
if (bi_l->sym->start != bi_r->sym->start)
98-
return (int64_t)(bi_r->sym->start - bi_l->sym->start);
88+
if (bi_l->start != bi_r->start)
89+
return (int64_t)(bi_r->start - bi_l->start);
9990

100-
return (int64_t)(bi_r->sym->end - bi_l->sym->end);
91+
return (int64_t)(bi_r->end - bi_l->end);
10192
}
10293

10394
static void init_block_info(struct block_info *bi, struct symbol *sym,

0 commit comments

Comments
 (0)