mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Esben Haabendal <esben@geanix.com>
Cc: "Lars-Peter Clausen" <lars@metafoo.de>,
	"Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	"Martin Kepplinger" <martink@posteo.de>,
	"Sean Nyekjaer" <sean@geanix.com>,
	"David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	"Martin Kepplinger" <martin.kepplinger@theobroma-systems.com>,
	"Christoph Muellner" <christoph.muellner@theobroma-systems.com>,
	linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH v10 03/10] iio: accel: mma8452: Fix runtime PM bugs in mma8452_read()
Date: Sun, 11 Oct 2026 13:19:46 +0100	[thread overview]
Message-ID: <20261011131946.16bf4ef2@jic23-hlaptop> (raw)
In-Reply-To: <20260928-mma8452-open-drain-v10-3-b906fb408386@geanix.com>

On Mon, 28 Sep 2026 10:26:19 +0200
Esben Haabendal <esben@geanix.com> wrote:

> When runtime PM support was added [1], the implementation in mma8452_read()
> was done incorrectly, as it calls mma8452_drdy() before ensuring runtime pm
> has set the device active, so it can cause read from STATUS register while
> device is suspended/off. At the same time, the return value from
> i2c_smbus_read_i2c_block_data() was discarded, and the function would
> return the value returned from pm_runtime_put_autosuspend() instead.
> 
> When the latter bug described above was fixed [2], another bug was
> introduced, as mma8452_read() would now leak the runtime PM reference
> counter when i2c_smbus_read_i2c_block_data() failed.
> 
> This commit corrects this mess.
> 
> [1] commit 96c0cb2bbfe0 ("iio: mma8452: add support for runtime power management")
> [2] commit 5bdff291d20c ("iio: accel: mma8452: handle I2C read error(s) in mma8452_read()")
> 
> Fixes: 96c0cb2bbfe0 ("iio: mma8452: add support for runtime power management")
> Cc: stable@vger.kernel.org
> Signed-off-by: Esben Haabendal <esben@geanix.com>

I suppose not directly relevant to this patch but that
set_runtime_pm_state() helper is definitely not helping.
I'd follow up with ripping that out and calling the two runtimme
pm calls directly.  Then you would be trivially able to use
ACQUIRE_RUNTIME_PM() etc to reduce complexity in places like this.

In more recent drivers I've always pushed back against that
sort of helper precisely because it stops other sensible refactors.

In general that also follows the common pattern of not checking for
errors in the put as that trips up on things like !CONFIG_PM and
is generally not that useful!

Jonathan
> ---
>  drivers/iio/accel/mma8452.c | 16 ++++++++++------
>  1 file changed, 10 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
> index a937cbd84f30..a77c4b88b61d 100644
> --- a/drivers/iio/accel/mma8452.c
> +++ b/drivers/iio/accel/mma8452.c
> @@ -242,21 +242,25 @@ static int mma8452_set_runtime_pm_state(struct i2c_client *client, bool on)
>  
>  static int mma8452_read(struct mma8452_data *data, __be16 buf[3])
>  {
> -	int ret = mma8452_drdy(data);
> -
> -	if (ret < 0)
> -		return ret;
> +	int ret;
>  
>  	ret = mma8452_set_runtime_pm_state(data->client, true);
>  	if (ret)
>  		return ret;
>  
> +	ret = mma8452_drdy(data);
> +	if (ret < 0)
> +		goto out_runtime_put;
> +
>  	ret = i2c_smbus_read_i2c_block_data(data->client, MMA8452_OUT_X,
>  					    3 * sizeof(__be16), (u8 *)buf);
>  	if (ret < 0)
> -		return ret;
> +		goto out_runtime_put;
> +
> +	return mma8452_set_runtime_pm_state(data->client, false);
>  
> -	ret = mma8452_set_runtime_pm_state(data->client, false);
> +out_runtime_put:
> +	mma8452_set_runtime_pm_state(data->client, false);
>  
>  	return ret;
>  }
> 


  reply	other threads:[~2026-10-11 12:20 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-28  8:26 [PATCH v10 00/10] io: accel: mma8452: Allow open drain interrupt pin configuration Esben Haabendal
2026-09-28  8:26 ` [PATCH v10 01/10] dt-bindings: iio: accel: mma8452: Add drive-open-drain Esben Haabendal
2026-09-28  8:26 ` [PATCH v10 02/10] iio: accel: mma8452: Fix use-after-free bug in error error path Esben Haabendal
2026-09-28  8:26 ` [PATCH v10 03/10] iio: accel: mma8452: Fix runtime PM bugs in mma8452_read() Esben Haabendal
2026-10-11 12:19   ` Jonathan Cameron [this message]
2026-09-28  8:26 ` [PATCH v10 04/10] iio: accel: mma8452: Optimize struct mma8452_data member orders Esben Haabendal
2026-09-28  8:26 ` [PATCH v10 05/10] iio: accel: mma8452: Only apply trigger type when not set by firmware Esben Haabendal
2026-09-28  8:26 ` [PATCH v10 06/10] iio: accel: mma8452: Fix unintended comment indent Esben Haabendal
2026-09-28  8:26 ` [PATCH v10 07/10] iio: accel: mma8452: Add comment block for struct mma8452_data Esben Haabendal
2026-09-28  8:26 ` [PATCH v10 08/10] iio: accel: mma8452: Allow open drain interrupt pin configuration Esben Haabendal
2026-09-28  8:26 ` [PATCH v10 09/10] iio: accel: mma8452: Use proper error code when missing device model Esben Haabendal
2026-09-28  8:26 ` [PATCH v10 10/10] iio: accel: mma8452: Support interrupt sharing Esben Haabendal
2026-09-28  9:26   ` Andy Shevchenko
2026-09-28 10:15     ` Esben Haabendal
2026-09-28 10:17       ` Esben Haabendal
2026-10-11 12:41       ` Jonathan Cameron
2026-09-28 10:27     ` Joshua Crofts
2026-10-11 13:00 ` [PATCH v10 00/10] io: accel: mma8452: Allow open drain interrupt pin configuration 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=20261011131946.16bf4ef2@jic23-hlaptop \
    --to=jic23@kernel.org \
    --cc=andy@kernel.org \
    --cc=christoph.muellner@theobroma-systems.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=esben@geanix.com \
    --cc=krzk+dt@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.kepplinger@theobroma-systems.com \
    --cc=martink@posteo.de \
    --cc=nuno.sa@analog.com \
    --cc=robh@kernel.org \
    --cc=sean@geanix.com \
    --cc=stable@vger.kernel.org \
    /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®