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

From: Michal Simek
Date: Thu Apr 08 2021 - 07:31:02 EST




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@xxxxxxxxxx>
> ---
> 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