linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] [v3] i2c: imx-lpi2c: Fix runtime PM imbalance on error
@ 2020-06-01  6:16 Dinghao Liu
  2020-06-01  6:24 ` [EXT] " Andy Duan
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Dinghao Liu @ 2020-06-01  6:16 UTC (permalink / raw)
  To: dinghao.liu, kjlu
  Cc: Markus Elfring, Dong Aisheng, Shawn Guo, Sascha Hauer,
	Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team,
	Wolfram Sang, Fugang Duan, linux-i2c, linux-arm-kernel,
	linux-kernel

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

Fix this by adding the missed function call.

Fixes: 13d6eb20fc79a ("i2c: imx-lpi2c: add runtime pm support")
Co-developed-by: Markus Elfring <Markus.Elfring@web.de>
Signed-off-by: Markus Elfring <Markus.Elfring@web.de>
Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
---

Changelog:

v2: - Use pm_runtime_put_noidle() instead of
      pm_runtime_put_autosuspend().

v3: - Refine commit message.
---
 drivers/i2c/busses/i2c-imx-lpi2c.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-imx-lpi2c.c b/drivers/i2c/busses/i2c-imx-lpi2c.c
index 94743ba581fe..bdee02dff284 100644
--- a/drivers/i2c/busses/i2c-imx-lpi2c.c
+++ b/drivers/i2c/busses/i2c-imx-lpi2c.c
@@ -260,8 +260,10 @@ static int lpi2c_imx_master_enable(struct lpi2c_imx_struct *lpi2c_imx)
 	int ret;
 
 	ret = pm_runtime_get_sync(lpi2c_imx->adapter.dev.parent);
-	if (ret < 0)
+	if (ret < 0) {
+		pm_runtime_put_noidle(lpi2c_imx->adapter.dev.parent);
 		return ret;
+	}
 
 	temp = MCR_RST;
 	writel(temp, lpi2c_imx->base + LPI2C_MCR);
-- 
2.17.1


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

* RE: [EXT] [PATCH] [v3] i2c: imx-lpi2c: Fix runtime PM imbalance on error
  2020-06-01  6:16 [PATCH] [v3] i2c: imx-lpi2c: Fix runtime PM imbalance on error Dinghao Liu
@ 2020-06-01  6:24 ` Andy Duan
  2020-06-01  6:42 ` [PATCH v3] i2c: imx-lpi2c: Fix runtime PM imbalance in lpi2c_imx_master_enable() Markus Elfring
  2020-06-14  9:12 ` [PATCH] [v3] i2c: imx-lpi2c: Fix runtime PM imbalance on error Wolfram Sang
  2 siblings, 0 replies; 8+ messages in thread
From: Andy Duan @ 2020-06-01  6:24 UTC (permalink / raw)
  To: Dinghao Liu, kjlu
  Cc: Markus Elfring, Aisheng Dong, Shawn Guo, Sascha Hauer,
	Pengutronix Kernel Team, Fabio Estevam, dl-linux-imx,
	Wolfram Sang, linux-i2c, linux-arm-kernel, linux-kernel

From: Dinghao Liu <dinghao.liu@zju.edu.cn> Sent: Monday, June 1, 2020 2:17 PM
> pm_runtime_get_sync() increments the runtime PM usage counter even the
> call returns an error code. Thus a corresponding decrement is needed on the
> error handling path to keep the counter balanced.
> 
> Fix this by adding the missed function call.
> 
> Fixes: 13d6eb20fc79a ("i2c: imx-lpi2c: add runtime pm support")
> Co-developed-by: Markus Elfring <Markus.Elfring@web.de>
> Signed-off-by: Markus Elfring <Markus.Elfring@web.de>
> Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>

Reviewed-by: Fugang Duan <fugang.duan@nxp.com>
> ---
> 
> Changelog:
> 
> v2: - Use pm_runtime_put_noidle() instead of
>       pm_runtime_put_autosuspend().
> 
> v3: - Refine commit message.
> ---
>  drivers/i2c/busses/i2c-imx-lpi2c.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/i2c/busses/i2c-imx-lpi2c.c
> b/drivers/i2c/busses/i2c-imx-lpi2c.c
> index 94743ba581fe..bdee02dff284 100644
> --- a/drivers/i2c/busses/i2c-imx-lpi2c.c
> +++ b/drivers/i2c/busses/i2c-imx-lpi2c.c
> @@ -260,8 +260,10 @@ static int lpi2c_imx_master_enable(struct
> lpi2c_imx_struct *lpi2c_imx)
>         int ret;
> 
>         ret = pm_runtime_get_sync(lpi2c_imx->adapter.dev.parent);
> -       if (ret < 0)
> +       if (ret < 0) {
> +               pm_runtime_put_noidle(lpi2c_imx->adapter.dev.parent);
>                 return ret;
> +       }
> 
>         temp = MCR_RST;
>         writel(temp, lpi2c_imx->base + LPI2C_MCR);
> --
> 2.17.1


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

* Re: [PATCH v3] i2c: imx-lpi2c: Fix runtime PM imbalance in lpi2c_imx_master_enable()
  2020-06-01  6:16 [PATCH] [v3] i2c: imx-lpi2c: Fix runtime PM imbalance on error Dinghao Liu
  2020-06-01  6:24 ` [EXT] " Andy Duan
@ 2020-06-01  6:42 ` Markus Elfring
  2020-06-14  9:12 ` [PATCH] [v3] i2c: imx-lpi2c: Fix runtime PM imbalance on error Wolfram Sang
  2 siblings, 0 replies; 8+ messages in thread
From: Markus Elfring @ 2020-06-01  6:42 UTC (permalink / raw)
  To: Dinghao Liu, Fugang Duan, kernel, linux-imx, linux-i2c, linux-arm-kernel
  Cc: kernel-janitors, linux-kernel, Dong Aisheng, Fabio Estevam,
	Kangjie Lu, Sascha Hauer, Shawn Guo, Wolfram Sang

> pm_runtime_get_sync() increments the runtime PM usage counter even
> the call returns an error code. Thus a corresponding decrement is
> needed on the error handling path to keep the counter balanced.
>
> Fix this by adding the missed function call.

How do you think about a wording variant like the following?

   Change description:
   The PM runtime usage counter is incremented even if a call of
   the function “pm_runtime_get_sync” failed. Thus decrement it also
   in an error case so that the reference counting is kept consistent.


Regards,
Markus

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

* Re: [PATCH] [v3] i2c: imx-lpi2c: Fix runtime PM imbalance on error
  2020-06-01  6:16 [PATCH] [v3] i2c: imx-lpi2c: Fix runtime PM imbalance on error Dinghao Liu
  2020-06-01  6:24 ` [EXT] " Andy Duan
  2020-06-01  6:42 ` [PATCH v3] i2c: imx-lpi2c: Fix runtime PM imbalance in lpi2c_imx_master_enable() Markus Elfring
@ 2020-06-14  9:12 ` Wolfram Sang
  2020-06-14 12:08   ` dinghao.liu
  2020-06-15  6:33   ` Aisheng Dong
  2 siblings, 2 replies; 8+ messages in thread
From: Wolfram Sang @ 2020-06-14  9:12 UTC (permalink / raw)
  To: Dinghao Liu
  Cc: kjlu, Markus Elfring, Dong Aisheng, Shawn Guo, Sascha Hauer,
	Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team,
	Fugang Duan, linux-i2c, linux-arm-kernel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 450 bytes --]

On Mon, Jun 01, 2020 at 02:16:40PM +0800, Dinghao Liu wrote:
> pm_runtime_get_sync() increments the runtime PM usage counter even
> the call returns an error code. Thus a corresponding decrement is
> needed on the error handling path to keep the counter balanced.

Can you point me to a discussion where it was decided that this is a
proper fix? I'd think we rather should fix pm_runtime_get_sync() but
maybe there are technical reasons against it.


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: Re: [PATCH] [v3] i2c: imx-lpi2c: Fix runtime PM imbalance on error
  2020-06-14  9:12 ` [PATCH] [v3] i2c: imx-lpi2c: Fix runtime PM imbalance on error Wolfram Sang
@ 2020-06-14 12:08   ` dinghao.liu
  2020-06-15  6:33   ` Aisheng Dong
  1 sibling, 0 replies; 8+ messages in thread
From: dinghao.liu @ 2020-06-14 12:08 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: kjlu, Markus Elfring, Dong Aisheng, Shawn Guo, Sascha Hauer,
	Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team,
	Fugang Duan, linux-i2c, linux-arm-kernel, linux-kernel

> 
> Can you point me to a discussion where it was decided that this is a
> proper fix? I'd think we rather should fix pm_runtime_get_sync() but
> maybe there are technical reasons against it.
> 

There is a discussion here:
https://lkml.org/lkml/2020/5/20/1100

There are many use cases that suppose pm_runtime_get_sync() will always
increment the usage counter and do not check its return value. So I don't
think we should adjust this function directly.

As for this API, Dan suggested a replacement (wrapper) for later developers.
I think this is the best solution.
https://lore.kernel.org/patchwork/patch/1245375/

Regards,
Dinghao

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

* RE: [PATCH] [v3] i2c: imx-lpi2c: Fix runtime PM imbalance on error
  2020-06-14  9:12 ` [PATCH] [v3] i2c: imx-lpi2c: Fix runtime PM imbalance on error Wolfram Sang
  2020-06-14 12:08   ` dinghao.liu
@ 2020-06-15  6:33   ` Aisheng Dong
  2020-06-15  7:06     ` Wolfram Sang
  1 sibling, 1 reply; 8+ messages in thread
From: Aisheng Dong @ 2020-06-15  6:33 UTC (permalink / raw)
  To: Wolfram Sang, Dinghao Liu, linux-pm, Ulf Hansson, Rafael J . Wysocki
  Cc: kjlu, Markus Elfring, Shawn Guo, Sascha Hauer,
	Pengutronix Kernel Team, Fabio Estevam, dl-linux-imx, Andy Duan,
	linux-i2c, linux-arm-kernel, linux-kernel

> From: Wolfram Sang <wsa@kernel.org>
> Sent: Sunday, June 14, 2020 5:12 PM
> 
> On Mon, Jun 01, 2020 at 02:16:40PM +0800, Dinghao Liu wrote:
> > pm_runtime_get_sync() increments the runtime PM usage counter even the
> > call returns an error code. Thus a corresponding decrement is needed
> > on the error handling path to keep the counter balanced.
> 
> Can you point me to a discussion where it was decided that this is a proper fix?
> I'd think we rather should fix pm_runtime_get_sync() but maybe there are
> technical reasons against it.

I had the same feeling.
Copy pm guys to comments.

Regards
Aisheng

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

* Re: [PATCH] [v3] i2c: imx-lpi2c: Fix runtime PM imbalance on error
  2020-06-15  6:33   ` Aisheng Dong
@ 2020-06-15  7:06     ` Wolfram Sang
  2020-06-15  7:40       ` Markus Elfring
  0 siblings, 1 reply; 8+ messages in thread
From: Wolfram Sang @ 2020-06-15  7:06 UTC (permalink / raw)
  To: Aisheng Dong
  Cc: Dinghao Liu, linux-pm, Ulf Hansson, Rafael J . Wysocki, kjlu,
	Markus Elfring, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team,
	Fabio Estevam, dl-linux-imx, Andy Duan, linux-i2c,
	linux-arm-kernel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 851 bytes --]

On Mon, Jun 15, 2020 at 06:33:40AM +0000, Aisheng Dong wrote:
> > From: Wolfram Sang <wsa@kernel.org>
> > Sent: Sunday, June 14, 2020 5:12 PM
> > 
> > On Mon, Jun 01, 2020 at 02:16:40PM +0800, Dinghao Liu wrote:
> > > pm_runtime_get_sync() increments the runtime PM usage counter even the
> > > call returns an error code. Thus a corresponding decrement is needed
> > > on the error handling path to keep the counter balanced.
> > 
> > Can you point me to a discussion where it was decided that this is a proper fix?
> > I'd think we rather should fix pm_runtime_get_sync() but maybe there are
> > technical reasons against it.
> 
> I had the same feeling.
> Copy pm guys to comments.

I started a seperate thread:

https://lkml.org/lkml/2020/6/14/76

Still, on-going discussion if the proper fix is to remove the error
check.


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [v3] i2c: imx-lpi2c: Fix runtime PM imbalance on error
  2020-06-15  7:06     ` Wolfram Sang
@ 2020-06-15  7:40       ` Markus Elfring
  0 siblings, 0 replies; 8+ messages in thread
From: Markus Elfring @ 2020-06-15  7:40 UTC (permalink / raw)
  To: Wolfram Sang, linux-pm, kernel, linux-imx, linux-i2c, linux-arm-kernel
  Cc: Aisheng Dong, Dinghao Liu, Ulf Hansson, Rafael J . Wysocki,
	Shawn Guo, Sascha Hauer, Fabio Estevam, Andy Duan, linux-kernel,
	Qiushi Wu, Navid Emamdoost, Kangjie Lu, Aditya Pakki

> I started a seperate thread:
>
> https://lkml.org/lkml/2020/6/14/76
>
> Still, on-going discussion if the proper fix is to remove the error check.

I find that a bit of additional information can make such a link safer.

RFC: a failing pm_runtime_get increases the refcnt?
https://lore.kernel.org/lkml/20200614090751.GA2878@kunai/

How will the clarification of corresponding software aspects evolve further?

Regards,
Markus

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

end of thread, other threads:[~2020-06-15  7:41 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-01  6:16 [PATCH] [v3] i2c: imx-lpi2c: Fix runtime PM imbalance on error Dinghao Liu
2020-06-01  6:24 ` [EXT] " Andy Duan
2020-06-01  6:42 ` [PATCH v3] i2c: imx-lpi2c: Fix runtime PM imbalance in lpi2c_imx_master_enable() Markus Elfring
2020-06-14  9:12 ` [PATCH] [v3] i2c: imx-lpi2c: Fix runtime PM imbalance on error Wolfram Sang
2020-06-14 12:08   ` dinghao.liu
2020-06-15  6:33   ` Aisheng Dong
2020-06-15  7:06     ` Wolfram Sang
2020-06-15  7:40       ` Markus Elfring

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).