Skip to contentSkip to conversation

hwmon: sy7636a: Fix regulator_enable resource leak on error path

PATCH Superseded Haotian Zhang 2 participants 4 messages Nov 26, 2025 Hardware monitoring

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hwmon: sy7636a: Fix regulator_enable resource leak on error path

In sy7636a_sensor_probe(), regulator_enable() is called but if devm_hwmon_device_register_with_info() fails, the function returns without calling regulator_disable(), leaving the regulator enabled and leaking the reference count.

Add regulator_disable() call in the error path to properly disable the regulator.

Fixes de34a4053250 ("hwmon: sy7636a: Add temperature driver for sy7636a")
---
 drivers/hwmon/sy7636a-hwmon.c | 1 +
 1 file changed, 1 insertion(+)
drivers/hwmon/sy7636a-hwmon.c +1 -0
index ed110884786b..b8e598a616ad 100644
@@ -88,6 +88,7 @@ static int sy7636a_sensor_probe(struct platform_device *pdev)
 	if (IS_ERR(hwmon_dev)) {
 		err = PTR_ERR(hwmon_dev);
 		dev_err(&pdev->dev, "Unable to register hwmon device, returned %d\n", err);
+		regulator_disable(regulator);
 		return err;
 	}
 
Signature · 1 line
2.50.1.windows.1
maintainer
#1 lore raw
Quoted 19 lines · Haotian Zhang

In sy7636a_sensor_probe(), regulator_enable() is called but if devm_hwmon_device_register_with_info() fails, the function returns without calling regulator_disable(), leaving the regulator enabled and leaking the reference count.

Add regulator_disable() call in the error path to properly disable the regulator.

Fixes de34a4053250 ("hwmon: sy7636a: Add temperature driver for sy7636a")
---
  drivers/hwmon/sy7636a-hwmon.c | 1 +
  1 file changed, 1 insertion(+)
drivers/hwmon/sy7636a-hwmon.c +0 -0
index ed110884786b..b8e598a616ad 100644

drivers/hwmon/sy7636a-hwmon.c static int sy7636a_sensor_probe(struct platform_device *pdev) · line 91

Quoted 4 lines
drivers/hwmon/sy7636a-hwmon.c +1 -0
@@ -88,6 +88,7 @@ static int sy7636a_sensor_probe(struct platform_device *pdev)
  	if (IS_ERR(hwmon_dev)) {
  		err = PTR_ERR(hwmon_dev);
  		dev_err(&pdev->dev, "Unable to register hwmon device, returned %d\n", err);
+		regulator_disable(regulator);

I would suggest to use devm_regulator_get_enable() instead of devm_regulator_get() instead. That also solves the problem that regulator_disable() is not called when the driver is removed.

Thanks,
Guenter

#2 lore raw

PATCH v2 1/1 hwmon: sy7636a: Fix regulator_enable resource leak on error path

In reply to Haotian Zhang

In sy7636a_sensor_probe(), regulator_enable() is called but if devm_hwmon_device_register_with_info() fails, the function returns without calling regulator_disable(), leaving the regulator enabled and leaking the reference count.

Switch to devm_regulator_get_enable() to automatically manage the regulator resource.

Fixes de34a4053250 ("hwmon: sy7636a: Add temperature driver for sy7636a")

---
Changes in v2:
-Use devm_regulator_get_enable() instead as suggested by Guenter Roeck.

---
 drivers/hwmon/sy7636a-hwmon.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/hwmon/sy7636a-hwmon.c +1 -6
index ed110884786b..4cbca1e6e597 100644
@@ -66,18 +66,13 @@ static const struct hwmon_chip_info sy7636a_chip_info = {
 static int sy7636a_sensor_probe(struct platform_device *pdev)
 {
 	struct regmap *regmap = dev_get_regmap(pdev->dev.parent, NULL);
-	struct regulator *regulator;
 	struct device *hwmon_dev;
 	int err;
 
 	if (!regmap)
 		return -EPROBE_DEFER;
 
-	regulator = devm_regulator_get(&pdev->dev, "vcom");
-	if (IS_ERR(regulator))
-		return PTR_ERR(regulator);
-
-	err = regulator_enable(regulator);
+	err = devm_regulator_get_enable(&pdev->dev, "vcom");
 	if (err)
 		return err;
 
Signature · 1 line
2.50.1.windows.1
maintainer Applied
#3 lore raw
Quoted 11 lines · Haotian Zhang

In sy7636a_sensor_probe(), regulator_enable() is called but if devm_hwmon_device_register_with_info() fails, the function returns without calling regulator_disable(), leaving the regulator enabled and leaking the reference count.

Switch to devm_regulator_get_enable() to automatically manage the regulator resource.

Fixes de34a4053250 ("hwmon: sy7636a: Add temperature driver for sy7636a")

Applied.

Thanks,
Guenter