diff mbox series

[-next] i2c: cadence: Fix PM reference leak in cdns_i2c_master_xfer()

Message ID 20210408112352.211173-1-pulehui@huawei.com
State New
Headers show
Series [-next] i2c: cadence: Fix PM reference leak in cdns_i2c_master_xfer() | expand

Commit Message

Pu Lehui April 8, 2021, 11:23 a.m. UTC
pm_runtime_get_sync() will increment pm usage counter even it failed.
Forgetting to putting operation will result in reference leak here.
Fix it by replacing it with pm_runtime_resume_and_get() to keep usage
counter balanced.

Signed-off-by: Pu Lehui <pulehui@huawei.com>
---
 drivers/i2c/busses/i2c-cadence.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Michal Simek April 8, 2021, 11:30 a.m. UTC | #1
On 4/8/21 1:23 PM, Pu Lehui wrote:
> pm_runtime_get_sync() will increment pm usage counter even it failed.
> Forgetting to putting operation will result in reference leak here.
> Fix it by replacing it with pm_runtime_resume_and_get() to keep usage
> counter balanced.
> 
> Signed-off-by: Pu Lehui <pulehui@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 e4b7f2a951ad..e8eae8725900 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;
>  
> 

Ravi/Shubhrajyoti: Please take a look at this.

Thanks,
Michal
Wolfram Sang April 14, 2021, 7:57 a.m. UTC | #2
On Thu, Apr 08, 2021 at 07:23:52PM +0800, Pu Lehui wrote:
> pm_runtime_get_sync() will increment pm usage counter even it failed.

> Forgetting to putting operation will result in reference leak here.

> Fix it by replacing it with pm_runtime_resume_and_get() to keep usage

> counter balanced.

> 

> Signed-off-by: Pu Lehui <pulehui@huawei.com>


Thanks, yet I applied this series now:

http://patchwork.ozlabs.org/project/linux-i2c/list/?series=217733&state=*
diff mbox series

Patch

diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c
index e4b7f2a951ad..e8eae8725900 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;