All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: "Rui Miguel Silva" <rui.silva@linaro.org>
Cc: "Mauro Carvalho Chehab" <mchehab+huawei@kernel.org>,
	<linux-iio@vger.kernel.org>,
	"Julia Lawall" <Julia.Lawall@inria.fr>,
	"Rafael J . Wysocki" <rjw@rjwysocki.net>,
	"Jonathan Cameron" <Jonathan.Cameron@huawei.com>
Subject: Re: [PATCH 01/28] iio: gyro: fxa210002c: Balance runtime pm + use pm_runtime_resume_and_get().
Date: Thu, 13 May 2021 17:35:57 +0100	[thread overview]
Message-ID: <20210513173557.2dfffa1b@jic23-huawei> (raw)
In-Reply-To: <20210513173131.64d84e4a@jic23-huawei>

On Thu, 13 May 2021 17:31:31 +0100
Jonathan Cameron <jic23@kernel.org> wrote:

> On Thu, 13 May 2021 09:34:52 +0100
> "Rui Miguel Silva" <rui.silva@linaro.org> wrote:
> 
> > Hi Mauro,
> > On Wed May 12, 2021 at 2:30 PM WEST, Mauro Carvalho Chehab wrote:
> >   
> > > Em Wed, 12 May 2021 15:22:43 +0200
> > > Mauro Carvalho Chehab <mchehab+huawei@kernel.org> escreveu:
> > >    
> > > > Em Sun,  9 May 2021 12:33:27 +0100
> > > > Jonathan Cameron <jic23@kernel.org> escreveu:
> > > >     
> > > > > From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > > > > 
> > > > > In both the probe() error path and remove() pm_runtime_put_noidle()
> > > > > is called which will decrement the runtime pm reference count.
> > > > > However, there is no matching function to have raised the reference count.
> > > > > Not this isn't a fix as the runtime pm core will stop the reference count
> > > > > going negative anyway.
> > > > > 
> > > > > An alternative would have been to raise the count in these paths, but
> > > > > it is not clear why that would be necessary.
> > > > > 
> > > > > Whilst we are here replace some boilerplate with pm_runtime_resume_and_get()
> > > > > Found using coccicheck script under review at:
> > > > > https://lore.kernel.org/lkml/20210427141946.2478411-1-Julia.Lawall@inria.fr/
> > > > > 
> > > > > Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > > > > Cc: Rui Miguel Silva <rui.silva@linaro.org>      
> > > > 
> > > > LGTM.
> > > > 
> > > > Reviewed-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>    
> > >
> > > Hmm...not quite...

Because the fix and the cleanup are in substantially different places in the
driver I'm going to assume git will sort it out and apply the original patch to my
togreg branch - initially pushed out as testing for bots to poke at.

Thanks,

Jonathan
> > >    
> > > > > diff --git a/drivers/iio/gyro/fxas21002c_core.c b/drivers/iio/gyro/fxas21002c_core.c
> > > > > index 5af7b48ff01a..539585b0d300 100644
> > > > > --- a/drivers/iio/gyro/fxas21002c_core.c
> > > > > +++ b/drivers/iio/gyro/fxas21002c_core.c
> > > > > @@ -366,14 +366,7 @@ static int fxas21002c_write(struct fxas21002c_data *data,
> > > > >  
> > > > >  static int  fxas21002c_pm_get(struct fxas21002c_data *data)
> > > > >  {
> > > > > -	struct device *dev = regmap_get_device(data->regmap);
> > > > > -	int ret;
> > > > > -
> > > > > -	ret = pm_runtime_get_sync(dev);
> > > > > -	if (ret < 0)
> > > > > -		pm_runtime_put_noidle(dev);
> > > > > -
> > > > > -	return ret;
> > > > > +	return pm_runtime_resume_and_get(regmap_get_device(data->regmap));
> > > > >  }    
> > >
> > > fxas21002c_temp_get() and fxas21002c_axis_get() seem to be
> > > missing a pm_runtime_put*() if something gets wrong at
> > > regmap_field_read(), e. g.:    
> > 
> > Thanks for catching this, you are right. However I think it should
> > have is own patch, since it is a real fix and this one is not.
> > 
> > Jonathan, bellow goes a proper patch, please feel free to squash this
> > on top of yours, or just apply it separately, your call.
> > 
> > Cheers,
> >      Rui
> > 
> > 8<-------------------------------------------------------------------
> > 
> > From 314a56247515c05c0c5504c1e305127878af0c9b Mon Sep 17 00:00:00 2001
> > From: Rui Miguel Silva <rui.silva@linaro.org>
> > Date: Wed, 12 May 2021 23:39:29 +0100
> > Subject: [PATCH] iio: gyro: fxas21002c: balance runtime power in error path
> > 
> > If we fail to read temperature or axis we need to decrement the
> > runtime pm reference count to trigger autosuspend.
> > 
> > Add the call to pm_put to do that in case of error.
> > 
> > Fixes: a0701b6263ae ("iio: gyro: add core driver for fxas21002c")
> > Suggested-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
> > Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>  
> 
> I've queued this as a fix in my fixes-togreg branch of iio.git and marked
> it for stable.
> 


> Thanks,
> 
> Jonathan
> 
> > ---
> >  drivers/iio/gyro/fxas21002c_core.c | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/drivers/iio/gyro/fxas21002c_core.c b/drivers/iio/gyro/fxas21002c_core.c
> > index 1a20c6b88e7d..645461c70454 100644
> > --- a/drivers/iio/gyro/fxas21002c_core.c
> > +++ b/drivers/iio/gyro/fxas21002c_core.c
> > @@ -399,6 +399,7 @@ static int fxas21002c_temp_get(struct fxas21002c_data *data, int *val)
> >  	ret = regmap_field_read(data->regmap_fields[F_TEMP], &temp);
> >  	if (ret < 0) {
> >  		dev_err(dev, "failed to read temp: %d\n", ret);
> > +		fxas21002c_pm_put(data);
> >  		goto data_unlock;
> >  	}
> >  
> > @@ -432,6 +433,7 @@ static int fxas21002c_axis_get(struct fxas21002c_data *data,
> >  			       &axis_be, sizeof(axis_be));
> >  	if (ret < 0) {
> >  		dev_err(dev, "failed to read axis: %d: %d\n", index, ret);
> > +		fxas21002c_pm_put(data);
> >  		goto data_unlock;
> >  	}
> >    
> 


  reply	other threads:[~2021-05-13 16:34 UTC|newest]

Thread overview: 99+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-09 11:33 [RESEND PATCH 00/28] IIO: Runtime PM related cleanups Jonathan Cameron
2021-05-09 11:33 ` [PATCH 01/28] iio: gyro: fxa210002c: Balance runtime pm + use pm_runtime_resume_and_get() Jonathan Cameron
2021-05-09 17:26   ` Rui Miguel Silva
2021-05-12 13:22   ` Mauro Carvalho Chehab
2021-05-12 13:30     ` Mauro Carvalho Chehab
2021-05-13  8:34       ` Rui Miguel Silva
2021-05-13 16:31         ` Jonathan Cameron
2021-05-13 16:35           ` Jonathan Cameron [this message]
2021-05-09 11:33 ` [PATCH 02/28] iio: light: isl29028: " Jonathan Cameron
2021-05-12 13:33   ` Mauro Carvalho Chehab
2021-05-13 16:37     ` Jonathan Cameron
2021-05-17 21:44   ` Linus Walleij
2021-05-09 11:33 ` [PATCH 03/28] iio: light: tsl2583: " Jonathan Cameron
2021-05-10 10:46   ` Brian Masney
2021-05-13 16:39     ` Jonathan Cameron
2021-05-12 13:35   ` Mauro Carvalho Chehab
2021-05-09 11:33 ` [PATCH 04/28] iio: accel: bmc150-accel: Balanced " Jonathan Cameron
2021-05-09 13:52   ` Hans de Goede
2021-05-13 16:41     ` Jonathan Cameron
2021-05-12 13:36   ` Mauro Carvalho Chehab
2021-05-09 11:33 ` [PATCH 05/28] iio: accel: mma8452: Balance " Jonathan Cameron
2021-05-12 13:37   ` Mauro Carvalho Chehab
2021-05-13 17:06     ` Jonathan Cameron
2021-05-09 11:33 ` [PATCH 06/28] iio: accel: mma9551/3: Balance untime " Jonathan Cameron
2021-05-12 13:37   ` Mauro Carvalho Chehab
2021-05-13 16:42     ` Jonathan Cameron
2021-05-09 11:33 ` [PATCH 07/28] iio: accel: kxcjk-1013: Balance runtime " Jonathan Cameron
2021-05-09 13:53   ` Hans de Goede
2021-05-12 13:39   ` Mauro Carvalho Chehab
2021-05-09 11:33 ` [PATCH 08/28] iio: hid: trigger: " Jonathan Cameron
2021-05-12 13:44   ` Mauro Carvalho Chehab
2021-05-16 15:19     ` Jonathan Cameron
2021-05-17  2:19       ` Srinivas Pandruvada
2021-05-17  8:43         ` Jonathan Cameron
2021-05-09 11:33 ` [PATCH 09/28] iio: imu: kmx61: " Jonathan Cameron
2021-05-12 13:45   ` Mauro Carvalho Chehab
2021-05-13 16:46     ` Jonathan Cameron
2021-05-09 11:33 ` [PATCH 10/28] iio: light: rpr0521: " Jonathan Cameron
2021-05-12 13:46   ` Mauro Carvalho Chehab
2021-05-13 17:03     ` Jonathan Cameron
2021-05-09 11:33 ` [PATCH 11/28] iio: magn: bmc150: " Jonathan Cameron
2021-05-12 13:48   ` Mauro Carvalho Chehab
2021-05-13 17:02     ` Jonathan Cameron
2021-05-17 21:49   ` Linus Walleij
2021-05-09 11:33 ` [PATCH 12/28] iio: accel: bmi088: " Jonathan Cameron
2021-05-12 13:51   ` Mauro Carvalho Chehab
2021-05-13 17:00     ` Jonathan Cameron
2021-05-09 11:33 ` [PATCH 13/28] iio: imu: mpu6050: Use pm_runtime_resume_and_get() to replace open coding Jonathan Cameron
2021-05-12 14:11   ` Mauro Carvalho Chehab
2021-05-16 15:36     ` Jonathan Cameron
2021-05-09 11:33 ` [PATCH 14/28] iio: adc: stm32-adc: " Jonathan Cameron
2021-05-12 13:30   ` Fabrice Gasnier
2021-05-13 16:47     ` Jonathan Cameron
2021-05-12 14:17   ` Mauro Carvalho Chehab
2021-05-09 11:33 ` [PATCH 15/28] iio: adc: stm32-dfsdm: " Jonathan Cameron
2021-05-12 13:31   ` Fabrice Gasnier
2021-05-13 16:48     ` Jonathan Cameron
2021-05-12 14:19   ` Mauro Carvalho Chehab
2021-05-09 11:33 ` [PATCH 16/28] iio: dac: stm32-dac: " Jonathan Cameron
2021-05-12 13:32   ` Fabrice Gasnier
2021-05-12 14:20   ` Mauro Carvalho Chehab
2021-05-13 16:49     ` Jonathan Cameron
2021-05-09 11:33 ` [PATCH 17/28] iio: adc: ads1015: " Jonathan Cameron
2021-05-12 14:22   ` Mauro Carvalho Chehab
2021-05-16 15:41     ` Jonathan Cameron
2021-05-09 11:33 ` [PATCH 18/28] iio: chemical: atlas-sensor: " Jonathan Cameron
2021-05-10  0:36   ` Matt Ranostay
2021-05-12 14:25   ` Mauro Carvalho Chehab
2021-05-16 15:46     ` Jonathan Cameron
2021-05-09 11:33 ` [PATCH 19/28] iio: light: pa12203001: " Jonathan Cameron
2021-05-14  7:35   ` Mauro Carvalho Chehab
2021-05-14  8:21     ` Jonathan Cameron
2021-05-09 11:33 ` [PATCH 20/28] iio: light: us5182: " Jonathan Cameron
2021-05-12 14:35   ` Mauro Carvalho Chehab
2021-05-13 16:51     ` Jonathan Cameron
2021-05-09 11:33 ` [PATCH 21/28] iio: light: vcnl4000: " Jonathan Cameron
2021-05-12 14:36   ` Mauro Carvalho Chehab
2021-05-13 16:57     ` Jonathan Cameron
2021-05-09 11:33 ` [PATCH 22/28] iio: light: vcnl4035: " Jonathan Cameron
2021-05-12 14:39   ` Mauro Carvalho Chehab
2021-05-13 16:58     ` Jonathan Cameron
2021-05-09 11:33 ` [PATCH 23/28] iio: pressure: zpa2326: fix potential extra call of runtime suspend Jonathan Cameron
2021-05-12 14:49   ` Mauro Carvalho Chehab
2021-05-16 16:08     ` Jonathan Cameron
2021-05-09 11:33 ` [PATCH 24/28] iio: temp: mlx90614: Handle failure in pm_runtime_resume_and_get() Jonathan Cameron
2021-05-12 14:51   ` Mauro Carvalho Chehab
2021-05-13 16:53     ` Jonathan Cameron
2021-05-09 11:33 ` [PATCH 25/28] iio: proximity: srf04: Use pm_runtime_resume_and_get() and handle error Jonathan Cameron
2021-05-12 14:53   ` Mauro Carvalho Chehab
2021-05-13 16:55     ` Jonathan Cameron
2021-05-09 11:33 ` [PATCH 26/28] iio: prox: pulsed-light-v2: Switch pm_runtime_resume_and_get() Jonathan Cameron
2021-05-12 14:56   ` Mauro Carvalho Chehab
2021-05-16 16:08     ` Jonathan Cameron
2021-05-09 11:33 ` [PATCH 27/28] iio: pressure: icp10100: Use pm_runtime_resume_and_get() + handle errors Jonathan Cameron
2021-05-12 15:00   ` Mauro Carvalho Chehab
2021-05-16 16:17     ` Jonathan Cameron
2021-05-09 11:33 ` [PATCH 28/28] iio: adc: rcar-gyroadc: Use pm_runtime_resume_and_get() and check in probe() Jonathan Cameron
2021-05-12 15:01   ` Mauro Carvalho Chehab
2021-05-13 16:54     ` 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=20210513173557.2dfffa1b@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=Julia.Lawall@inria.fr \
    --cc=linux-iio@vger.kernel.org \
    --cc=mchehab+huawei@kernel.org \
    --cc=rjw@rjwysocki.net \
    --cc=rui.silva@linaro.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.