2020-12-01 22:30:59

by Qinglang Miao

[permalink] [raw]
Subject: [PATCH 0/8] i2c: fix reference leak when pm_runtime_get_sync fails

pm_runtime_get_sync will increment the PM reference count
even failed. Forgetting to putting operation will result
in a reference leak here.

Replace it with pm_runtime_resume_and_get to keep usage
counter balanced.

BTW, pm_runtime_resume_and_get is introduced in v5.10-rc5 as
dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get
to dealwith usage counter")

Qinglang Miao (8):
i2c: cadence: fix reference leak when pm_runtime_get_sync fails
i2c: img-scb: fix reference leak when pm_runtime_get_sync fails
i2c: imx-lpi2c: fix reference leak when pm_runtime_get_sync fails
i2c: imx: fix reference leak when pm_runtime_get_sync fails
i2c: omap: fix reference leak when pm_runtime_get_sync fails
i2c: sprd: fix reference leak when pm_runtime_get_sync fails
i2c: stm32f7: fix reference leak when pm_runtime_get_sync fails
i2c: xiic: fix reference leak when pm_runtime_get_sync fails

drivers/i2c/busses/i2c-cadence.c | 4 ++--
drivers/i2c/busses/i2c-img-scb.c | 4 ++--
drivers/i2c/busses/i2c-imx-lpi2c.c | 2 +-
drivers/i2c/busses/i2c-imx.c | 4 ++--
drivers/i2c/busses/i2c-omap.c | 8 ++++----
drivers/i2c/busses/i2c-sprd.c | 4 ++--
drivers/i2c/busses/i2c-stm32f7.c | 12 ++++++------
drivers/i2c/busses/i2c-xiic.c | 4 ++--
8 files changed, 21 insertions(+), 21 deletions(-)

--
2.23.0


2020-12-01 22:31:16

by Qinglang Miao

[permalink] [raw]
Subject: [PATCH 1/8] i2c: cadence: fix reference leak when pm_runtime_get_sync fails

The PM reference count is not expected to be incremented on
return in functions cdns_i2c_master_xfer and cdns_reg_slave.

However, pm_runtime_get_sync will increment pm usage counter
even failed. Forgetting to putting operation will result in a
reference leak here.

Replace it with pm_runtime_resume_and_get to keep usage
counter balanced.

Fixes: 7fa32329ca03 ("i2c: cadence: Move to sensible power management")
Reported-by: Hulk Robot <[email protected]>
Signed-off-by: Qinglang Miao <[email protected]>
---
drivers/i2c/busses/i2c-cadence.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c
index e4b7f2a95..e8eae8725 100644
--- a/drivers/i2c/busses/i2c-cadence.c
+++ b/drivers/i2c/busses/i2c-cadence.c
@@ -789,7 +789,7 @@ static int cdns_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
bool change_role = false;
#endif

- ret = pm_runtime_get_sync(id->dev);
+ ret = pm_runtime_resume_and_get(id->dev);
if (ret < 0)
return ret;

@@ -911,7 +911,7 @@ static int cdns_reg_slave(struct i2c_client *slave)
if (slave->flags & I2C_CLIENT_TEN)
return -EAFNOSUPPORT;

- ret = pm_runtime_get_sync(id->dev);
+ ret = pm_runtime_resume_and_get(id->dev);
if (ret < 0)
return ret;

--
2.23.0

2020-12-01 22:31:24

by Qinglang Miao

[permalink] [raw]
Subject: [PATCH 7/8] i2c: stm32f7: fix reference leak when pm_runtime_get_sync fails

The PM reference count is not expected to be incremented on
return in these stm32f7_i2c_xx serious functions.

However, pm_runtime_get_sync will increment the PM reference
count even failed. Forgetting to putting operation will result
in a reference leak here.

Replace it with pm_runtime_resume_and_get to keep usage
counter balanced.

Fixes: ea6dd25deeb5 ("i2c: stm32f7: add PM_SLEEP suspend/resume support")
Reported-by: Hulk Robot <[email protected]>
Signed-off-by: Qinglang Miao <[email protected]>
---
drivers/i2c/busses/i2c-stm32f7.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/i2c/busses/i2c-stm32f7.c b/drivers/i2c/busses/i2c-stm32f7.c
index f41f51a17..72fd5bdd6 100644
--- a/drivers/i2c/busses/i2c-stm32f7.c
+++ b/drivers/i2c/busses/i2c-stm32f7.c
@@ -1643,7 +1643,7 @@ static int stm32f7_i2c_xfer(struct i2c_adapter *i2c_adap,
i2c_dev->msg_id = 0;
f7_msg->smbus = false;

- ret = pm_runtime_get_sync(i2c_dev->dev);
+ ret = pm_runtime_resume_and_get(i2c_dev->dev);
if (ret < 0)
return ret;

@@ -1689,7 +1689,7 @@ static int stm32f7_i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
f7_msg->read_write = read_write;
f7_msg->smbus = true;

- ret = pm_runtime_get_sync(dev);
+ ret = pm_runtime_resume_and_get(dev);
if (ret < 0)
return ret;

@@ -1790,7 +1790,7 @@ static int stm32f7_i2c_reg_slave(struct i2c_client *slave)
if (ret)
return ret;

- ret = pm_runtime_get_sync(dev);
+ ret = pm_runtime_resume_and_get(dev);
if (ret < 0)
return ret;

@@ -1871,7 +1871,7 @@ static int stm32f7_i2c_unreg_slave(struct i2c_client *slave)

WARN_ON(!i2c_dev->slave[id]);

- ret = pm_runtime_get_sync(i2c_dev->dev);
+ ret = pm_runtime_resume_and_get(i2c_dev->dev);
if (ret < 0)
return ret;

@@ -2268,7 +2268,7 @@ static int stm32f7_i2c_regs_backup(struct stm32f7_i2c_dev *i2c_dev)
int ret;
struct stm32f7_i2c_regs *backup_regs = &i2c_dev->backup_regs;

- ret = pm_runtime_get_sync(i2c_dev->dev);
+ ret = pm_runtime_resume_and_get(i2c_dev->dev);
if (ret < 0)
return ret;

@@ -2290,7 +2290,7 @@ static int stm32f7_i2c_regs_restore(struct stm32f7_i2c_dev *i2c_dev)
int ret;
struct stm32f7_i2c_regs *backup_regs = &i2c_dev->backup_regs;

- ret = pm_runtime_get_sync(i2c_dev->dev);
+ ret = pm_runtime_resume_and_get(i2c_dev->dev);
if (ret < 0)
return ret;

--
2.23.0

2021-04-14 14:34:31

by Wolfram Sang

[permalink] [raw]
Subject: Re: [PATCH 0/8] i2c: fix reference leak when pm_runtime_get_sync fails

On Tue, Dec 01, 2020 at 05:29:24PM +0800, Qinglang Miao wrote:
> pm_runtime_get_sync will increment the PM reference count
> even failed. Forgetting to putting operation will result
> in a reference leak here.
>
> Replace it with pm_runtime_resume_and_get to keep usage
> counter balanced.
>
> BTW, pm_runtime_resume_and_get is introduced in v5.10-rc5 as
> dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get
> to dealwith usage counter")
>
> Qinglang Miao (8):
> i2c: cadence: fix reference leak when pm_runtime_get_sync fails
> i2c: img-scb: fix reference leak when pm_runtime_get_sync fails
> i2c: imx-lpi2c: fix reference leak when pm_runtime_get_sync fails
> i2c: imx: fix reference leak when pm_runtime_get_sync fails
> i2c: omap: fix reference leak when pm_runtime_get_sync fails
> i2c: sprd: fix reference leak when pm_runtime_get_sync fails
> i2c: stm32f7: fix reference leak when pm_runtime_get_sync fails
> i2c: xiic: fix reference leak when pm_runtime_get_sync fails

I applied this series now to for-next, thanks!


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