]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
perf: arm_pmuv3: Zero initialize hw_id branch stack field
authorJames Clark <james.clark@linaro.org>
Fri, 7 Aug 2026 09:14:59 +0000 (10:14 +0100)
committerWill Deacon <will@kernel.org>
Fri, 7 Aug 2026 11:55:16 +0000 (11:55 +0000)
PERF_SAMPLE_BRANCH_HW_INDEX is supported by BRBE so hw_id is passed to
userspace, but it's never set by the BRBE driver. Zero initialize it as
it should be according to the docs:

   * For the architectures whose raw branch records are
   * already stored in age order, the hw_idx should be 0.

It's probably too risky to remove PERF_SAMPLE_BRANCH_HW_INDEX from BRBE
now in case anyone is setting it and reading the value, but zero
initializing the whole struct also protects against the same issue with
new fields that are added in the future.

Fixes: 58074a0fce66 ("perf: arm_pmuv3: Add support for the Branch Record Buffer Extension (BRBE)")
Signed-off-by: James Clark <james.clark@linaro.org>
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
Signed-off-by: Will Deacon <will@kernel.org>
drivers/perf/arm_pmuv3.c

index 6d4d57342352aaf7474398ccc143b8f1f96644be..03359e078301f85f3bb1beca2b346aa29c822cc8 100644 (file)
@@ -1407,7 +1407,7 @@ static int branch_records_alloc(struct arm_pmu *armpmu)
                struct pmu_hw_events *events_cpu;
 
                events_cpu = per_cpu_ptr(armpmu->hw_events, cpu);
-               events_cpu->branch_stack = kmalloc(size, GFP_KERNEL);
+               events_cpu->branch_stack = kzalloc(size, GFP_KERNEL);
                if (!events_cpu->branch_stack)
                        return -ENOMEM;
        }