Commit 425756f937f1 for kernel
commit 425756f937f134d175b5fe263581d8db90fa1afd
Author: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
Date: Thu Dec 3 15:13:30 2026 +0400
hwmon: (da9052) Tie the tsiref regulator to the hwmon device
da9052_hwmon_probe() calls devm_regulator_get_enable_read_voltage() on
the parent MFD device, because the tsiref supply is described in the
PMIC node. The reference and the enable then belong to the parent and
are not dropped when the probe fails later or when the hwmon driver is
unbound. Every new bind enables the regulator once more.
Look the regulator up on the parent, but enable it with the plain
calls and disable and put it from a devm action of the hwmon device.
Fixes: d72fd5228c9f ("hwmon: (da9052) Use devm_regulator_get_enable_read_voltage()")
Cc: stable@vger.kernel.org
Reviewed-by: David Lechner <dlechner@baylibre.com>
Signed-off-by: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
Link: https://patch.msgid.link/20261203-s2p-lpr-hwmon-v2-1-8d808e44d20e@mbzuai.ac.ae
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
diff --git a/drivers/hwmon/da9052-hwmon.c b/drivers/hwmon/da9052-hwmon.c
index a795b71c54f6..58131398b166 100644
--- a/drivers/hwmon/da9052-hwmon.c
+++ b/drivers/hwmon/da9052-hwmon.c
@@ -391,6 +391,47 @@ static irqreturn_t da9052_tsi_datardy_irq(int irq, void *data)
return IRQ_HANDLED;
}
+static void da9052_tsiref_disable(void *data)
+{
+ struct regulator *tsiref = data;
+
+ regulator_disable(tsiref);
+ regulator_put(tsiref);
+}
+
+/*
+ * The tsiref supply is a property of the parent node, so look it up there,
+ * but let this device own the reference and the enable.
+ */
+static int da9052_tsiref_get_enable_read_voltage(struct device *dev)
+{
+ struct regulator *tsiref;
+ int ret;
+
+ /*
+ * The supply is not optional. As in
+ * devm_regulator_get_enable_read_voltage(), use
+ * regulator_get_optional() to fail with -ENODEV here instead of
+ * getting a dummy regulator and failing later with -EINVAL in
+ * regulator_get_voltage().
+ */
+ tsiref = regulator_get_optional(dev->parent, "tsiref");
+ if (IS_ERR(tsiref))
+ return PTR_ERR(tsiref);
+
+ ret = regulator_enable(tsiref);
+ if (ret) {
+ regulator_put(tsiref);
+ return ret;
+ }
+
+ ret = devm_add_action_or_reset(dev, da9052_tsiref_disable, tsiref);
+ if (ret)
+ return ret;
+
+ return regulator_get_voltage(tsiref);
+}
+
static int da9052_hwmon_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
@@ -413,8 +454,7 @@ static int da9052_hwmon_probe(struct platform_device *pdev)
device_property_read_bool(pdev->dev.parent, "dlg,tsi-as-adc");
if (hwmon->tsi_as_adc) {
- tsiref_uv = devm_regulator_get_enable_read_voltage(dev->parent,
- "tsiref");
+ tsiref_uv = da9052_tsiref_get_enable_read_voltage(dev);
if (tsiref_uv < 0)
return dev_err_probe(dev, tsiref_uv,
"failed to get tsiref voltage\n");