* [PATCH] backlight: qcom-wled: Add NULL check in the wled_configure
@ 2025-03-31 9:12 Henry Martin
2025-03-31 11:11 ` Daniel Thompson
2025-03-31 11:50 ` Markus Elfring
0 siblings, 2 replies; 3+ messages in thread
From: Henry Martin @ 2025-03-31 9:12 UTC (permalink / raw)
To: lee, danielt, jingoohan1, deller
Cc: linux-arm-msm, dri-devel, linux-fbdev, linux-kernel, Henry Martin
When devm_kasprintf() fails, it returns a NULL pointer. However, this return value is not properly checked in the function wled_configure.
A NULL check should be added after the devm_kasprintf call to prevent potential NULL pointer dereference error.
Fixes: f86b77583d88c ("backlight: pm8941: Convert to using %pOFn instead of device_node.name")
Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
---
drivers/video/backlight/qcom-wled.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/video/backlight/qcom-wled.c b/drivers/video/backlight/qcom-wled.c
index 9afe701b2a1b..db5eda8ec37e 100644
--- a/drivers/video/backlight/qcom-wled.c
+++ b/drivers/video/backlight/qcom-wled.c
@@ -1406,8 +1406,14 @@ 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) {
+ dev_err(dev, "Failed to allocate memory for wled name\n");
+ return -ENOMEM;
+ }
+ }
+
switch (wled->version) {
case 3:
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] backlight: qcom-wled: Add NULL check in the wled_configure
2025-03-31 9:12 [PATCH] backlight: qcom-wled: Add NULL check in the wled_configure Henry Martin
@ 2025-03-31 11:11 ` Daniel Thompson
2025-03-31 11:50 ` Markus Elfring
1 sibling, 0 replies; 3+ messages in thread
From: Daniel Thompson @ 2025-03-31 11:11 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 05:12:45PM +0800, Henry Martin wrote:
> When devm_kasprintf() fails, it returns a NULL pointer. However, this return value is not properly checked in the function wled_configure.
>
> A NULL check should be added after the devm_kasprintf call to prevent potential NULL pointer dereference error.
>
> Fixes: f86b77583d88c ("backlight: pm8941: Convert to using %pOFn instead of device_node.name")
>
> Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
> ---
> drivers/video/backlight/qcom-wled.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/video/backlight/qcom-wled.c b/drivers/video/backlight/qcom-wled.c
> index 9afe701b2a1b..db5eda8ec37e 100644
> --- a/drivers/video/backlight/qcom-wled.c
> +++ b/drivers/video/backlight/qcom-wled.c
> @@ -1406,8 +1406,14 @@ 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) {
> + dev_err(dev, "Failed to allocate memory for wled name\n");
> + return -ENOMEM;
> + }
> + }
> +
No objections to the check but I don't think it needs a dev_err(). It
is a waste of .text to store a string that is likely never to be
printed.
Daniel.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] backlight: qcom-wled: Add NULL check in the wled_configure
2025-03-31 9:12 [PATCH] backlight: qcom-wled: Add NULL check in the wled_configure Henry Martin
2025-03-31 11:11 ` Daniel Thompson
@ 2025-03-31 11:50 ` Markus Elfring
1 sibling, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2025-03-31 11:50 UTC (permalink / raw)
To: Henry Martin, linux-fbdev, linux-arm-msm, dri-devel
Cc: LKML, Daniel Thompson, Daniel Thompson, Helge Deller, Jingoo Han,
Lee Jones
> When devm_kasprintf() fails, it returns a NULL pointer. However, this return value is not properly checked in the function wled_configure.
>
> A NULL check should be added after the devm_kasprintf call to prevent potential NULL pointer dereference error.
* Please adhere to word wrapping preferences around 75 characters per text line.
* How do you think about 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
…
> +++ b/drivers/video/backlight/qcom-wled.c
> @@ -1406,8 +1406,14 @@ 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) {
> + dev_err(dev, "Failed to allocate memory for wled name\n");
> + return -ENOMEM;
> + }
> + }
…
An extra error messages for a failed memory allocation may occasionally be omitted.
Regards,
Markus
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-03-31 11:51 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-31 9:12 [PATCH] backlight: qcom-wled: Add NULL check in the wled_configure Henry Martin
2025-03-31 11:11 ` Daniel Thompson
2025-03-31 11:50 ` Markus Elfring
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox