Linux-PM Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] power: supply: bq24190_charger: fix runtime pm imbalance
@ 2020-05-20  7:43 Dinghao Liu
  2020-05-25 10:33 ` Rafael J. Wysocki
  0 siblings, 1 reply; 3+ messages in thread
From: Dinghao Liu @ 2020-05-20  7:43 UTC (permalink / raw)
  To: dinghao.liu, kjlu; +Cc: Sebastian Reichel, linux-pm, linux-kernel

pm_runtime_get_sync() increments the runtime PM usage counter even
it returns an error code. Thus a pairing decrement is needed on
the error handling path to keep the counter balanced.

Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
---
 drivers/power/supply/bq24190_charger.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/power/supply/bq24190_charger.c b/drivers/power/supply/bq24190_charger.c
index 453d6332d43a..4f7c6b6abb56 100644
--- a/drivers/power/supply/bq24190_charger.c
+++ b/drivers/power/supply/bq24190_charger.c
@@ -481,8 +481,10 @@ static ssize_t bq24190_sysfs_store(struct device *dev,
 		return ret;
 
 	ret = pm_runtime_get_sync(bdi->dev);
-	if (ret < 0)
+	if (ret < 0) {
+		pm_runtime_put_autosuspend(bdi->dev);
 		return ret;
+	}
 
 	ret = bq24190_write_mask(bdi, info->reg, info->mask, info->shift, v);
 	if (ret)
-- 
2.17.1


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

* Re: [PATCH] power: supply: bq24190_charger: fix runtime pm imbalance
  2020-05-20  7:43 [PATCH] power: supply: bq24190_charger: fix runtime pm imbalance Dinghao Liu
@ 2020-05-25 10:33 ` Rafael J. Wysocki
  2020-05-25 10:39   ` dinghao.liu
  0 siblings, 1 reply; 3+ messages in thread
From: Rafael J. Wysocki @ 2020-05-25 10:33 UTC (permalink / raw)
  To: Dinghao Liu
  Cc: Kangjie Lu, Sebastian Reichel, Linux PM, Linux Kernel Mailing List

On Wed, May 20, 2020 at 10:01 AM Dinghao Liu <dinghao.liu@zju.edu.cn> wrote:
>
> pm_runtime_get_sync() increments the runtime PM usage counter even
> it returns an error code. Thus a pairing decrement is needed on
> the error handling path to keep the counter balanced.
>
> Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> ---
>  drivers/power/supply/bq24190_charger.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/power/supply/bq24190_charger.c b/drivers/power/supply/bq24190_charger.c
> index 453d6332d43a..4f7c6b6abb56 100644
> --- a/drivers/power/supply/bq24190_charger.c
> +++ b/drivers/power/supply/bq24190_charger.c
> @@ -481,8 +481,10 @@ static ssize_t bq24190_sysfs_store(struct device *dev,
>                 return ret;
>
>         ret = pm_runtime_get_sync(bdi->dev);
> -       if (ret < 0)
> +       if (ret < 0) {
> +               pm_runtime_put_autosuspend(bdi->dev);

The autosuspend thing is not necessary here, because the suspend is
not going to work anyway due to the resume error, so this can be
_put_noidle().

You might as well do something like

count = ret;
goto out;

here and add an "out" label before the pm_runtime_mark_last_busy() call, though.

>                 return ret;
> +       }
>
>         ret = bq24190_write_mask(bdi, info->reg, info->mask, info->shift, v);
>         if (ret)
> --
> 2.17.1
>

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

* Re: Re: [PATCH] power: supply: bq24190_charger: fix runtime pm imbalance
  2020-05-25 10:33 ` Rafael J. Wysocki
@ 2020-05-25 10:39   ` dinghao.liu
  0 siblings, 0 replies; 3+ messages in thread
From: dinghao.liu @ 2020-05-25 10:39 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Kangjie Lu, Sebastian Reichel, Linux PM, Linux Kernel Mailing List

> On Wed, May 20, 2020 at 10:01 AM Dinghao Liu <dinghao.liu@zju.edu.cn> wrote:
> >
> > pm_runtime_get_sync() increments the runtime PM usage counter even
> > it returns an error code. Thus a pairing decrement is needed on
> > the error handling path to keep the counter balanced.
> >
> > Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> > ---
> >  drivers/power/supply/bq24190_charger.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/power/supply/bq24190_charger.c b/drivers/power/supply/bq24190_charger.c
> > index 453d6332d43a..4f7c6b6abb56 100644
> > --- a/drivers/power/supply/bq24190_charger.c
> > +++ b/drivers/power/supply/bq24190_charger.c
> > @@ -481,8 +481,10 @@ static ssize_t bq24190_sysfs_store(struct device *dev,
> >                 return ret;
> >
> >         ret = pm_runtime_get_sync(bdi->dev);
> > -       if (ret < 0)
> > +       if (ret < 0) {
> > +               pm_runtime_put_autosuspend(bdi->dev);
> 
> The autosuspend thing is not necessary here, because the suspend is
> not going to work anyway due to the resume error, so this can be
> _put_noidle().
> 
> You might as well do something like
> 
> count = ret;
> goto out;
> 
> here and add an "out" label before the pm_runtime_mark_last_busy() call, though.
> 
> >                 return ret;
> > +       }
> >
> >         ret = bq24190_write_mask(bdi, info->reg, info->mask, info->shift, v);
> >         if (ret)
> > --
> > 2.17.1
> >

Thank you for your advice! I will fix this in the next version of patch.

Regards,
Dinghao

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

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-20  7:43 [PATCH] power: supply: bq24190_charger: fix runtime pm imbalance Dinghao Liu
2020-05-25 10:33 ` Rafael J. Wysocki
2020-05-25 10:39   ` dinghao.liu

Linux-PM Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-pm/0 linux-pm/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-pm linux-pm/ https://lore.kernel.org/linux-pm \
		linux-pm@vger.kernel.org
	public-inbox-index linux-pm

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-pm


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git