linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] [v2] iio: magnetometer: ak8974: Fix runtime PM imbalance on error
@ 2020-05-26 10:47 Dinghao Liu
  2020-05-26 11:13 ` Linus Walleij
  0 siblings, 1 reply; 5+ messages in thread
From: Dinghao Liu @ 2020-05-26 10:47 UTC (permalink / raw)
  To: dinghao.liu, kjlu
  Cc: Linus Walleij, Jonathan Cameron, Hartmut Knaack,
	Lars-Peter Clausen, Peter Meerwald-Stadler, linux-iio,
	linux-kernel

When devm_regmap_init_i2c() returns an error code, a pairing
runtime PM usage counter decrement is needed to keep the
counter balanced. For error paths after ak8974_set_power(),
ak8974_detect() and ak8974_reset(), things are the same.

However, When iio_triggered_buffer_setup() returns an error
code, there will be two PM usgae counter decrements.

Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
---

Changelog:

v2: - Change 3 goto targets from "power_off" to
      "disabel_pm". Remove unused lable "power_off".
      Move 3 PM runtime related calls to the end of
      the function.
---
 drivers/iio/magnetometer/ak8974.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/drivers/iio/magnetometer/ak8974.c b/drivers/iio/magnetometer/ak8974.c
index d32996702110..c48c67d4b371 100644
--- a/drivers/iio/magnetometer/ak8974.c
+++ b/drivers/iio/magnetometer/ak8974.c
@@ -764,19 +764,21 @@ static int ak8974_probe(struct i2c_client *i2c,
 	ak8974->map = devm_regmap_init_i2c(i2c, &ak8974_regmap_config);
 	if (IS_ERR(ak8974->map)) {
 		dev_err(&i2c->dev, "failed to allocate register map\n");
+		pm_runtime_put_noidle(&i2c->dev);
+		pm_runtime_disable(&i2c->dev);
 		return PTR_ERR(ak8974->map);
 	}
 
 	ret = ak8974_set_power(ak8974, AK8974_PWR_ON);
 	if (ret) {
 		dev_err(&i2c->dev, "could not power on\n");
-		goto power_off;
+		goto disable_pm;
 	}
 
 	ret = ak8974_detect(ak8974);
 	if (ret) {
 		dev_err(&i2c->dev, "neither AK8974 nor AMI30x found\n");
-		goto power_off;
+		goto disable_pm;
 	}
 
 	ret = ak8974_selftest(ak8974);
@@ -786,14 +788,9 @@ static int ak8974_probe(struct i2c_client *i2c,
 	ret = ak8974_reset(ak8974);
 	if (ret) {
 		dev_err(&i2c->dev, "AK8974 reset failed\n");
-		goto power_off;
+		goto disable_pm;
 	}
 
-	pm_runtime_set_autosuspend_delay(&i2c->dev,
-					 AK8974_AUTOSUSPEND_DELAY);
-	pm_runtime_use_autosuspend(&i2c->dev);
-	pm_runtime_put(&i2c->dev);
-
 	indio_dev->dev.parent = &i2c->dev;
 	indio_dev->channels = ak8974_channels;
 	indio_dev->num_channels = ARRAY_SIZE(ak8974_channels);
@@ -846,6 +843,11 @@ static int ak8974_probe(struct i2c_client *i2c,
 		goto cleanup_buffer;
 	}
 
+	pm_runtime_set_autosuspend_delay(&i2c->dev,
+					 AK8974_AUTOSUSPEND_DELAY);
+	pm_runtime_use_autosuspend(&i2c->dev);
+	pm_runtime_put(&i2c->dev);
+
 	return 0;
 
 cleanup_buffer:
@@ -854,7 +856,6 @@ static int ak8974_probe(struct i2c_client *i2c,
 	pm_runtime_put_noidle(&i2c->dev);
 	pm_runtime_disable(&i2c->dev);
 	ak8974_set_power(ak8974, AK8974_PWR_OFF);
-power_off:
 	regulator_bulk_disable(ARRAY_SIZE(ak8974->regs), ak8974->regs);
 
 	return ret;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] [v2] iio: magnetometer: ak8974: Fix runtime PM imbalance on error
  2020-05-26 10:47 [PATCH] [v2] iio: magnetometer: ak8974: Fix runtime PM imbalance on error Dinghao Liu
@ 2020-05-26 11:13 ` Linus Walleij
  2020-05-31 14:00   ` Jonathan Cameron
  0 siblings, 1 reply; 5+ messages in thread
From: Linus Walleij @ 2020-05-26 11:13 UTC (permalink / raw)
  To: Dinghao Liu
  Cc: Kangjie Lu, Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, linux-iio, linux-kernel

On Tue, May 26, 2020 at 12:47 PM Dinghao Liu <dinghao.liu@zju.edu.cn> wrote:

> When devm_regmap_init_i2c() returns an error code, a pairing
> runtime PM usage counter decrement is needed to keep the
> counter balanced. For error paths after ak8974_set_power(),
> ak8974_detect() and ak8974_reset(), things are the same.
>
> However, When iio_triggered_buffer_setup() returns an error
> code, there will be two PM usgae counter decrements.
>
> Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> ---
>
> Changelog:
>
> v2: - Change 3 goto targets from "power_off" to
>       "disabel_pm". Remove unused lable "power_off".
>       Move 3 PM runtime related calls to the end of
>       the function.

Thanks for fixing this Dinghao!
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] [v2] iio: magnetometer: ak8974: Fix runtime PM imbalance on error
  2020-05-26 11:13 ` Linus Walleij
@ 2020-05-31 14:00   ` Jonathan Cameron
  2020-06-08 12:12     ` Linus Walleij
  0 siblings, 1 reply; 5+ messages in thread
From: Jonathan Cameron @ 2020-05-31 14:00 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Dinghao Liu, Kangjie Lu, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, linux-iio, linux-kernel

On Tue, 26 May 2020 13:13:56 +0200
Linus Walleij <linus.walleij@linaro.org> wrote:

> On Tue, May 26, 2020 at 12:47 PM Dinghao Liu <dinghao.liu@zju.edu.cn> wrote:
> 
> > When devm_regmap_init_i2c() returns an error code, a pairing
> > runtime PM usage counter decrement is needed to keep the
> > counter balanced. For error paths after ak8974_set_power(),
> > ak8974_detect() and ak8974_reset(), things are the same.
> >
> > However, When iio_triggered_buffer_setup() returns an error
> > code, there will be two PM usgae counter decrements.
> >
> > Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> > ---
> >
> > Changelog:
> >
> > v2: - Change 3 goto targets from "power_off" to
> >       "disabel_pm". Remove unused lable "power_off".
> >       Move 3 PM runtime related calls to the end of
> >       the function.  
> 
> Thanks for fixing this Dinghao!
> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Could I have a fixes tag for this one?

Thanks,

Jonathan

> 
> Yours,
> Linus Walleij


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] [v2] iio: magnetometer: ak8974: Fix runtime PM imbalance on error
  2020-05-31 14:00   ` Jonathan Cameron
@ 2020-06-08 12:12     ` Linus Walleij
  2020-06-14 12:11       ` Jonathan Cameron
  0 siblings, 1 reply; 5+ messages in thread
From: Linus Walleij @ 2020-06-08 12:12 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Dinghao Liu, Kangjie Lu, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, linux-iio, linux-kernel

Hi Jonathan,

sorry for missing this :(

On Sun, May 31, 2020 at 4:00 PM Jonathan Cameron <jic23@kernel.org> wrote:
> On Tue, 26 May 2020 13:13:56 +0200
> Linus Walleij <linus.walleij@linaro.org> wrote:
>
> > On Tue, May 26, 2020 at 12:47 PM Dinghao Liu <dinghao.liu@zju.edu.cn> wrote:
> >
> > > When devm_regmap_init_i2c() returns an error code, a pairing
> > > runtime PM usage counter decrement is needed to keep the
> > > counter balanced. For error paths after ak8974_set_power(),
> > > ak8974_detect() and ak8974_reset(), things are the same.
> > >
> > > However, When iio_triggered_buffer_setup() returns an error
> > > code, there will be two PM usgae counter decrements.
> > >
> > > Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> > > ---
> > >
> > > Changelog:
> > >
> > > v2: - Change 3 goto targets from "power_off" to
> > >       "disabel_pm". Remove unused lable "power_off".
> > >       Move 3 PM runtime related calls to the end of
> > >       the function.
> >
> > Thanks for fixing this Dinghao!
> > Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
>
> Could I have a fixes tag for this one?

It's been  there since the beginning so:
Fixes: 7c94a8b2ee8c ("iio: magn: add a driver for AK8974")

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] [v2] iio: magnetometer: ak8974: Fix runtime PM imbalance on error
  2020-06-08 12:12     ` Linus Walleij
@ 2020-06-14 12:11       ` Jonathan Cameron
  0 siblings, 0 replies; 5+ messages in thread
From: Jonathan Cameron @ 2020-06-14 12:11 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Dinghao Liu, Kangjie Lu, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, linux-iio, linux-kernel

On Mon, 8 Jun 2020 14:12:18 +0200
Linus Walleij <linus.walleij@linaro.org> wrote:

> Hi Jonathan,
> 
> sorry for missing this :(
> 
> On Sun, May 31, 2020 at 4:00 PM Jonathan Cameron <jic23@kernel.org> wrote:
> > On Tue, 26 May 2020 13:13:56 +0200
> > Linus Walleij <linus.walleij@linaro.org> wrote:
> >  
> > > On Tue, May 26, 2020 at 12:47 PM Dinghao Liu <dinghao.liu@zju.edu.cn> wrote:
> > >  
> > > > When devm_regmap_init_i2c() returns an error code, a pairing
> > > > runtime PM usage counter decrement is needed to keep the
> > > > counter balanced. For error paths after ak8974_set_power(),
> > > > ak8974_detect() and ak8974_reset(), things are the same.
> > > >
> > > > However, When iio_triggered_buffer_setup() returns an error
> > > > code, there will be two PM usgae counter decrements.
> > > >
> > > > Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> > > > ---
> > > >
> > > > Changelog:
> > > >
> > > > v2: - Change 3 goto targets from "power_off" to
> > > >       "disabel_pm". Remove unused lable "power_off".
> > > >       Move 3 PM runtime related calls to the end of
> > > >       the function.  
> > >
> > > Thanks for fixing this Dinghao!
> > > Reviewed-by: Linus Walleij <linus.walleij@linaro.org>  
> >
> > Could I have a fixes tag for this one?  
> 
> It's been  there since the beginning so:
> Fixes: 7c94a8b2ee8c ("iio: magn: add a driver for AK8974")
There was a lot of fuzz in this one due to other changes to the driver.
I 'think' it went it cleanly though.

Applied to the fixes-togreg branch of iio.git and marked for
stable.

Thanks,

Jonathan

> 
> Yours,
> Linus Walleij


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-06-14 12:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-26 10:47 [PATCH] [v2] iio: magnetometer: ak8974: Fix runtime PM imbalance on error Dinghao Liu
2020-05-26 11:13 ` Linus Walleij
2020-05-31 14:00   ` Jonathan Cameron
2020-06-08 12:12     ` Linus Walleij
2020-06-14 12:11       ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).