From: Thomas Richard <thomas.richard@bootlin.com>
To: Li Qiang <liqiang01@kylinos.cn>, linux@roeck-us.net
Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] hwmon: cgbc-hwmon: Add missing NULL check after devm_kzalloc()
Date: Fri, 17 Oct 2025 10:12:40 +0200 [thread overview]
Message-ID: <7c2dd51f-a601-4c64-9295-0cf63ab8d749@bootlin.com> (raw)
In-Reply-To: <20251017063414.1557447-1-liqiang01@kylinos.cn>
Hi,
On 10/17/25 8:34 AM, Li Qiang wrote:
> The driver allocates memory for sensor data using devm_kzalloc(), but
> did not check if the allocation succeeded. In case of memory allocation
> failure, dereferencing the NULL pointer would lead to a kernel crash.
>
> Add a NULL pointer check and return -ENOMEM to handle allocation failure
> properly.
>
> Signed-off-by: Li Qiang <liqiang01@kylinos.cn>
> ---
> drivers/hwmon/cgbc-hwmon.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/hwmon/cgbc-hwmon.c b/drivers/hwmon/cgbc-hwmon.c
> index 772f44d56ccf..3aff4e092132 100644
> --- a/drivers/hwmon/cgbc-hwmon.c
> +++ b/drivers/hwmon/cgbc-hwmon.c
> @@ -107,6 +107,9 @@ static int cgbc_hwmon_probe_sensors(struct device *dev, struct cgbc_hwmon_data *
> nb_sensors = data[0];
>
> hwmon->sensors = devm_kzalloc(dev, sizeof(*hwmon->sensors) * nb_sensors, GFP_KERNEL);
> + if (!hwmon->sensors)
> + return -ENOMEM;
> +
Thanks for your patch.
Reviewed-by: Thomas Richard <thomas.richard@bootlin.com>
Best Regards,
Thomas
next prev parent reply other threads:[~2025-10-17 8:12 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-17 6:34 [PATCH] hwmon: cgbc-hwmon: Add missing NULL check after devm_kzalloc() Li Qiang
2025-10-17 8:12 ` Thomas Richard [this message]
2025-10-17 12:42 ` Guenter Roeck
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=7c2dd51f-a601-4c64-9295-0cf63ab8d749@bootlin.com \
--to=thomas.richard@bootlin.com \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=liqiang01@kylinos.cn \
/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