[PATCH v2] hwmon: sy7636a: Fix regulator_enable resource leak on error path

Haotian Zhang posted 1 patch 5 days, 5 hours ago
drivers/hwmon/sy7636a-hwmon.c | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
[PATCH v2] hwmon: sy7636a: Fix regulator_enable resource leak on error path
Posted by Haotian Zhang 5 days, 5 hours ago
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")
Suggested-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
---
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(-)

diff --git a/drivers/hwmon/sy7636a-hwmon.c b/drivers/hwmon/sy7636a-hwmon.c
index ed110884786b..4cbca1e6e597 100644
--- a/drivers/hwmon/sy7636a-hwmon.c
+++ b/drivers/hwmon/sy7636a-hwmon.c
@@ -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;
 
-- 
2.50.1.windows.1
Re: [PATCH v2] hwmon: sy7636a: Fix regulator_enable resource leak on error path
Posted by Guenter Roeck 5 days, 5 hours ago
On Thu, Nov 27, 2025 at 12:26:02AM +0800, Haotian Zhang wrote:
> 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")
> Suggested-by: Guenter Roeck <linux@roeck-us.net>
> Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>

Applied.

Thanks,
Guenter