Skip to contentSkip to conversation

drivers/perf: Add NULL check in tx2_uncore_pmu_register

PATCH In review Henry Martin 2 participants 2 messages Mar 31, 2025 Arm PMU profiling and debugging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers/perf: Add NULL check in tx2_uncore_pmu_register

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")
---
 drivers/perf/thunderx2_pmu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/perf/thunderx2_pmu.c +2 -1
index 6ed4707bd6bb..ea36a82c3577 100644
@@ -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);
 }
 
Signature · 1 line
2.34.1
#1 lore raw
Quoted 3 lines

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.

* Please adhere to word wrapping preferences around 75 characters per text line.

* Would you like to choose the imperative mood for an improved change description?
https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.14#n94

Regards,
Markus