* [PATCH v2] backlight: pm8941: Add NULL check in wled_configure()
@ 2025-03-31 14:16 Henry Martin
2025-03-31 16:48 ` Markus Elfring
2025-03-31 20:23 ` Dmitry Baryshkov
0 siblings, 2 replies; 3+ messages in thread
From: Henry Martin @ 2025-03-31 14:16 UTC (permalink / raw)
To: lee, danielt, jingoohan1, deller
Cc: linux-arm-msm, dri-devel, linux-fbdev, linux-kernel, Henry Martin
devm_kasprintf() return NULL if memory allocation fails. Currently,
wled_configure() does not check for this case, leading to a possible NULL
pointer dereference.
Add NULL check after devm_kasprintf() to prevent this issue.
Fixes: f86b77583d88 ("backlight: pm8941: Convert to using %pOFn instead of device_node.name")
Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
---
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] backlight: pm8941: Add NULL check in wled_configure()
2025-03-31 14:16 [PATCH v2] backlight: pm8941: Add NULL check in wled_configure() Henry Martin
@ 2025-03-31 16:48 ` Markus Elfring
2025-03-31 20:23 ` Dmitry Baryshkov
1 sibling, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2025-03-31 16:48 UTC (permalink / raw)
To: Henry Martin, linux-fbdev, linux-arm-msm, dri-devel
Cc: LKML, Daniel Thompson, Helge Deller, Jingoo Han, Lee Jones
> devm_kasprintf() return NULL if memory allocation fails. Currently,
call? failed?
> wled_configure() does not check for this case, leading to a possible NULL
> pointer dereference.
You may omit the word “possible” in such a change description.
(Would questionable data processing happen in other function implementations?)
> Add NULL check after devm_kasprintf() to prevent this issue.
Do you complete the error/exception handling also with the statement “return -ENOMEM;”?
Regards,
Markus
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] backlight: pm8941: Add NULL check in wled_configure()
2025-03-31 14:16 [PATCH v2] backlight: pm8941: Add NULL check in wled_configure() Henry Martin
2025-03-31 16:48 ` Markus Elfring
@ 2025-03-31 20:23 ` Dmitry Baryshkov
1 sibling, 0 replies; 3+ messages in thread
From: Dmitry Baryshkov @ 2025-03-31 20:23 UTC (permalink / raw)
To: Henry Martin
Cc: lee, danielt, jingoohan1, deller, linux-arm-msm, dri-devel,
linux-fbdev, linux-kernel
On Mon, Mar 31, 2025 at 10:16:54PM +0800, Henry Martin wrote:
> devm_kasprintf() return NULL if memory allocation fails. Currently,
> wled_configure() does not check for this case, leading to a possible NULL
> pointer dereference.
>
> Add NULL check after devm_kasprintf() to prevent this issue.
>
> Fixes: f86b77583d88 ("backlight: pm8941: Convert to using %pOFn instead of device_node.name")
> Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
> ---
> 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(-)
>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
--
With best wishes
Dmitry
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-03-31 20:23 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-31 14:16 [PATCH v2] backlight: pm8941: Add NULL check in wled_configure() Henry Martin
2025-03-31 16:48 ` Markus Elfring
2025-03-31 20:23 ` Dmitry Baryshkov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox