Skip to contentSkip to conversation

perf branch: Avoid incrementing NULL

PATCH Applied Ian Rogers 2 participants 2 messages Mar 12 – Mar 14 perf events

lore
Share & tools
lore

Ian Rogers

author reviewer
#0 lore raw

PATCH 1/1 perf branch: Avoid incrementing NULL

If the entry is NULL the value is meaningless so early return NULL to avoid an increment of NULL. This was happening in calls from has_stitched_lbr when running the "perf record LBR tests". The return value isn't used in that case, so returning NULL as no effect.

Fixes 42bbabed09ce ("perf tools: Add hw_idx in struct branch_stack")
---
 tools/perf/util/branch.h | 3 +++
 1 file changed, 3 insertions(+)
tools/perf/util/branch.h +3 -0
index 7429530fa774..a1d4736497c4 100644
@@ -66,6 +66,9 @@ static inline struct branch_entry *perf_sample__branch_entries(struct perf_sampl
 {
 	u64 *entry = (u64 *)sample->branch_stack;
 
+	if (entry == NULL)
+		return NULL;
+
 	entry++;
 	if (sample->no_hw_idx)
 		return (struct branch_entry *)entry;
Signature · 1 line
2.53.0.851.ga537e3e6e9-goog
maintainer Applied
#1 lore raw
Quoted 7 lines · Ian Rogers

If the entry is NULL the value is meaningless so early return NULL to avoid an increment of NULL. This was happening in calls from has_stitched_lbr when running the "perf record LBR tests". The return value isn't used in that case, so returning NULL as no effect.

Fixes 42bbabed09ce ("perf tools: Add hw_idx in struct branch_stack")

Applied to perf-tools-next, thanks!

Best regards,
Namhyung