Skip to content

Commit 64c17be

Browse files
committed
perf annotate: Fix off by one symbol hist size allocation and hit accounting
We were not noticing it because symbol__inc_addr_samples was erroneously dropping samples that hit the last byte in a function. Working on a fix for a problem reported by David Miller, Stephane Eranian and Sorin Dumitru, where addresses < sym->start were causing problems, I noticed this other problem. Cc: David Ahern <[email protected]> Cc: David Miller <[email protected]> Cc: Frederic Weisbecker <[email protected]> Cc: Mike Galbraith <[email protected]> Cc: Paul Mackerras <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Sorin Dumitru <[email protected]> Cc: Stephane Eranian <[email protected]> Link: http://lkml.kernel.org/n/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent cc96aa7 commit 64c17be

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

tools/perf/util/annotate.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ int symbol__annotate_init(struct map *map __used, struct symbol *sym)
2828
int symbol__alloc_hist(struct symbol *sym)
2929
{
3030
struct annotation *notes = symbol__annotation(sym);
31-
size_t sizeof_sym_hist = (sizeof(struct sym_hist) +
32-
(sym->end - sym->start) * sizeof(u64));
31+
const size_t size = sym->end - sym->start + 1;
32+
size_t sizeof_sym_hist = (sizeof(struct sym_hist) + size * sizeof(u64));
3333

3434
notes->src = zalloc(sizeof(*notes->src) + symbol_conf.nr_events * sizeof_sym_hist);
3535
if (notes->src == NULL)
@@ -64,7 +64,7 @@ int symbol__inc_addr_samples(struct symbol *sym, struct map *map,
6464

6565
pr_debug3("%s: addr=%#" PRIx64 "\n", __func__, map->unmap_ip(map, addr));
6666

67-
if (addr >= sym->end)
67+
if (addr > sym->end)
6868
return 0;
6969

7070
offset = addr - sym->start;

0 commit comments

Comments
 (0)