[PATCH] drivers/perf: Add NULL check in tx2_uncore_pmu_register

Henry Martin posted 1 patch 8 months, 3 weeks ago
drivers/perf/thunderx2_pmu.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
[PATCH] drivers/perf: Add NULL check in tx2_uncore_pmu_register
Posted by Henry Martin 8 months, 3 weeks ago
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@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
Re: [PATCH] drivers/perf: Add NULL check in tx2_uncore_pmu_register
Posted by Markus Elfring 8 months, 3 weeks ago
> 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