From: Lee Jones <lee@kernel.org>
To: Haoran Wang <wanghr2026@mail.zgclab.edu.cn>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>,
Alexandre Torgue <alexandre.torgue@foss.st.com>,
mfd@lists.linux.dev, linux-stm32@st-md-mailman.stormreply.com,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] mfd: stmpe: Disable regulators on probe failure
Date: Fri, 27 Nov 2026 15:07:15 +0000 [thread overview]
Message-ID: <179568586298.32537.18171310345438853843@kernel.org> (raw)
In-Reply-To: <179534733065.15652.3659794654405986240@mail.zgclab.edu.cn>
On Sun, 22 Nov 2026, Haoran Wang wrote:
> 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 the supplies, and track whether each
> supply was enabled in dedicated flags instead of consulting
> regulator_is_enabled(), which reports the hardware state rather than
> whether this consumer enabled it. Drop the manual regulator_disable()
> calls from stmpe_remove() so the supplies are disabled exactly once via
> the devres action.
>
> Fixes: 9c9e321455fb ("mfd: stmpe: add optional regulators")
> Signed-off-by: Haoran Wang <wanghr2026@mail.zgclab.edu.cn>
> ---
Changelog?
> drivers/mfd/stmpe.c | 24 +++++++++++++++++++-----
> include/linux/mfd/stmpe.h | 2 ++
> 2 files changed, 21 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/mfd/stmpe.c b/drivers/mfd/stmpe.c
> index fd51ba74275c..fb30b8a4fbac 100644
> --- a/drivers/mfd/stmpe.c
> +++ b/drivers/mfd/stmpe.c
> @@ -1362,6 +1362,16 @@ static void stmpe_of_probe(struct stmpe_platform_data *pdata,
> }
> }
>
> +static void stmpe_disable_regulators(void *data)
> +{
> + struct stmpe *stmpe = data;
> +
> + if (stmpe->vio_enabled)
> + regulator_disable(stmpe->vio);
> + if (stmpe->vcc_enabled)
> + regulator_disable(stmpe->vcc);
> +}
Yeah, this is worse!
Instead of manually tracking these, why not use devm_add_action_or_reset() for each?
static void stmpe_disable_regulator(void *regulator)
{
regulator_disable(regulator);
}
Then, when regulator_enable() succeeds:
ret = devm_add_action_or_reset(ci->dev, stmpe_disable_regulator, stmpe->vcc);
if (ret)
return ret;
ret = devm_add_action_or_reset(ci->dev, stmpe_disable_regulator, stmpe->vio);
if (ret)
return ret;
> /* Called from client specific probe routines */
> int stmpe_probe(struct stmpe_client_info *ci, enum stmpe_partnum partnum)
> {
> @@ -1410,13 +1420,22 @@ int stmpe_probe(struct stmpe_client_info *ci, enum stmpe_partnum partnum)
> ret = regulator_enable(stmpe->vcc);
> if (ret)
> dev_warn(ci->dev, "failed to enable VCC supply\n");
> + else
> + stmpe->vcc_enabled = true;
> }
> stmpe->vio = devm_regulator_get_optional(ci->dev, "vio");
> if (!IS_ERR(stmpe->vio)) {
> ret = regulator_enable(stmpe->vio);
> if (ret)
> dev_warn(ci->dev, "failed to enable VIO supply\n");
> + else
> + stmpe->vio_enabled = true;
> }
> +
> + ret = devm_add_action_or_reset(ci->dev, stmpe_disable_regulators, stmpe);
> + if (ret)
> + return ret;
> +
> dev_set_drvdata(stmpe->dev, stmpe);
>
> if (ci->init)
> @@ -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);
> diff --git a/include/linux/mfd/stmpe.h b/include/linux/mfd/stmpe.h
> index 87e29d561e22..eec5fc795014 100644
> --- a/include/linux/mfd/stmpe.h
> +++ b/include/linux/mfd/stmpe.h
> @@ -122,6 +122,8 @@ struct stmpe_platform_data;
> struct stmpe {
> struct regulator *vcc;
> struct regulator *vio;
> + bool vcc_enabled;
> + bool vio_enabled;
> struct mutex lock;
> struct mutex irq_lock;
> struct device *dev;
>
--
Lee Jones
prev parent reply other threads:[~2026-11-27 15:07 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-22 11:35 [PATCH v2] mfd: stmpe: Disable regulators on probe failure Haoran Wang
2026-11-27 15:07 ` Lee Jones [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=179568586298.32537.18171310345438853843@kernel.org \
--to=lee@kernel.org \
--cc=alexandre.torgue@foss.st.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=mcoquelin.stm32@gmail.com \
--cc=mfd@lists.linux.dev \
--cc=wanghr2026@mail.zgclab.edu.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox