* [PATCH] drivers/perf: Add NULL check in tx2_uncore_pmu_register
@ 2025-03-31 10:23 Henry Martin
2025-03-31 12:08 ` Markus Elfring
0 siblings, 1 reply; 2+ messages in thread
From: Henry Martin @ 2025-03-31 10:23 UTC (permalink / raw)
To: will, mark.rutland
Cc: linux-arm-kernel, linux-perf-users, linux-kernel, Henry Martin
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] drivers/perf: Add NULL check in tx2_uncore_pmu_register
2025-03-31 10:23 [PATCH] drivers/perf: Add NULL check in tx2_uncore_pmu_register Henry Martin
@ 2025-03-31 12:08 ` Markus Elfring
0 siblings, 0 replies; 2+ messages in thread
From: Markus Elfring @ 2025-03-31 12:08 UTC (permalink / raw)
To: Henry Martin, linux-perf-users, linux-arm-kernel
Cc: LKML, Mark Rutland, Will Deacon
> 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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-03-31 12:08 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-31 10:23 [PATCH] drivers/perf: Add NULL check in tx2_uncore_pmu_register Henry Martin
2025-03-31 12:08 ` Markus Elfring
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox