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

Michal Simek michal.simek at xilinx.com
Thu Apr 8 12:30:51 BST 2021



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 at 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



More information about the linux-arm-kernel mailing list