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);
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
linux-stable-mirror@lists.linaro.org