* [PATCH v3] backlight: pm8941: Add NULL check in wled_configure()
@ 2025-04-01 2:57 Henry Martin
2025-04-01 6:18 ` Markus Elfring
2025-04-01 8:44 ` [PATCH v3] " Daniel Thompson
0 siblings, 2 replies; 11+ messages in thread
From: Henry Martin @ 2025-04-01 2:57 UTC (permalink / raw)
To: lee, danielt, jingoohan1, deller
Cc: linux-arm-msm, dri-devel, linux-fbdev, linux-kernel, Henry Martin,
Dmitry Baryshkov
devm_kasprintf() returns NULL when memory allocation fails. Currently,
wled_configure() does not check for this case, which results in a 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")
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
---
V2 -> V3: Correct commit meessage and confirm this patch has considered
resource cleanup to avoid any subsequent issues, ensuring that errors
are handled properly and no resources are left in an inconsistent
state.
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] 11+ messages in thread
* Re: [PATCH v3] backlight: pm8941: Add NULL check in wled_configure()
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
2025-04-01 8:44 ` [PATCH v3] " Daniel Thompson
1 sibling, 2 replies; 11+ messages in thread
From: Markus Elfring @ 2025-04-01 6:18 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?
> Add NULL check after devm_kasprintf() to prevent this issue.
Do you propose to improve this function implementation a bit more?
Regards,
Markus
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v3] backlight: pm8941: Add NULL check in wled_configure()
2025-04-01 6:18 ` Markus Elfring
@ 2025-04-01 6:53 ` Henry Martin
2025-04-01 8:29 ` Henry Martin
1 sibling, 0 replies; 11+ messages in thread
From: Henry Martin @ 2025-04-01 6:53 UTC (permalink / raw)
To: markus
Cc: lee, danielt, jingoohan1, deller, linux-arm-msm, dri-devel,
linux-fbdev, linux-kernel
Thanks for your review. No further improvements needed for this implementation
- it already handles all error cases appropriately.
Best regards,
Henry
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v3] backlight: pm8941: Add NULL check in wled_configure()
2025-04-01 6:18 ` Markus Elfring
2025-04-01 6:53 ` Henry Martin
@ 2025-04-01 8:29 ` Henry Martin
2025-04-01 8:58 ` Daniel Thompson
1 sibling, 1 reply; 11+ messages in thread
From: Henry Martin @ 2025-04-01 8:29 UTC (permalink / raw)
To: Markus.Elfring
Cc: lee, danielt, jingoohan1, deller, linux-arm-msm, dri-devel,
linux-fbdev, linux-kernel, Henry Martin, Dmitry Baryshkov
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
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v3] backlight: pm8941: Add NULL check in wled_configure()
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 8:44 ` Daniel Thompson
1 sibling, 0 replies; 11+ messages in thread
From: Daniel Thompson @ 2025-04-01 8:44 UTC (permalink / raw)
To: Henry Martin
Cc: lee, jingoohan1, deller, linux-arm-msm, dri-devel, linux-fbdev,
linux-kernel, Dmitry Baryshkov
On Tue, Apr 01, 2025 at 10:57:37AM +0800, Henry Martin wrote:
> devm_kasprintf() returns NULL when memory allocation fails. Currently,
> wled_configure() does not check for this case, which results in a 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")
> Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
> Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
Reviewed-by: Daniel Thompson (RISCstar) <danielt@kernel.org>
Daniel.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3] backlight: pm8941: Add NULL check in wled_configure()
2025-04-01 8:29 ` Henry Martin
@ 2025-04-01 8:58 ` Daniel Thompson
2025-04-01 9:16 ` [PATCH v4] " Henry Martin
2025-04-01 10:00 ` [v4?] " Markus Elfring
0 siblings, 2 replies; 11+ messages in thread
From: Daniel Thompson @ 2025-04-01 8:58 UTC (permalink / raw)
To: Henry Martin
Cc: Markus.Elfring, lee, jingoohan1, deller, linux-arm-msm, dri-devel,
linux-fbdev, linux-kernel, Dmitry Baryshkov
On Tue, Apr 01, 2025 at 04:29:50PM +0800, Henry Martin wrote:
> 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)
Two things have gone wrong here:
1. This patch has been incorrectly posted with the wrong patch number.
2. You've let Markus bully you into adding some pointless text in the
patch description ;-). I think the original v3 was better worded.
IMHO the bulleted list adds nothing useful.
When you get the chance please send a v4 of the patch so we can pick it
up without any confusion (I suspect it might be a week or two before
this gets pulled so clean mail threads help a lot). It's up to you but
I'd recommend keeping the original v3 wording and label it something
like:
V3 -> V4: No functional changes, just correcting the version number
Daniel.
>
> 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
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v4] backlight: pm8941: Add NULL check in wled_configure()
2025-04-01 8:58 ` Daniel Thompson
@ 2025-04-01 9:16 ` Henry Martin
2025-04-04 15:11 ` (subset) " Lee Jones
2025-04-01 10:00 ` [v4?] " Markus Elfring
1 sibling, 1 reply; 11+ messages in thread
From: Henry Martin @ 2025-04-01 9:16 UTC (permalink / raw)
To: danielt
Cc: lee, jingoohan1, deller, linux-arm-msm, dri-devel, linux-fbdev,
linux-kernel, Henry Martin, Dmitry Baryshkov
devm_kasprintf() returns NULL when memory allocation fails. Currently,
wled_configure() does not check for this case, which results in a 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>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
Reviewed-by: Daniel Thompson (RISCstar) <danielt@kernel.org>
---
V3 -> V4: No functional changes, just correcting the version number
V2 -> V3: Correct commit meessage and confirm this patch has considered
resource cleanup to avoid any subsequent issues, ensuring that errors
are handled properly and no resources are left in an inconsistent
state.
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] 11+ messages in thread
* Re: [v4?] backlight: pm8941: Add NULL check in wled_configure()
2025-04-01 8:58 ` Daniel Thompson
2025-04-01 9:16 ` [PATCH v4] " Henry Martin
@ 2025-04-01 10:00 ` Markus Elfring
1 sibling, 0 replies; 11+ messages in thread
From: Markus Elfring @ 2025-04-01 10:00 UTC (permalink / raw)
To: Daniel Thompson, Henry Martin, linux-fbdev, linux-arm-msm,
dri-devel
Cc: LKML, Dmitry Baryshkov, Helge Deller, Jingoo Han, Lee Jones
…
> patch description ;-). I think the original v3 was better worded.
…
Can you find the mentioning of adjustments helpful for better error handling?
Regards,
Markus
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: (subset) [PATCH v4] backlight: pm8941: Add NULL check in wled_configure()
2025-04-01 9:16 ` [PATCH v4] " Henry Martin
@ 2025-04-04 15:11 ` Lee Jones
2025-04-04 15:13 ` Lee Jones
0 siblings, 1 reply; 11+ messages in thread
From: Lee Jones @ 2025-04-04 15:11 UTC (permalink / raw)
To: danielt, Henry Martin
Cc: lee, jingoohan1, deller, linux-arm-msm, dri-devel, linux-fbdev,
linux-kernel, Dmitry Baryshkov
On Tue, 01 Apr 2025 17:16:47 +0800, Henry Martin wrote:
> devm_kasprintf() returns NULL when memory allocation fails. Currently,
> wled_configure() does not check for this case, which results in a NULL
> pointer dereference.
>
> Add NULL check after devm_kasprintf() to prevent this issue.
>
>
> [...]
Applied, thanks!
[1/1] backlight: pm8941: Add NULL check in wled_configure()
commit: b0fdeb96ead46de57a6226bc3a3ac7f9b50c0ace
--
Lee Jones [李琼斯]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: (subset) [PATCH v4] backlight: pm8941: Add NULL check in wled_configure()
2025-04-04 15:11 ` (subset) " Lee Jones
@ 2025-04-04 15:13 ` Lee Jones
2025-04-04 15:19 ` henry martin
0 siblings, 1 reply; 11+ messages in thread
From: Lee Jones @ 2025-04-04 15:13 UTC (permalink / raw)
To: danielt, Henry Martin
Cc: jingoohan1, deller, linux-arm-msm, dri-devel, linux-fbdev,
linux-kernel, Dmitry Baryshkov
On Fri, 04 Apr 2025, Lee Jones wrote:
> On Tue, 01 Apr 2025 17:16:47 +0800, Henry Martin wrote:
> > devm_kasprintf() returns NULL when memory allocation fails. Currently,
> > wled_configure() does not check for this case, which results in a NULL
> > pointer dereference.
> >
> > Add NULL check after devm_kasprintf() to prevent this issue.
> >
> >
> > [...]
>
> Applied, thanks!
>
> [1/1] backlight: pm8941: Add NULL check in wled_configure()
> commit: b0fdeb96ead46de57a6226bc3a3ac7f9b50c0ace
Next time, please send subsequent patch versions independently.
--
Lee Jones [李琼斯]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: (subset) [PATCH v4] backlight: pm8941: Add NULL check in wled_configure()
2025-04-04 15:13 ` Lee Jones
@ 2025-04-04 15:19 ` henry martin
0 siblings, 0 replies; 11+ messages in thread
From: henry martin @ 2025-04-04 15:19 UTC (permalink / raw)
To: Lee Jones
Cc: danielt, jingoohan1, deller, linux-arm-msm, dri-devel,
linux-fbdev, linux-kernel, Dmitry Baryshkov
Noted, thanks for the feedback! I’ll send subsequent versions as
independent patches in the future.
Best regards,
Henry
Lee Jones <lee@kernel.org> 于2025年4月4日周五 23:13写道:
>
> On Fri, 04 Apr 2025, Lee Jones wrote:
>
> > On Tue, 01 Apr 2025 17:16:47 +0800, Henry Martin wrote:
> > > devm_kasprintf() returns NULL when memory allocation fails. Currently,
> > > wled_configure() does not check for this case, which results in a NULL
> > > pointer dereference.
> > >
> > > Add NULL check after devm_kasprintf() to prevent this issue.
> > >
> > >
> > > [...]
> >
> > Applied, thanks!
> >
> > [1/1] backlight: pm8941: Add NULL check in wled_configure()
> > commit: b0fdeb96ead46de57a6226bc3a3ac7f9b50c0ace
>
> Next time, please send subsequent patch versions independently.
>
> --
> Lee Jones [李琼斯]
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2025-04-04 15:19 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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
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).