Linux IIO development
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Sean Nyekjaer <sean@geanix.com>
Cc: "Jean-Baptiste Maneyrol" <jean-baptiste.maneyrol@tdk.com>,
	"David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 6/6] iio: imu: inv_icm42600: Avoid configuring if already pm_runtime suspended
Date: Wed, 16 Jul 2025 09:06:55 +0100	[thread overview]
Message-ID: <20250716090655.0ba30a2a@jic23-huawei> (raw)
In-Reply-To: <kcrov3lqigiqzea2eds73ibhix46ovqrqkhodfatqwfmjanxya@l2cla3fkl6ow>

On Mon, 14 Jul 2025 10:15:59 +0000
Sean Nyekjaer <sean@geanix.com> wrote:

> On Sun, Jul 13, 2025 at 03:32:27PM +0100, Jonathan Cameron wrote:
> > On Wed, 09 Jul 2025 14:35:14 +0200
> > Sean Nyekjaer <sean@geanix.com> wrote:
> >   
> > > Do as in suspend, skip resume configuration steps if the device is already
> > > pm_runtime suspended. This avoids reconfiguring a device that is already
> > > in the correct low-power state and ensures that pm_runtimeM handles the
> > > power state transitions properly.
> > >
> > > Fixes: 31c24c1e93c3 ("iio: imu: inv_icm42600: add core of new inv_icm42600 driver")
> > > Signed-off-by: Sean Nyekjaer <sean@geanix.com>
> > > ---  
> > 
> > Not really related to what you have here, but this code would really
> > benefit from using guard(mutex)()
> > 
> > Jonathan  
> 
> I have converted most of this driver to use guard(mutex).
> 
> Does it make sense to use guard(mutex) in functions that still relies on
> goto error out? Like...

No - general rule is never combine cleanup.h magic like guard with gotos.

If you do want to use it in cases like this, factor out the stuff
> 
> static int inv_icm42600_temp_read(struct inv_icm42600_state *st, s16 *temp)
> {
> 	struct device *dev = regmap_get_device(st->map);
> 	__be16 *raw;
> 	int ret;
> 
> 	pm_runtime_get_sync(dev);
> 	mutex_lock(&st->lock);
> 

from here

> 	ret = inv_icm42600_set_temp_conf(st, true, NULL);
> 	if (ret)
> 		goto exit;
> 
> 	raw = (__be16 *)&st->buffer[0];
> 	ret = regmap_bulk_read(st->map, INV_ICM42600_REG_TEMP_DATA, raw, sizeof(*raw));
> 	if (ret)
> 		goto exit;
> 
> 	*temp = (s16)be16_to_cpup(raw);
> 	if (*temp == INV_ICM42600_DATA_INVALID)
> 		ret = -EINVAL;
> 

to here as a utility function.  Then can use direct returns in that 
function and there are no gotos to worry about.

> exit:
> 	mutex_unlock(&st->lock);
> 	pm_runtime_mark_last_busy(dev);
> 	pm_runtime_put_autosuspend(dev);
> 
> 	return ret;
> }
> 
> 
> If I use guard_scoped(..) it creates a lot of diff lines...
The only way to use that here and avoid the issue would be with breaks
which is ugly.   If we are going to pay the cost of churn, then
factoring out the guts of the function is much cleaner.

May not be worth bothering though!

Jonathan

> 
> /Sean
> 


  reply	other threads:[~2025-07-16  8:07 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-09 12:35 [PATCH 0/6] iio: imu: inv_icm42600: pm_runtime fixes + various changes Sean Nyekjaer
2025-07-09 12:35 ` [PATCH 1/6] iio: imu: inv_icm42600: Use inv_icm42600_disable_vddio_reg() Sean Nyekjaer
2025-07-13 14:17   ` Jonathan Cameron
2025-07-09 12:35 ` [PATCH 2/6] iio: imu: inv_icm42600: Use devm_regulator_get_enable() for vdd regulator Sean Nyekjaer
2025-07-13 14:19   ` Jonathan Cameron
2025-07-09 12:35 ` [PATCH 3/6] iio: imu: inv_icm42600: Remove redundant error msg on regulator_disable() Sean Nyekjaer
2025-07-10  9:03   ` Andy Shevchenko
2025-07-10 10:47     ` Sean Nyekjaer
2025-07-10 13:07       ` Andy Shevchenko
2025-07-13 14:22   ` Jonathan Cameron
2025-07-09 12:35 ` [PATCH 4/6] iio: imu: inv_icm42600: Simplify pm_runtime setup Sean Nyekjaer
2025-07-10  9:08   ` Andy Shevchenko
2025-07-10 10:45     ` Sean Nyekjaer
2025-07-10 12:23       ` Andy Shevchenko
2025-07-13 14:28   ` Jonathan Cameron
2025-07-14  7:24     ` Sean Nyekjaer
2025-07-14  7:42       ` Sean Nyekjaer
2025-07-16  8:00         ` Jonathan Cameron
2025-07-18  6:40           ` Sean Nyekjaer
2025-07-19 11:47             ` Jonathan Cameron
2025-07-19 13:32               ` Jonathan Cameron
2025-08-08 13:42                 ` Sean Nyekjaer
2025-07-09 12:35 ` [PATCH 5/6] iio: imu: inv_icm42600: Drop redundant pm_runtime reinitialization in resume Sean Nyekjaer
2025-07-09 12:35 ` [PATCH 6/6] iio: imu: inv_icm42600: Avoid configuring if already pm_runtime suspended Sean Nyekjaer
2025-07-10  9:11   ` Andy Shevchenko
2025-07-13 14:32   ` Jonathan Cameron
2025-07-14 10:15     ` Sean Nyekjaer
2025-07-16  8:06       ` Jonathan Cameron [this message]
2025-07-10  9:12 ` [PATCH 0/6] iio: imu: inv_icm42600: pm_runtime fixes + various changes Andy Shevchenko

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=20250716090655.0ba30a2a@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=andy@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=jean-baptiste.maneyrol@tdk.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    --cc=sean@geanix.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