[PATCH] i2c: hix5hd2: Make sure clk is disabled in remove

From: Alexey Khoroshilov
Date: Thu Dec 07 2017 - 16:28:18 EST


pm_runtime_set_suspended() does not lead to call of suspend callback,
so clk may be left undisabled in hix5hd2_i2c_remove().

By the way, the patch adds error handling for clk_prepare_enable().

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov <khoroshilov@xxxxxxxxx>
---
drivers/i2c/busses/i2c-hix5hd2.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/i2c/busses/i2c-hix5hd2.c b/drivers/i2c/busses/i2c-hix5hd2.c
index bb68957d3da5..8a921b5135ad 100644
--- a/drivers/i2c/busses/i2c-hix5hd2.c
+++ b/drivers/i2c/busses/i2c-hix5hd2.c
@@ -446,7 +446,11 @@ static int hix5hd2_i2c_probe(struct platform_device *pdev)
dev_err(&pdev->dev, "cannot get clock\n");
return PTR_ERR(priv->clk);
}
- clk_prepare_enable(priv->clk);
+ ret = clk_prepare_enable(priv->clk);
+ if (ret) {
+ dev_err(&pdev->dev, "cannot enable clock\n");
+ return ret;
+ }

strlcpy(priv->adap.name, "hix5hd2-i2c", sizeof(priv->adap.name));
priv->dev = &pdev->dev;
@@ -496,8 +500,9 @@ static int hix5hd2_i2c_remove(struct platform_device *pdev)
struct hix5hd2_i2c_priv *priv = platform_get_drvdata(pdev);

i2c_del_adapter(&priv->adap);
- pm_runtime_disable(priv->dev);
- pm_runtime_set_suspended(priv->dev);
+
+ /* Make sure priv->clk is disabled */
+ pm_runtime_force_suspend(priv->dev);

return 0;
}
--
2.7.4