* [PATCH] hwmon: (da9052) Tie the tsiref regulator to the hwmon device
@ 2026-12-01 19:26 Arina Kharlamova via B4 Relay
2026-12-01 19:32 ` sashiko-bot
2026-12-01 19:51 ` David Lechner
0 siblings, 2 replies; 3+ messages in thread
From: Arina Kharlamova via B4 Relay @ 2026-12-01 19:26 UTC (permalink / raw)
To: Support Opensource, Guenter Roeck, Liam Girdwood, Mark Brown,
David Lechner, Jonathan Cameron
Cc: linux-hwmon, linux-kernel, stable, Arina Kharlamova
From: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
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
Signed-off-by: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
---
The tsiref regulator stays enabled after unbind or a failed probe,
and every bind enables it once more.
I found this with spec2patch. I model-checked the probe and remove paths
of the driver with CBMC against formal specifications of the kernel APIs
it calls. The specifications are checked against the kernel source, and
some of them are proved in Rocq against a transcription of the kernel
code. I also checked lock usage separately. With the help of an AI
coding assistant (Claude); I reviewed the analysis and the fix.
Compile-tested only, not tested on hardware.
---
drivers/hwmon/da9052-hwmon.c | 37 +++++++++++++++++++++++++++++++++++--
1 file changed, 35 insertions(+), 2 deletions(-)
diff --git a/drivers/hwmon/da9052-hwmon.c b/drivers/hwmon/da9052-hwmon.c
index a795b71c54f6..428da8022695 100644
--- a/drivers/hwmon/da9052-hwmon.c
+++ b/drivers/hwmon/da9052-hwmon.c
@@ -391,6 +391,40 @@ 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_enable_read_voltage(struct device *dev)
+{
+ struct regulator *tsiref;
+ int ret;
+
+ 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 +447,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_enable_read_voltage(dev);
if (tsiref_uv < 0)
return dev_err_probe(dev, tsiref_uv,
"failed to get tsiref voltage\n");
---
base-commit: 32a9f95f4fd42a0b7c0b750597e68175948fd3d0
change-id: 20261201-s2p-lpr-hwmon-fb3f04daaa75
Best regards,
--
Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] hwmon: (da9052) Tie the tsiref regulator to the hwmon device
2026-12-01 19:26 [PATCH] hwmon: (da9052) Tie the tsiref regulator to the hwmon device Arina Kharlamova via B4 Relay
@ 2026-12-01 19:32 ` sashiko-bot
2026-12-01 19:51 ` David Lechner
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-12-01 19:32 UTC (permalink / raw)
To: Arina Kharlamova; +Cc: linux-hwmon
> From: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
>
> 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
> Signed-off-by: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201-s2p-lpr-hwmon-v1-1-c9dacf93eae1@mbzuai.ac.ae?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] hwmon: (da9052) Tie the tsiref regulator to the hwmon device
2026-12-01 19:26 [PATCH] hwmon: (da9052) Tie the tsiref regulator to the hwmon device Arina Kharlamova via B4 Relay
2026-12-01 19:32 ` sashiko-bot
@ 2026-12-01 19:51 ` David Lechner
1 sibling, 0 replies; 3+ messages in thread
From: David Lechner @ 2026-12-01 19:51 UTC (permalink / raw)
To: arina.kharlamova, Support Opensource, Guenter Roeck,
Liam Girdwood, Mark Brown, Jonathan Cameron
Cc: linux-hwmon, linux-kernel, stable
On 12/1/26 1:26 PM, Arina Kharlamova via B4 Relay wrote:
> From: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
>
> 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
> Signed-off-by: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
> ---
> The tsiref regulator stays enabled after unbind or a failed probe,
> and every bind enables it once more.
>
> I found this with spec2patch. I model-checked the probe and remove paths
> of the driver with CBMC against formal specifications of the kernel APIs
> it calls. The specifications are checked against the kernel source, and
> some of them are proved in Rocq against a transcription of the kernel
> code. I also checked lock usage separately. With the help of an AI
> coding assistant (Claude); I reviewed the analysis and the fix.
> Compile-tested only, not tested on hardware.
> ---
> drivers/hwmon/da9052-hwmon.c | 37 +++++++++++++++++++++++++++++++++++--
> 1 file changed, 35 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/hwmon/da9052-hwmon.c b/drivers/hwmon/da9052-hwmon.c
> index a795b71c54f6..428da8022695 100644
> --- a/drivers/hwmon/da9052-hwmon.c
> +++ b/drivers/hwmon/da9052-hwmon.c
> @@ -391,6 +391,40 @@ 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_enable_read_voltage(struct device *dev)
> +{
> + struct regulator *tsiref;
> + int ret;
> +
Could use a comment similar to the one from devm_regulator_get_enable_read_voltage()
to explain why we use optional here (to get -ENODEV here instead of -EINVAL later).
It is not actually optional.
> + 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 +447,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_enable_read_voltage(dev);
Why not da9052_tsiref_get_enable_read_voltage()?
> if (tsiref_uv < 0)
> return dev_err_probe(dev, tsiref_uv,
> "failed to get tsiref voltage\n");
>
> ---
> base-commit: 32a9f95f4fd42a0b7c0b750597e68175948fd3d0
> change-id: 20261201-s2p-lpr-hwmon-fb3f04daaa75
>
> Best regards,
> --
> Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
I made a few suggestions for improvement, but the important parts look
correct so...
Reviewed-by: David Lechner <dlechner@baylibre.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-01 19:51 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 19:26 [PATCH] hwmon: (da9052) Tie the tsiref regulator to the hwmon device Arina Kharlamova via B4 Relay
2026-12-01 19:32 ` sashiko-bot
2026-12-01 19:51 ` David Lechner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox