2020-06-13 22:16:37

by Qiushi Wu

[permalink] [raw]
Subject: [PATCH] i2c: busses: Fix a reference count leak.

From: Qiushi Wu <[email protected]>

pm_runtime_get_sync() increments the runtime PM usage counter even
when it returns an error code. Thus call pm_runtime_put_noidle()
if pm_runtime_get_sync() fails.

Fixes: 13d6eb20fc79 ("i2c: imx-lpi2c: add runtime pm support")
Signed-off-by: Qiushi Wu <[email protected]>
---
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 9db6ccded5e9..85b9c1fc7681 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


2020-06-15 02:50:58

by Andy Duan

[permalink] [raw]
Subject: RE: [EXT] [PATCH] i2c: busses: Fix a reference count leak.

From: [email protected] <[email protected]> Sent: Sunday, June 14, 2020 6:12 AM
> From: Qiushi Wu <[email protected]>
>
> pm_runtime_get_sync() increments the runtime PM usage counter even
> when it returns an error code. Thus call pm_runtime_put_noidle() if
> pm_runtime_get_sync() fails.
>
> Fixes: 13d6eb20fc79 ("i2c: imx-lpi2c: add runtime pm support")
> Signed-off-by: Qiushi Wu <[email protected]>

Again, which case can trigger the issue ?
> ---
> 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 9db6ccded5e9..85b9c1fc7681 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

2020-06-15 06:33:37

by Aisheng Dong

[permalink] [raw]
Subject: RE: [PATCH] i2c: busses: Fix a reference count leak.

> From: Andy Duan <[email protected]>
> Sent: Monday, June 15, 2020 10:49 AM
>
> From: [email protected] <[email protected]> Sent: Sunday, June 14,
> 2020 6:12 AM
> > From: Qiushi Wu <[email protected]>
> >
> > pm_runtime_get_sync() increments the runtime PM usage counter even
> > when it returns an error code. Thus call pm_runtime_put_noidle() if
> > pm_runtime_get_sync() fails.
> >
> > Fixes: 13d6eb20fc79 ("i2c: imx-lpi2c: add runtime pm support")
> > Signed-off-by: Qiushi Wu <[email protected]>
>
> Again, which case can trigger the issue ?

It's just error handling improvement because pm_runtime_get_sync() will increase the
reference count even it's failed.

I wonder if such de-reference can be better handled by pm runtime core code.
Copy pm guys to comment.

Regards
Aisheng

> > ---
> > 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 9db6ccded5e9..85b9c1fc7681 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

2020-06-15 07:09:11

by Wolfram Sang

[permalink] [raw]
Subject: Re: [PATCH] i2c: busses: Fix a reference count leak.

On Mon, Jun 15, 2020 at 06:31:28AM +0000, Aisheng Dong wrote:
> > From: Andy Duan <[email protected]>
> > Sent: Monday, June 15, 2020 10:49 AM
> >
> > From: [email protected] <[email protected]> Sent: Sunday, June 14,
> > 2020 6:12 AM
> > > From: Qiushi Wu <[email protected]>
> > >
> > > pm_runtime_get_sync() increments the runtime PM usage counter even
> > > when it returns an error code. Thus call pm_runtime_put_noidle() if
> > > pm_runtime_get_sync() fails.
> > >
> > > Fixes: 13d6eb20fc79 ("i2c: imx-lpi2c: add runtime pm support")
> > > Signed-off-by: Qiushi Wu <[email protected]>
> >
> > Again, which case can trigger the issue ?
>
> It's just error handling improvement because pm_runtime_get_sync() will increase the
> reference count even it's failed.
>
> I wonder if such de-reference can be better handled by pm runtime core code.
> Copy pm guys to comment.

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.


Attachments:
(No filename) (1.02 kB)
signature.asc (849.00 B)
Download all attachments