Linux-i2c Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH -next] i2c: imx: Fix PM reference leak in i2c_imx_reg_slave()
@ 2021-04-08 11:06 Ye Weihua
  2021-04-14  8:04 ` Wolfram Sang
  0 siblings, 1 reply; 2+ messages in thread
From: Ye Weihua @ 2021-04-08 11:06 UTC (permalink / raw)
  To: linux, kernel, shawnguo, s.hauer, festevam, linux-imx
  Cc: linux-i2c, linux-arm-kernel, linux-kernel, yangjihong1, zhangjinhao2

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

However, pm_runtime_get_sync() will increment the PM reference count
even on failure. forgetting to put the reference again will result in
a leak.

Replace it with pm_runtime_resume_and_get() to keep the usage counter
balanced.

Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Ye Weihua <yeweihua4@huawei.com>
---
 drivers/i2c/busses/i2c-imx.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index b80fdc1f0092..dc5ca71906db 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -801,7 +801,7 @@ static int i2c_imx_reg_slave(struct i2c_client *client)
 	i2c_imx->last_slave_event = I2C_SLAVE_STOP;
 
 	/* Resume */
-	ret = pm_runtime_get_sync(i2c_imx->adapter.dev.parent);
+	ret = pm_runtime_resume_and_get(i2c_imx->adapter.dev.parent);
 	if (ret < 0) {
 		dev_err(&i2c_imx->adapter.dev, "failed to resume i2c controller");
 		return ret;
@@ -1253,7 +1253,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;
 
@@ -1496,7 +1496,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.17.1


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

* Re: [PATCH -next] i2c: imx: Fix PM reference leak in i2c_imx_reg_slave()
  2021-04-08 11:06 [PATCH -next] i2c: imx: Fix PM reference leak in i2c_imx_reg_slave() Ye Weihua
@ 2021-04-14  8:04 ` Wolfram Sang
  0 siblings, 0 replies; 2+ messages in thread
From: Wolfram Sang @ 2021-04-14  8:04 UTC (permalink / raw)
  To: Ye Weihua
  Cc: linux, kernel, shawnguo, s.hauer, festevam, linux-imx, linux-i2c,
	linux-arm-kernel, linux-kernel, yangjihong1, zhangjinhao2


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

On Thu, Apr 08, 2021 at 07:06:38PM +0800, Ye Weihua wrote:
> The PM reference count is not expected to be incremented on return in
> these functions.
> 
> However, pm_runtime_get_sync() will increment the PM reference count
> even on failure. forgetting to put the reference again will result in
> a leak.
> 
> Replace it with pm_runtime_resume_and_get() to keep the usage counter
> balanced.
> 
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Ye Weihua <yeweihua4@huawei.com>

After rebasing, only one hunk was left:

> @@ -801,7 +801,7 @@ static int i2c_imx_reg_slave(struct i2c_client *client)
>  	i2c_imx->last_slave_event = I2C_SLAVE_STOP;
>  
>  	/* Resume */
> -	ret = pm_runtime_get_sync(i2c_imx->adapter.dev.parent);
> +	ret = pm_runtime_resume_and_get(i2c_imx->adapter.dev.parent);
>  	if (ret < 0) {
>  		dev_err(&i2c_imx->adapter.dev, "failed to resume i2c controller");
>  		return ret;

I applied this to for-next, thanks!


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

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

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-08 11:06 [PATCH -next] i2c: imx: Fix PM reference leak in i2c_imx_reg_slave() Ye Weihua
2021-04-14  8:04 ` Wolfram Sang

Linux-i2c Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-i2c/0 linux-i2c/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-i2c linux-i2c/ https://lore.kernel.org/linux-i2c \
		linux-i2c@vger.kernel.org
	public-inbox-index linux-i2c

Example config snippet for mirrors

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


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