From: Henry Martin <bsdhenrymartin@gmail.com>
To: will@kernel.org, mark.rutland@arm.com
Cc: linux-arm-kernel@lists.infradead.org,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
Henry Martin <bsdhenrymartin@gmail.com>
Subject: [PATCH v3] driver: tx2: Add NULL check in tx2_uncore_pmu_register
Date: Mon, 31 Mar 2025 22:43:24 +0800 [thread overview]
Message-ID: <20250331144324.12940-1-bsdhenrymartin@gmail.com> (raw)
devm_kasprintf() returns NULL if memory allocation fails. Currently,
tx2_uncore_pmu_register() does not check for this case, leading to a
NULL pointer dereference.
Add NULL check after devm_kasprintf() to prevent this issue.
No automated tools were used; this was found during manual code review.
Fixes: 69c32972d593 ("drivers/perf: Add Cavium ThunderX2 SoC UNCORE PMU driver")
Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
---
V2 -> V3: Dropped the redundant error message as suggested by Markus.
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..24443ab5d998 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
next reply other threads:[~2025-03-31 14:43 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-31 14:43 Henry Martin [this message]
2025-03-31 15:00 ` [PATCH v3] driver: tx2: Add NULL check in tx2_uncore_pmu_register Markus Elfring
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250331144324.12940-1-bsdhenrymartin@gmail.com \
--to=bsdhenrymartin@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox