From: Henry Martin <bsdhenrymartin@gmail.com>
To: Markus.Elfring@web.de
Cc: lee@kernel.org, danielt@kernel.org, jingoohan1@gmail.com,
deller@gmx.de, linux-arm-msm@vger.kernel.org,
dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org,
linux-kernel@vger.kernel.org,
Henry Martin <bsdhenrymartin@gmail.com>,
Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
Subject: [PATCH v3] backlight: pm8941: Add NULL check in wled_configure()
Date: Tue, 1 Apr 2025 16:29:50 +0800 [thread overview]
Message-ID: <20250401082950.21698-1-bsdhenrymartin@gmail.com> (raw)
In-Reply-To: <d5f2aa49-27e2-4cc1-91be-4e195ed5249e@web.de>
The function wled_configure() uses devm_kasprintf() without checking for
allocation failures, which could lead to NULL pointer dereferences.
Add proper error handling when devm_kasprintf() fails by:
- Returning -ENOMEM immediately
- Ensuring no resources are left allocated (none need cleanup in this case)
Fixes: f86b77583d88 ("backlight: pm8941: Convert to using %pOFn instead of device_node.name")
Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
---
V2 -> V3: Fix commit message and verify proper error handling with
resource cleanup.
V1 -> V2: Fix commit message to use imperative mood and wrap lines to 75
characters.
drivers/video/backlight/qcom-wled.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/video/backlight/qcom-wled.c b/drivers/video/backlight/qcom-wled.c
index 9afe701b2a1b..a63bb42c8f8b 100644
--- a/drivers/video/backlight/qcom-wled.c
+++ b/drivers/video/backlight/qcom-wled.c
@@ -1406,9 +1406,11 @@ static int wled_configure(struct wled *wled)
wled->ctrl_addr = be32_to_cpu(*prop_addr);
rc = of_property_read_string(dev->of_node, "label", &wled->name);
- if (rc)
+ if (rc) {
wled->name = devm_kasprintf(dev, GFP_KERNEL, "%pOFn", dev->of_node);
-
+ if (!wled->name)
+ return -ENOMEM;
+ }
switch (wled->version) {
case 3:
u32_opts = wled3_opts;
--
2.34.1
next prev parent reply other threads:[~2025-04-01 8:30 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-01 2:57 [PATCH v3] backlight: pm8941: Add NULL check in wled_configure() Henry Martin
2025-04-01 6:18 ` Markus Elfring
2025-04-01 6:53 ` Henry Martin
2025-04-01 8:29 ` Henry Martin [this message]
2025-04-01 8:58 ` Daniel Thompson
2025-04-01 9:16 ` [PATCH v4] " Henry Martin
2025-04-04 15:11 ` (subset) " Lee Jones
2025-04-04 15:13 ` Lee Jones
2025-04-04 15:19 ` henry martin
2025-04-01 10:00 ` [v4?] " Markus Elfring
2025-04-01 8:44 ` [PATCH v3] " Daniel Thompson
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=20250401082950.21698-1-bsdhenrymartin@gmail.com \
--to=bsdhenrymartin@gmail.com \
--cc=Markus.Elfring@web.de \
--cc=danielt@kernel.org \
--cc=deller@gmx.de \
--cc=dmitry.baryshkov@oss.qualcomm.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=jingoohan1@gmail.com \
--cc=lee@kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-fbdev@vger.kernel.org \
--cc=linux-kernel@vger.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;
as well as URLs for NNTP newsgroup(s).