Skip to contentSkip to conversation

i2c: hix5hd2: Make sure clk is disabled in remove

PATCH In review Andi Shyti 3 participants 5 messages Jun 8, 2023 – Jun 23, 2023 I2C subsystem host drivers

lore
Share & tools
lore

Andi Shyti

author maintainer
#0 lore raw

PATCH v2 1/1 i2c: hix5hd2: Make sure clk is disabled in remove

From: Alexey Khoroshilov <[email protected]>

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).

---
Hi,

Look what I fished from the far December 2017 :)

It looked better to respin it rather than replying to such an old mail.

I haven't made any modification to the patch exept for a little rebase conflict. Here's a full changelog, anyway.

Changelog
=========
v1 -> v2:
- Fished this out from the muddy pond.
- Added my SoB
- Fixed rebase conflict

Andi

 drivers/i2c/busses/i2c-hix5hd2.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/i2c/busses/i2c-hix5hd2.c +9 -3
index 0e34cbaca22dc..ec775ffefa9fc 100644
@@ -421,7 +421,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;
+	}
 
 	strscpy(priv->adap.name, "hix5hd2-i2c", sizeof(priv->adap.name));
 	priv->dev = &pdev->dev;
@@ -469,8 +473,10 @@ 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);
+
 	clk_disable_unprepare(priv->clk);
 
 	return 0;
Signature · 1 line
2.40.1
author maintainer
#1 lore raw

Hi Alexey,

are you still around? Your patch looks good, just two things...

Quoted 6 lines · Andi Shyti

From: Alexey Khoroshilov <[email protected]>

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().

could you please put this in a separate patch?

Quoted 4 lines

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

if you're taking this, feel free to drop my SoB...

Quoted 11 lines

---
Hi,

Look what I fished from the far December 2017 :)

It looked better to respin it rather than replying to such an old mail.

I haven't made any modification to the patch exept for a little rebase conflict. Here's a full changelog, anyway.

Quoted 6 lines

Changelog
=========
v1 -> v2:
- Fished this out from the muddy pond.
- Added my SoB
- Fixed rebase conflict

... but please keep the changelog.

Quoted 10 lines

Andi

 drivers/i2c/busses/i2c-hix5hd2.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/i2c/busses/i2c-hix5hd2.c +0 -0
index 0e34cbaca22dc..ec775ffefa9fc 100644

drivers/i2c/busses/i2c-hix5hd2.c static int hix5hd2_i2c_probe(struct platform_device *pdev) · line 424

Quoted 5 lines
drivers/i2c/busses/i2c-hix5hd2.c +1 -1
@@ -421,7 +421,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);

please use devm_clk_get_enabled();

Thanks,
Andi

Quoted 23 lines
drivers/i2c/busses/i2c-hix5hd2.c +8 -2
+	if (ret) {
+		dev_err(&pdev->dev, "cannot enable clock\n");
+		return ret;
+	}
 
 	strscpy(priv->adap.name, "hix5hd2-i2c", sizeof(priv->adap.name));
 	priv->dev = &pdev->dev;
@@ -469,8 +473,10 @@ 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);
+
 	clk_disable_unprepare(priv->clk);
 
 	return 0;
Signature · 1 line
2.40.1
#2 lore raw

Hi Andi,

Quoted 5 lines · Andi Shyti

Hi Alexey,

are you still around? Your patch looks good, just two things...

On Fri, Jun 09, 2023 at 12:55:13AM +0200, Andi Shyti wrote:

Quoted 8 lines
Quoted 6 lines

From: Alexey Khoroshilov <[email protected]>

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().

could you please put this in a separate patch?

Sure I can do that, thank you for catching it up!

--
Alexey

Quoted 72 lines
Quoted 5 lines

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

if you're taking this, feel free to drop my SoB...

Quoted 11 lines

---
Hi,

Look what I fished from the far December 2017 :)

It looked better to respin it rather than replying to such an old mail.

I haven't made any modification to the patch exept for a little rebase conflict. Here's a full changelog, anyway.

Quoted 6 lines

Changelog
=========
v1 -> v2:
- Fished this out from the muddy pond.
- Added my SoB
- Fixed rebase conflict

... but please keep the changelog.

Quoted 10 lines

Andi

 drivers/i2c/busses/i2c-hix5hd2.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/i2c/busses/i2c-hix5hd2.c +0 -0
index 0e34cbaca22dc..ec775ffefa9fc 100644

drivers/i2c/busses/i2c-hix5hd2.c static int hix5hd2_i2c_probe(struct platform_device *pdev) · line 424

Quoted 5 lines
drivers/i2c/busses/i2c-hix5hd2.c +1 -1
@@ -421,7 +421,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);

please use devm_clk_get_enabled();

Thanks,
Andi

Quoted 23 lines
drivers/i2c/busses/i2c-hix5hd2.c +8 -2
+	if (ret) {
+		dev_err(&pdev->dev, "cannot enable clock\n");
+		return ret;
+	}
 
 	strscpy(priv->adap.name, "hix5hd2-i2c", sizeof(priv->adap.name));
 	priv->dev = &pdev->dev;
@@ -469,8 +473,10 @@ 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);
+
 	clk_disable_unprepare(priv->clk);
 
 	return 0;
Signature · 1 line
2.40.1
#3 lore raw
In reply to Andi Shyti
Quoted 11 lines · Andi Shyti

From: Alexey Khoroshilov <[email protected]>

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).

I have now applied "[PATCH 05/15] i2c: busses: hix5hd2: Use devm_clk_get_enabled()". Can this patch then be dropped entirely?

author maintainer
#4 lore raw

Hi Wolfram,

Quoted 8 lines · Wolfram Sang
Quoted 7 lines · Andi Shyti

From: Alexey Khoroshilov <[email protected]>

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().

Quoted 7 lines
Quoted 4 lines

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

I have now applied "[PATCH 05/15] i2c: busses: hix5hd2: Use devm_clk_get_enabled()". Can this patch then be dropped entirely?

yes, this patch can be dropped. When I resent this I didn't plan that refactoring.

Thanks,
Andi