From: Daniel Thompson <daniel@riscstar.com>
To: Henry Martin <bsdhenrymartin@gmail.com>
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
Subject: Re: [PATCH] backlight: qcom-wled: Add NULL check in the wled_configure
Date: Mon, 31 Mar 2025 12:11:32 +0100 [thread overview]
Message-ID: <Z-p4ZLkyIIeyVzPm@aspen.lan> (raw)
In-Reply-To: <20250331091245.6668-1-bsdhenrymartin@gmail.com>
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.
next prev parent reply other threads:[~2025-03-31 11:11 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2025-03-31 11:50 ` 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=Z-p4ZLkyIIeyVzPm@aspen.lan \
--to=daniel@riscstar.com \
--cc=bsdhenrymartin@gmail.com \
--cc=danielt@kernel.org \
--cc=deller@gmx.de \
--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