linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/8] i2c: fix reference leak when pm_runtime_get_sync fails
@ 2020-12-01  9:29 Qinglang Miao
  2020-12-01  9:31 ` [PATCH 1/8] i2c: cadence: " Qinglang Miao
                   ` (8 more replies)
  0 siblings, 9 replies; 13+ messages in thread
From: Qinglang Miao @ 2020-12-01  9:29 UTC (permalink / raw)
  To: Michal Simek, Dong Aisheng, Shawn Guo, Sascha Hauer,
	Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team,
	Oleksij Rempel, Vignesh R, Aaro Koskinen, Tony Lindgren,
	Orson Zhai, Baolin Wang, Chunyan Zhang, Pierre-Yves MORDRET,
	Maxime Coquelin, Alexandre Torgue
  Cc: linux-arm-kernel, linux-i2c, linux-kernel, Qinglang Miao

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


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

* [PATCH 1/8] i2c: cadence: fix reference leak when pm_runtime_get_sync fails
  2020-12-01  9:29 [PATCH 0/8] i2c: fix reference leak when pm_runtime_get_sync fails Qinglang Miao
@ 2020-12-01  9:31 ` Qinglang Miao
  2020-12-01  9:31 ` [PATCH 2/8] i2c: img-scb: " Qinglang Miao
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: Qinglang Miao @ 2020-12-01  9:31 UTC (permalink / raw)
  To: Michal Simek; +Cc: linux-arm-kernel, linux-i2c, linux-kernel, Qinglang Miao

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 <hulkci@huawei.com>
Signed-off-by: Qinglang Miao <miaoqinglang@huawei.com>
---
 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


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

* [PATCH 2/8] i2c: img-scb: fix reference leak when pm_runtime_get_sync fails
  2020-12-01  9:29 [PATCH 0/8] i2c: fix reference leak when pm_runtime_get_sync fails Qinglang Miao
  2020-12-01  9:31 ` [PATCH 1/8] i2c: cadence: " Qinglang Miao
@ 2020-12-01  9:31 ` Qinglang Miao
  2020-12-01  9:31 ` [PATCH 3/8] i2c: imx-lpi2c: " Qinglang Miao
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: Qinglang Miao @ 2020-12-01  9:31 UTC (permalink / raw)
  Cc: linux-i2c, linux-kernel, Qinglang Miao

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

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: 93222bd9b966 ("i2c: img-scb: Add runtime PM")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Qinglang Miao <miaoqinglang@huawei.com>
---
 drivers/i2c/busses/i2c-img-scb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/i2c/busses/i2c-img-scb.c b/drivers/i2c/busses/i2c-img-scb.c
index 98a89301e..8e987945e 100644
--- a/drivers/i2c/busses/i2c-img-scb.c
+++ b/drivers/i2c/busses/i2c-img-scb.c
@@ -1057,7 +1057,7 @@ static int img_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
 			atomic = true;
 	}
 
-	ret = pm_runtime_get_sync(adap->dev.parent);
+	ret = pm_runtime_resume_and_get(adap->dev.parent);
 	if (ret < 0)
 		return ret;
 
@@ -1158,7 +1158,7 @@ static int img_i2c_init(struct img_i2c *i2c)
 	u32 rev;
 	int ret;
 
-	ret = pm_runtime_get_sync(i2c->adap.dev.parent);
+	ret = pm_runtime_resume_and_get(i2c->adap.dev.parent);
 	if (ret < 0)
 		return ret;
 
-- 
2.23.0


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

* [PATCH 3/8] i2c: imx-lpi2c: fix reference leak when pm_runtime_get_sync fails
  2020-12-01  9:29 [PATCH 0/8] i2c: fix reference leak when pm_runtime_get_sync fails Qinglang Miao
  2020-12-01  9:31 ` [PATCH 1/8] i2c: cadence: " Qinglang Miao
  2020-12-01  9:31 ` [PATCH 2/8] i2c: img-scb: " Qinglang Miao
@ 2020-12-01  9:31 ` Qinglang Miao
  2020-12-01  9:31 ` [PATCH 4/8] i2c: imx: " Qinglang Miao
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: Qinglang Miao @ 2020-12-01  9:31 UTC (permalink / raw)
  To: Dong Aisheng, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team,
	Fabio Estevam, NXP Linux Team
  Cc: linux-i2c, linux-arm-kernel, linux-kernel, Qinglang Miao

The PM reference count is not expected to be incremented on
return in lpi2c_imx_master_enable.

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: 13d6eb20fc79 ("i2c: imx-lpi2c: add runtime pm support")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Qinglang Miao <miaoqinglang@huawei.com>
---
 drivers/i2c/busses/i2c-imx-lpi2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-imx-lpi2c.c b/drivers/i2c/busses/i2c-imx-lpi2c.c
index 9db6ccded..8b9ba055c 100644
--- a/drivers/i2c/busses/i2c-imx-lpi2c.c
+++ b/drivers/i2c/busses/i2c-imx-lpi2c.c
@@ -259,7 +259,7 @@ static int lpi2c_imx_master_enable(struct lpi2c_imx_struct *lpi2c_imx)
 	unsigned int temp;
 	int ret;
 
-	ret = pm_runtime_get_sync(lpi2c_imx->adapter.dev.parent);
+	ret = pm_runtime_resume_and_get(lpi2c_imx->adapter.dev.parent);
 	if (ret < 0)
 		return ret;
 
-- 
2.23.0


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

* [PATCH 4/8] i2c: imx: fix reference leak when pm_runtime_get_sync fails
  2020-12-01  9:29 [PATCH 0/8] i2c: fix reference leak when pm_runtime_get_sync fails Qinglang Miao
                   ` (2 preceding siblings ...)
  2020-12-01  9:31 ` [PATCH 3/8] i2c: imx-lpi2c: " Qinglang Miao
@ 2020-12-01  9:31 ` Qinglang Miao
  2020-12-11 11:18   ` Oleksij Rempel
  2020-12-01  9:31 ` [PATCH 5/8] i2c: omap: " Qinglang Miao
                   ` (4 subsequent siblings)
  8 siblings, 1 reply; 13+ messages in thread
From: Qinglang Miao @ 2020-12-01  9:31 UTC (permalink / raw)
  To: Oleksij Rempel, Pengutronix Kernel Team, Shawn Guo, Sascha Hauer,
	Fabio Estevam, NXP Linux Team
  Cc: linux-i2c, linux-arm-kernel, linux-kernel, Qinglang Miao

In i2c_imx_xfer() and i2c_imx_remove(), the pm reference count
is not expected to be incremented on return.

However, pm_runtime_get_sync will increment 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: 3a5ee18d2a32 ("i2c: imx: implement master_xfer_atomic callback")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Qinglang Miao <miaoqinglang@huawei.com>
---
 drivers/i2c/busses/i2c-imx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index c98529c76..93d2069da 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -1008,7 +1008,7 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
 	struct imx_i2c_struct *i2c_imx = i2c_get_adapdata(adapter);
 	int result;
 
-	result = pm_runtime_get_sync(i2c_imx->adapter.dev.parent);
+	result = pm_runtime_resume_and_get(i2c_imx->adapter.dev.parent);
 	if (result < 0)
 		return result;
 
@@ -1252,7 +1252,7 @@ static int i2c_imx_remove(struct platform_device *pdev)
 	struct imx_i2c_struct *i2c_imx = platform_get_drvdata(pdev);
 	int irq, ret;
 
-	ret = pm_runtime_get_sync(&pdev->dev);
+	ret = pm_runtime_resume_and_get(&pdev->dev);
 	if (ret < 0)
 		return ret;
 
-- 
2.23.0


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

* [PATCH 5/8] i2c: omap: fix reference leak when pm_runtime_get_sync fails
  2020-12-01  9:29 [PATCH 0/8] i2c: fix reference leak when pm_runtime_get_sync fails Qinglang Miao
                   ` (3 preceding siblings ...)
  2020-12-01  9:31 ` [PATCH 4/8] i2c: imx: " Qinglang Miao
@ 2020-12-01  9:31 ` Qinglang Miao
  2020-12-01 16:53   ` Grygorii Strashko
  2020-12-02  5:13   ` Vignesh Raghavendra
  2020-12-01  9:31 ` [PATCH 6/8] i2c: sprd: " Qinglang Miao
                   ` (3 subsequent siblings)
  8 siblings, 2 replies; 13+ messages in thread
From: Qinglang Miao @ 2020-12-01  9:31 UTC (permalink / raw)
  To: Vignesh R, Aaro Koskinen, Tony Lindgren
  Cc: linux-omap, linux-i2c, linux-kernel, Qinglang Miao

The PM reference count is not expected to be incremented on
return in omap_i2c_probe() and omap_i2c_remove().

However, pm_runtime_get_sync will increment the PM reference
count even failed. Forgetting to putting operation will result
in a reference leak here. I Replace it with pm_runtime_resume_and_get
to keep usage counter balanced.

What's more, error path 'err_free_mem' seems not like a proper
name any more. So I change the name to err_disable_pm and move
pm_runtime_disable below, for pm_runtime of 'pdev->dev' should
be disabled when pm_runtime_resume_and_get fails.

Fixes: 3b0fb97c8dc4 ("I2C: OMAP: Handle error check for pm runtime")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Qinglang Miao <miaoqinglang@huawei.com>
---
 drivers/i2c/busses/i2c-omap.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index 12ac4212a..d4f6c6d60 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -1404,9 +1404,9 @@ omap_i2c_probe(struct platform_device *pdev)
 	pm_runtime_set_autosuspend_delay(omap->dev, OMAP_I2C_PM_TIMEOUT);
 	pm_runtime_use_autosuspend(omap->dev);
 
-	r = pm_runtime_get_sync(omap->dev);
+	r = pm_runtime_resume_and_get(omap->dev);
 	if (r < 0)
-		goto err_free_mem;
+		goto err_disable_pm;
 
 	/*
 	 * Read the Rev hi bit-[15:14] ie scheme this is 1 indicates ver2.
@@ -1513,8 +1513,8 @@ omap_i2c_probe(struct platform_device *pdev)
 	omap_i2c_write_reg(omap, OMAP_I2C_CON_REG, 0);
 	pm_runtime_dont_use_autosuspend(omap->dev);
 	pm_runtime_put_sync(omap->dev);
+err_disable_pm:
 	pm_runtime_disable(&pdev->dev);
-err_free_mem:
 
 	return r;
 }
@@ -1525,7 +1525,7 @@ static int omap_i2c_remove(struct platform_device *pdev)
 	int ret;
 
 	i2c_del_adapter(&omap->adapter);
-	ret = pm_runtime_get_sync(&pdev->dev);
+	ret = pm_runtime_resume_and_get(&pdev->dev);
 	if (ret < 0)
 		return ret;
 
-- 
2.23.0


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

* [PATCH 6/8] i2c: sprd: fix reference leak when pm_runtime_get_sync fails
  2020-12-01  9:29 [PATCH 0/8] i2c: fix reference leak when pm_runtime_get_sync fails Qinglang Miao
                   ` (4 preceding siblings ...)
  2020-12-01  9:31 ` [PATCH 5/8] i2c: omap: " Qinglang Miao
@ 2020-12-01  9:31 ` Qinglang Miao
  2020-12-01  9:31 ` [PATCH 7/8] i2c: stm32f7: " Qinglang Miao
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: Qinglang Miao @ 2020-12-01  9:31 UTC (permalink / raw)
  To: Orson Zhai, Baolin Wang, Chunyan Zhang
  Cc: linux-i2c, linux-kernel, Qinglang Miao

The PM reference count is not expected to be incremented on
return in sprd_i2c_master_xfer() and sprd_i2c_remove().

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: 8b9ec0719834 ("i2c: Add Spreadtrum I2C controller driver")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Qinglang Miao <miaoqinglang@huawei.com>
---
 drivers/i2c/busses/i2c-sprd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/i2c/busses/i2c-sprd.c b/drivers/i2c/busses/i2c-sprd.c
index 19cda6742..103b1a852 100644
--- a/drivers/i2c/busses/i2c-sprd.c
+++ b/drivers/i2c/busses/i2c-sprd.c
@@ -284,7 +284,7 @@ static int sprd_i2c_master_xfer(struct i2c_adapter *i2c_adap,
 	struct sprd_i2c *i2c_dev = i2c_adap->algo_data;
 	int im, ret;
 
-	ret = pm_runtime_get_sync(i2c_dev->dev);
+	ret = pm_runtime_resume_and_get(i2c_dev->dev);
 	if (ret < 0)
 		return ret;
 
@@ -570,7 +570,7 @@ static int sprd_i2c_remove(struct platform_device *pdev)
 	struct sprd_i2c *i2c_dev = platform_get_drvdata(pdev);
 	int ret;
 
-	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


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

* [PATCH 7/8] i2c: stm32f7: fix reference leak when pm_runtime_get_sync fails
  2020-12-01  9:29 [PATCH 0/8] i2c: fix reference leak when pm_runtime_get_sync fails Qinglang Miao
                   ` (5 preceding siblings ...)
  2020-12-01  9:31 ` [PATCH 6/8] i2c: sprd: " Qinglang Miao
@ 2020-12-01  9:31 ` Qinglang Miao
  2020-12-01  9:31 ` [PATCH 8/8] i2c: xiic: " Qinglang Miao
  2021-04-14  7:51 ` [PATCH 0/8] i2c: " Wolfram Sang
  8 siblings, 0 replies; 13+ messages in thread
From: Qinglang Miao @ 2020-12-01  9:31 UTC (permalink / raw)
  To: Pierre-Yves MORDRET, Maxime Coquelin, Alexandre Torgue
  Cc: linux-i2c, linux-stm32, linux-arm-kernel, linux-kernel, Qinglang Miao

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 <hulkci@huawei.com>
Signed-off-by: Qinglang Miao <miaoqinglang@huawei.com>
---
 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


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

* [PATCH 8/8] i2c: xiic: fix reference leak when pm_runtime_get_sync fails
  2020-12-01  9:29 [PATCH 0/8] i2c: fix reference leak when pm_runtime_get_sync fails Qinglang Miao
                   ` (6 preceding siblings ...)
  2020-12-01  9:31 ` [PATCH 7/8] i2c: stm32f7: " Qinglang Miao
@ 2020-12-01  9:31 ` Qinglang Miao
  2021-04-14  7:51 ` [PATCH 0/8] i2c: " Wolfram Sang
  8 siblings, 0 replies; 13+ messages in thread
From: Qinglang Miao @ 2020-12-01  9:31 UTC (permalink / raw)
  To: Michal Simek; +Cc: linux-arm-kernel, linux-i2c, linux-kernel, Qinglang Miao

The PM reference count is not expected to be incremented on
return in xiic_xfer and xiic_i2c_remove.

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: 10b17004a74c ("i2c: xiic: Fix the clocking across bind unbind")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Qinglang Miao <miaoqinglang@huawei.com>
---
 drivers/i2c/busses/i2c-xiic.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/i2c/busses/i2c-xiic.c b/drivers/i2c/busses/i2c-xiic.c
index 087b29519..2a8568b97 100644
--- a/drivers/i2c/busses/i2c-xiic.c
+++ b/drivers/i2c/busses/i2c-xiic.c
@@ -706,7 +706,7 @@ static int xiic_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
 	dev_dbg(adap->dev.parent, "%s entry SR: 0x%x\n", __func__,
 		xiic_getreg8(i2c, XIIC_SR_REG_OFFSET));
 
-	err = pm_runtime_get_sync(i2c->dev);
+	err = pm_runtime_resume_and_get(i2c->dev);
 	if (err < 0)
 		return err;
 
@@ -873,7 +873,7 @@ static int xiic_i2c_remove(struct platform_device *pdev)
 	/* remove adapter & data */
 	i2c_del_adapter(&i2c->adap);
 
-	ret = pm_runtime_get_sync(i2c->dev);
+	ret = pm_runtime_resume_and_get(i2c->dev);
 	if (ret < 0)
 		return ret;
 
-- 
2.23.0


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

* Re: [PATCH 5/8] i2c: omap: fix reference leak when pm_runtime_get_sync fails
  2020-12-01  9:31 ` [PATCH 5/8] i2c: omap: " Qinglang Miao
@ 2020-12-01 16:53   ` Grygorii Strashko
  2020-12-02  5:13   ` Vignesh Raghavendra
  1 sibling, 0 replies; 13+ messages in thread
From: Grygorii Strashko @ 2020-12-01 16:53 UTC (permalink / raw)
  To: Qinglang Miao, Vignesh R, Aaro Koskinen, Tony Lindgren
  Cc: linux-omap, linux-i2c, linux-kernel



On 01/12/2020 11:31, Qinglang Miao wrote:
> The PM reference count is not expected to be incremented on
> return in omap_i2c_probe() and omap_i2c_remove().
> 
> However, pm_runtime_get_sync will increment the PM reference
> count even failed. Forgetting to putting operation will result
> in a reference leak here. I Replace it with pm_runtime_resume_and_get
> to keep usage counter balanced.
> 
> What's more, error path 'err_free_mem' seems not like a proper
> name any more. So I change the name to err_disable_pm and move
> pm_runtime_disable below, for pm_runtime of 'pdev->dev' should
> be disabled when pm_runtime_resume_and_get fails.
> 
> Fixes: 3b0fb97c8dc4 ("I2C: OMAP: Handle error check for pm runtime")
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Qinglang Miao <miaoqinglang@huawei.com>
> ---
>   drivers/i2c/busses/i2c-omap.c | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
> index 12ac4212a..d4f6c6d60 100644
> --- a/drivers/i2c/busses/i2c-omap.c
> +++ b/drivers/i2c/busses/i2c-omap.c
> @@ -1404,9 +1404,9 @@ omap_i2c_probe(struct platform_device *pdev)
>   	pm_runtime_set_autosuspend_delay(omap->dev, OMAP_I2C_PM_TIMEOUT);
>   	pm_runtime_use_autosuspend(omap->dev);
>   
> -	r = pm_runtime_get_sync(omap->dev);
> +	r = pm_runtime_resume_and_get(omap->dev);
>   	if (r < 0)
> -		goto err_free_mem;
> +		goto err_disable_pm;
>   
>   	/*
>   	 * Read the Rev hi bit-[15:14] ie scheme this is 1 indicates ver2.
> @@ -1513,8 +1513,8 @@ omap_i2c_probe(struct platform_device *pdev)
>   	omap_i2c_write_reg(omap, OMAP_I2C_CON_REG, 0);
>   	pm_runtime_dont_use_autosuspend(omap->dev);
>   	pm_runtime_put_sync(omap->dev);
> +err_disable_pm:
>   	pm_runtime_disable(&pdev->dev);
> -err_free_mem:
>   
>   	return r;
>   }
> @@ -1525,7 +1525,7 @@ static int omap_i2c_remove(struct platform_device *pdev)
>   	int ret;
>   
>   	i2c_del_adapter(&omap->adapter);
> -	ret = pm_runtime_get_sync(&pdev->dev);
> +	ret = pm_runtime_resume_and_get(&pdev->dev);
>   	if (ret < 0)
>   		return ret;
>   
> 

Reviewed-by: Grygorii Strashko <grygorii.strashko@ti.com>

-- 
Best regards,
grygorii

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

* Re: [PATCH 5/8] i2c: omap: fix reference leak when pm_runtime_get_sync fails
  2020-12-01  9:31 ` [PATCH 5/8] i2c: omap: " Qinglang Miao
  2020-12-01 16:53   ` Grygorii Strashko
@ 2020-12-02  5:13   ` Vignesh Raghavendra
  1 sibling, 0 replies; 13+ messages in thread
From: Vignesh Raghavendra @ 2020-12-02  5:13 UTC (permalink / raw)
  To: Qinglang Miao, Aaro Koskinen, Tony Lindgren
  Cc: linux-omap, linux-i2c, linux-kernel



On 12/1/20 3:01 PM, Qinglang Miao wrote:
> The PM reference count is not expected to be incremented on
> return in omap_i2c_probe() and omap_i2c_remove().
> 
> However, pm_runtime_get_sync will increment the PM reference
> count even failed. Forgetting to putting operation will result
> in a reference leak here. I Replace it with pm_runtime_resume_and_get
> to keep usage counter balanced.
> 
> What's more, error path 'err_free_mem' seems not like a proper
> name any more. So I change the name to err_disable_pm and move
> pm_runtime_disable below, for pm_runtime of 'pdev->dev' should
> be disabled when pm_runtime_resume_and_get fails.
> 
> Fixes: 3b0fb97c8dc4 ("I2C: OMAP: Handle error check for pm runtime")
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Qinglang Miao <miaoqinglang@huawei.com>
> ---

Reviewed-by: Vignesh Raghavendra <vigneshr@ti.com>

>  drivers/i2c/busses/i2c-omap.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
> index 12ac4212a..d4f6c6d60 100644
> --- a/drivers/i2c/busses/i2c-omap.c
> +++ b/drivers/i2c/busses/i2c-omap.c
> @@ -1404,9 +1404,9 @@ omap_i2c_probe(struct platform_device *pdev)
>  	pm_runtime_set_autosuspend_delay(omap->dev, OMAP_I2C_PM_TIMEOUT);
>  	pm_runtime_use_autosuspend(omap->dev);
>  
> -	r = pm_runtime_get_sync(omap->dev);
> +	r = pm_runtime_resume_and_get(omap->dev);
>  	if (r < 0)
> -		goto err_free_mem;
> +		goto err_disable_pm;
>  
>  	/*
>  	 * Read the Rev hi bit-[15:14] ie scheme this is 1 indicates ver2.
> @@ -1513,8 +1513,8 @@ omap_i2c_probe(struct platform_device *pdev)
>  	omap_i2c_write_reg(omap, OMAP_I2C_CON_REG, 0);
>  	pm_runtime_dont_use_autosuspend(omap->dev);
>  	pm_runtime_put_sync(omap->dev);
> +err_disable_pm:
>  	pm_runtime_disable(&pdev->dev);
> -err_free_mem:
>  
>  	return r;
>  }
> @@ -1525,7 +1525,7 @@ static int omap_i2c_remove(struct platform_device *pdev)
>  	int ret;
>  
>  	i2c_del_adapter(&omap->adapter);
> -	ret = pm_runtime_get_sync(&pdev->dev);
> +	ret = pm_runtime_resume_and_get(&pdev->dev);
>  	if (ret < 0)
>  		return ret;
>  
> 

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

* Re: [PATCH 4/8] i2c: imx: fix reference leak when pm_runtime_get_sync fails
  2020-12-01  9:31 ` [PATCH 4/8] i2c: imx: " Qinglang Miao
@ 2020-12-11 11:18   ` Oleksij Rempel
  0 siblings, 0 replies; 13+ messages in thread
From: Oleksij Rempel @ 2020-12-11 11:18 UTC (permalink / raw)
  To: Qinglang Miao
  Cc: Oleksij Rempel, Pengutronix Kernel Team, Shawn Guo, Sascha Hauer,
	Fabio Estevam, NXP Linux Team, linux-i2c, linux-arm-kernel,
	linux-kernel

On Tue, Dec 01, 2020 at 05:31:41PM +0800, Qinglang Miao wrote:
> In i2c_imx_xfer() and i2c_imx_remove(), the pm reference count
> is not expected to be incremented on return.
> 
> However, pm_runtime_get_sync will increment 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: 3a5ee18d2a32 ("i2c: imx: implement master_xfer_atomic callback")
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Qinglang Miao <miaoqinglang@huawei.com>

Thank you!

Reviewed-by: Oleksij Rempel <o.rempel@pengutronix.de>

> ---
>  drivers/i2c/busses/i2c-imx.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
> index c98529c76..93d2069da 100644
> --- a/drivers/i2c/busses/i2c-imx.c
> +++ b/drivers/i2c/busses/i2c-imx.c
> @@ -1008,7 +1008,7 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
>  	struct imx_i2c_struct *i2c_imx = i2c_get_adapdata(adapter);
>  	int result;
>  
> -	result = pm_runtime_get_sync(i2c_imx->adapter.dev.parent);
> +	result = pm_runtime_resume_and_get(i2c_imx->adapter.dev.parent);
>  	if (result < 0)
>  		return result;
>  
> @@ -1252,7 +1252,7 @@ static int i2c_imx_remove(struct platform_device *pdev)
>  	struct imx_i2c_struct *i2c_imx = platform_get_drvdata(pdev);
>  	int irq, ret;
>  
> -	ret = pm_runtime_get_sync(&pdev->dev);
> +	ret = pm_runtime_resume_and_get(&pdev->dev);
>  	if (ret < 0)
>  		return ret;
>  
> -- 
> 2.23.0
> 
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

* Re: [PATCH 0/8] i2c: fix reference leak when pm_runtime_get_sync fails
  2020-12-01  9:29 [PATCH 0/8] i2c: fix reference leak when pm_runtime_get_sync fails Qinglang Miao
                   ` (7 preceding siblings ...)
  2020-12-01  9:31 ` [PATCH 8/8] i2c: xiic: " Qinglang Miao
@ 2021-04-14  7:51 ` Wolfram Sang
  8 siblings, 0 replies; 13+ messages in thread
From: Wolfram Sang @ 2021-04-14  7:51 UTC (permalink / raw)
  To: Qinglang Miao
  Cc: Michal Simek, Dong Aisheng, Shawn Guo, Sascha Hauer,
	Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team,
	Oleksij Rempel, Vignesh R, Aaro Koskinen, Tony Lindgren,
	Orson Zhai, Baolin Wang, Chunyan Zhang, Pierre-Yves MORDRET,
	Maxime Coquelin, Alexandre Torgue, linux-arm-kernel, linux-i2c,
	linux-kernel

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

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!


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

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

end of thread, other threads:[~2021-04-14  7:51 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-01  9:29 [PATCH 0/8] i2c: fix reference leak when pm_runtime_get_sync fails Qinglang Miao
2020-12-01  9:31 ` [PATCH 1/8] i2c: cadence: " Qinglang Miao
2020-12-01  9:31 ` [PATCH 2/8] i2c: img-scb: " Qinglang Miao
2020-12-01  9:31 ` [PATCH 3/8] i2c: imx-lpi2c: " Qinglang Miao
2020-12-01  9:31 ` [PATCH 4/8] i2c: imx: " Qinglang Miao
2020-12-11 11:18   ` Oleksij Rempel
2020-12-01  9:31 ` [PATCH 5/8] i2c: omap: " Qinglang Miao
2020-12-01 16:53   ` Grygorii Strashko
2020-12-02  5:13   ` Vignesh Raghavendra
2020-12-01  9:31 ` [PATCH 6/8] i2c: sprd: " Qinglang Miao
2020-12-01  9:31 ` [PATCH 7/8] i2c: stm32f7: " Qinglang Miao
2020-12-01  9:31 ` [PATCH 8/8] i2c: xiic: " Qinglang Miao
2021-04-14  7:51 ` [PATCH 0/8] i2c: " Wolfram Sang

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