mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] hwmon: Check dev_set_name() return value
@ 2024-12-11  2:34 Ma Ke
  2024-12-11  4:42 ` Guenter Roeck
  0 siblings, 1 reply; 2+ messages in thread
From: Ma Ke @ 2024-12-11  2:34 UTC (permalink / raw)
  To: jdelvare, linux, jic23, punitagrawal
  Cc: linux-hwmon, linux-kernel, Ma Ke, stable

It's possible that dev_set_name() returns -ENOMEM. We could catch and
handle it by adding dev_set_name() return value check.

Cc: stable@vger.kernel.org
Fixes: d560168b5d0f ("hwmon: (core) New hwmon registration API")
Signed-off-by: Ma Ke <make_ruc2021@163.com>
---
 drivers/hwmon/hwmon.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
index bbb9cc44e29f..8b9bdb28650d 100644
--- a/drivers/hwmon/hwmon.c
+++ b/drivers/hwmon/hwmon.c
@@ -955,7 +955,10 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata,
 	hdev->of_node = tdev ? tdev->of_node : NULL;
 	hwdev->chip = chip;
 	dev_set_drvdata(hdev, drvdata);
-	dev_set_name(hdev, HWMON_ID_FORMAT, id);
+	err = dev_set_name(hdev, HWMON_ID_FORMAT, id);
+	if (err)
+		goto free_hwmon;
+
 	err = device_register(hdev);
 	if (err) {
 		put_device(hdev);
-- 
2.25.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] hwmon: Check dev_set_name() return value
  2024-12-11  2:34 [PATCH] hwmon: Check dev_set_name() return value Ma Ke
@ 2024-12-11  4:42 ` Guenter Roeck
  0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2024-12-11  4:42 UTC (permalink / raw)
  To: Ma Ke, jdelvare, jic23, punitagrawal; +Cc: linux-hwmon, linux-kernel, stable

On 12/10/24 18:34, Ma Ke wrote:
> It's possible that dev_set_name() returns -ENOMEM. We could catch and
> handle it by adding dev_set_name() return value check.
> 
> Cc: stable@vger.kernel.org
> Fixes: d560168b5d0f ("hwmon: (core) New hwmon registration API")
> Signed-off-by: Ma Ke <make_ruc2021@163.com>
> ---
>   drivers/hwmon/hwmon.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
> index bbb9cc44e29f..8b9bdb28650d 100644
> --- a/drivers/hwmon/hwmon.c
> +++ b/drivers/hwmon/hwmon.c
> @@ -955,7 +955,10 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata,
>   	hdev->of_node = tdev ? tdev->of_node : NULL;
>   	hwdev->chip = chip;
>   	dev_set_drvdata(hdev, drvdata);
> -	dev_set_name(hdev, HWMON_ID_FORMAT, id);
> +	err = dev_set_name(hdev, HWMON_ID_FORMAT, id);
> +	if (err)
> +		goto free_hwmon;
> +
>   	err = device_register(hdev);
>   	if (err) {
>   		put_device(hdev);

As has been mentioned elsewhere:

If dev_set_name() fails, device_add() will fail. device_register() calls
device_add() and will therefore fail as well. For that reason, error
checking dev_set_name() is unnecessary for hwmon devices.

Guenter


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-12-11  4:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-11  2:34 [PATCH] hwmon: Check dev_set_name() return value Ma Ke
2024-12-11  4:42 ` Guenter Roeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®