Commit 47ff6172 authored by Qinglang Miao's avatar Qinglang Miao Committed by Wolfram Sang
Browse files

i2c: imx: fix reference leak when pm_runtime_get_sync fails



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: 3a5ee18d ("i2c: imx: implement master_xfer_atomic callback")
Reported-by: default avatarHulk Robot <hulkci@huawei.com>
Signed-off-by: default avatarQinglang Miao <miaoqinglang@huawei.com>
Reviewed-by: default avatarOleksij Rempel <o.rempel@pengutronix.de>
Signed-off-by: default avatarWolfram Sang <wsa@kernel.org>
parent 278e5bbd
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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;