[PATCH] hwmon: Check dev_set_name() return value
From: Ma Ke
Date: Tue Dec 10 2024 - 21:34:55 EST
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@xxxxxxxxxxxxxxx
Fixes: d560168b5d0f ("hwmon: (core) New hwmon registration API")
Signed-off-by: Ma Ke <make_ruc2021@xxxxxxx>
---
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