[PATCH v3] mfd: stmpe: Disable regulators on probe failure

Haoran Wang wanghr2026 at mail.zgclab.edu.cn
Tue Dec 1 23:15:28 PST 2026


The VCC and VIO supplies are enabled in stmpe_probe() but were never
disabled if probing failed later, leaking the enabled regulators.

Register a devm action to disable each supply as soon as it has been
successfully enabled, and drop the manual regulator_disable() calls
from stmpe_remove() so the supplies are disabled exactly once via
devres.

Fixes: 9c9e321455fb ("mfd: stmpe: add optional regulators")
Signed-off-by: Haoran Wang <wanghr2026 at mail.zgclab.edu.cn>
---
Changes in v3:
- Register a devm action per regulator as soon as it is enabled, using a
  stmpe_disable_regulator() callback, instead of tracking the enabled
  state in vcc_enabled/vio_enabled flags (suggested by Lee Jones).

Changes in v2:
- Track whether each supply was enabled in dedicated flags rather than
  consulting regulator_is_enabled(), which reports hardware state.
- Drop the manual regulator_disable() calls from stmpe_remove() so the
  supplies are disabled exactly once.

 drivers/mfd/stmpe.c | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)

diff --git a/drivers/mfd/stmpe.c b/drivers/mfd/stmpe.c
index fd51ba74275c..e28419263ef5 100644
--- a/drivers/mfd/stmpe.c
+++ b/drivers/mfd/stmpe.c
@@ -1362,6 +1362,11 @@ static void stmpe_of_probe(struct stmpe_platform_data *pdata,
 	}
 }

+static void stmpe_disable_regulator(void *regulator)
+{
+	regulator_disable(regulator);
+}
+
 /* Called from client specific probe routines */
 int stmpe_probe(struct stmpe_client_info *ci, enum stmpe_partnum partnum)
 {
@@ -1408,14 +1413,28 @@ int stmpe_probe(struct stmpe_client_info *ci, enum stmpe_partnum partnum)
 	stmpe->vcc = devm_regulator_get_optional(ci->dev, "vcc");
 	if (!IS_ERR(stmpe->vcc)) {
 		ret = regulator_enable(stmpe->vcc);
-		if (ret)
+		if (ret) {
 			dev_warn(ci->dev, "failed to enable VCC supply\n");
+		} else {
+			ret = devm_add_action_or_reset(ci->dev,
+						       stmpe_disable_regulator,
+						       stmpe->vcc);
+			if (ret)
+				return ret;
+		}
 	}
 	stmpe->vio = devm_regulator_get_optional(ci->dev, "vio");
 	if (!IS_ERR(stmpe->vio)) {
 		ret = regulator_enable(stmpe->vio);
-		if (ret)
+		if (ret) {
 			dev_warn(ci->dev, "failed to enable VIO supply\n");
+		} else {
+			ret = devm_add_action_or_reset(ci->dev,
+						       stmpe_disable_regulator,
+						       stmpe->vio);
+			if (ret)
+				return ret;
+		}
 	}
 	dev_set_drvdata(stmpe->dev, stmpe);

@@ -1489,11 +1508,6 @@ void stmpe_remove(struct stmpe *stmpe)
 	if (stmpe->domain)
 		irq_domain_remove(stmpe->domain);

-	if (!IS_ERR(stmpe->vio) && regulator_is_enabled(stmpe->vio))
-		regulator_disable(stmpe->vio);
-	if (!IS_ERR(stmpe->vcc) && regulator_is_enabled(stmpe->vcc))
-		regulator_disable(stmpe->vcc);
-
 	__stmpe_disable(stmpe, STMPE_BLOCK_ADC);

 	mfd_remove_devices(stmpe->dev);

---

PoC reproduction (7.4.0-rc2, arm64 QEMU virt, unmodified kernel):

Device tree injection, spliced into the QEMU virt machine DT:

    reg_vcc: regulator-0 { compatible = "regulator-fixed";
        regulator-name = "stmpe-vcc"; regulator-min-microvolt = <3300000>;
        regulator-max-microvolt = <3300000>; };

    reg_vio: regulator-1 { compatible = "regulator-fixed";
        regulator-name = "stmpe-vio"; regulator-min-microvolt = <1800000>;
        regulator-max-microvolt = <1800000>; };

    i2c at 0 { compatible = "i2c-gpio";
        sda-gpios = <&gpio0 0 0>; scl-gpios = <&gpio0 1 0>;
        i2c-gpio,delay-us = <2>; #address-cells = <1>; #size-cells = <0>;
        stmpe811 at 41 { compatible = "st,stmpe811"; reg = <0x41>;
            vcc-supply = <&reg_vcc>; vio-supply = <&reg_vio>; }; };

The stmpe811 node has no interrupts property, so the probe enables both
rails and then returns -ENODEV on the no-irq check.

Trigger:

    modprobe i2c-gpio
    modprobe stmpe-i2c

Result:

    stmpe-i2c 0-0041: stmpe811 configured in no-irq mode by platform data
    stmpe-i2c 0-0041: stmpe811 does not support no-irq mode!
    WARNING: drivers/regulator/core.c:2678 at _regulator_put
    WARNING: drivers/regulator/core.c:2678 at _regulator_put

Two warnings, one per leaked rail, and the regulator use counts go from
1 to 2 after the failed probe.

Note: the PoC was generated with AI assistance and the vulnerability was
found by static analysis. The device tree is trusted input (a bad DT
requires root or physical access), so this is not a security fix, but it
prevents a potential resource leak or system failure on a failed probe or
an old or malformed DT.




More information about the linux-arm-kernel mailing list