From: Jonathan Cameron <jic23@kernel.org>
To: Stepan Ionichev <sozdayvek@gmail.com>
Cc: dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 4/4] iio: accel: mma8452: use devm_pm_runtime_enable() to fix probe error path
Date: Fri, 29 May 2026 18:23:20 +0100 [thread overview]
Message-ID: <20260529182320.4f45e53c@jic23-huawei> (raw)
In-Reply-To: <e10c970e911bf68e62e0a58d48b3513f1f947587.1780051096.git.sozdayvek@gmail.com>
On Fri, 29 May 2026 15:45:44 +0500
Stepan Ionichev <sozdayvek@gmail.com> wrote:
> mma8452_probe() calls pm_runtime_enable() and then iio_device_register().
> If iio_device_register() fails the function jumps to buffer_cleanup but
> the existing manual unwind does not call pm_runtime_disable(), leaking the
> runtime PM enable_count on probe failure and on subsequent rebind.
>
> Switch to devm_pm_runtime_enable() so the enable (and the matching
> dont_use_autosuspend) are torn down automatically. On its new error path
> the probe jumps to the existing buffer_cleanup label so the triggered
> buffer, trigger and regulator cleanup chain stays intact. The
> pm_runtime_disable() and pm_runtime_set_suspended() calls in
> mma8452_remove() are dropped; the devm action runs after .remove() and
> handles the teardown.
>
> Signed-off-by: Stepan Ionichev <sozdayvek@gmail.com>
Same again on not mixing devm with goto.
Side effect here is that the tear down order is completely different from
reverse of setup.
> ---
> drivers/iio/accel/mma8452.c | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
> index 15172ba2972c..88ed47d33e03 100644
> --- a/drivers/iio/accel/mma8452.c
> +++ b/drivers/iio/accel/mma8452.c
> @@ -1693,7 +1693,9 @@ static int mma8452_probe(struct i2c_client *client)
> if (ret < 0)
> goto buffer_cleanup;
>
> - pm_runtime_enable(&client->dev);
> + ret = devm_pm_runtime_enable(&client->dev);
> + if (ret)
> + goto buffer_cleanup;
> pm_runtime_set_autosuspend_delay(&client->dev,
> MMA8452_AUTO_SUSPEND_DELAY_MS);
> pm_runtime_use_autosuspend(&client->dev);
> @@ -1733,9 +1735,6 @@ static void mma8452_remove(struct i2c_client *client)
>
> iio_device_unregister(indio_dev);
>
> - pm_runtime_disable(&client->dev);
> - pm_runtime_set_suspended(&client->dev);
> -
> iio_triggered_buffer_cleanup(indio_dev);
> mma8452_trigger_cleanup(indio_dev);
> mma8452_standby(iio_priv(indio_dev));
next prev parent reply other threads:[~2026-05-29 17:23 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-29 10:45 [PATCH 0/4] iio: PM-enable leak on probe error path (goto-variant drivers) Stepan Ionichev
2026-05-29 10:45 ` [PATCH 1/4] iio: light: pa12203001: use devm_pm_runtime_enable() to fix probe error path Stepan Ionichev
2026-05-29 17:19 ` Jonathan Cameron
2026-05-29 10:45 ` [PATCH 2/4] iio: light: us5182d: " Stepan Ionichev
2026-05-29 17:20 ` Jonathan Cameron
2026-05-29 10:45 ` [PATCH 3/4] iio: light: apds9960: " Stepan Ionichev
2026-05-29 17:22 ` Jonathan Cameron
2026-05-29 10:45 ` [PATCH 4/4] iio: accel: mma8452: " Stepan Ionichev
2026-05-29 17:23 ` Jonathan Cameron [this message]
2026-05-29 13:08 ` [PATCH 0/4] iio: PM-enable leak on probe error path (goto-variant drivers) Jonathan Cameron
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=20260529182320.4f45e53c@jic23-huawei \
--to=jic23@kernel.org \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=sozdayvek@gmail.com \
/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
all inboxes | Powered by JetHome®