[PATCH] perf: starfive: Fix potential per-CPU memory leak on probe failure

Guangshuo Li liguangshuo at mail.sdu.edu.cn
Wed Nov 11 04:23:16 PST 2026


The per-CPU hardware events remain allocated when a later probe step
fails, although the device-managed PMU structure is released.

Allocate the events with devm_alloc_percpu() so failed probing releases
them after the interrupt handlers have been removed.

This issue was found by our static analysis tool under development.

Fixes: c2b24812f7bc ("perf: starfive: Add StarLink PMU support")
Cc: stable at vger.kernel.org
Signed-off-by: Guangshuo Li <liguangshuo at mail.sdu.edu.cn>
---
 drivers/perf/starfive_starlink_pmu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/perf/starfive_starlink_pmu.c b/drivers/perf/starfive_starlink_pmu.c
index d9843645554b..25d57b904028 100644
--- a/drivers/perf/starfive_starlink_pmu.c
+++ b/drivers/perf/starfive_starlink_pmu.c
@@ -519,8 +519,8 @@ static int starlink_pmu_probe(struct platform_device *pdev)
 	if (IS_ERR(starlink_pmu->pmu_base))
 		return PTR_ERR(starlink_pmu->pmu_base);
 
-	starlink_pmu->hw_events = alloc_percpu_gfp(struct starlink_hw_events,
-						   GFP_KERNEL);
+	starlink_pmu->hw_events = devm_alloc_percpu(&pdev->dev,
+						    struct starlink_hw_events);
 	if (!starlink_pmu->hw_events) {
 		dev_err(&pdev->dev, "Failed to allocate per-cpu PMU data\n");
 		return -ENOMEM;

base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4



More information about the linux-arm-kernel mailing list