[PATCH] drivers/perf: Add NULL check in tx2_uncore_pmu_register
Henry Martin
bsdhenrymartin at gmail.com
Mon Mar 31 03:23:46 PDT 2025
When devm_kasprintf() fails, it returns a NULL pointer. However, this return value is not properly checked in the function tx2_uncore_pmu_register.
A NULL check should be added after the devm_kasprintf() to prevent potential NULL pointer dereference error.
Fixes: 69c32972d5938 ("Add Cavium ThunderX2 SoC UNCORE PMU driver")
Signed-off-by: Henry Martin <bsdhenrymartin at gmail.com>
---
drivers/perf/thunderx2_pmu.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/perf/thunderx2_pmu.c b/drivers/perf/thunderx2_pmu.c
index 6ed4707bd6bb..ea36a82c3577 100644
--- a/drivers/perf/thunderx2_pmu.c
+++ b/drivers/perf/thunderx2_pmu.c
@@ -738,7 +738,8 @@ static int tx2_uncore_pmu_register(
tx2_pmu->pmu.name = devm_kasprintf(dev, GFP_KERNEL,
"%s", name);
-
+ if (!tx2_pmu->pmu.name)
+ return -ENOMEM
return perf_pmu_register(&tx2_pmu->pmu, tx2_pmu->pmu.name, -1);
}
--
2.34.1
More information about the linux-arm-kernel
mailing list