LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH v2] i2c: axxia: enable clock before calling clk_get_rate()
@ 2018-04-30 14:49 Tobias Jordan
  2018-05-08 21:15 ` Wolfram Sang
  0 siblings, 1 reply; 2+ messages in thread
From: Tobias Jordan @ 2018-04-30 14:49 UTC (permalink / raw)
  To: wsa; +Cc: linux-i2c, linux-kernel

axxia_i2c_init() uses clk_get_rate() for idev->i2c_clk. clk_get_rate()
should only be called if the clock is enabled, so ensure that by moving
the clk_prepare_enable() call before the call to axxia_i2c_init().

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

Fixes: 08678b850cd0 ("i2c: axxia: Add I2C driver for AXM55xx")
Signed-off-by: Tobias Jordan <Tobias.Jordan@elektrobit.com>
---
v2:
first version of the patch ignored that the clock should be disabled in
case we bail out later...
compile-tested and coccichecked.

 drivers/i2c/busses/i2c-axxia.c | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/drivers/i2c/busses/i2c-axxia.c b/drivers/i2c/busses/i2c-axxia.c
index 13f07482ec68..12f92369888b 100644
--- a/drivers/i2c/busses/i2c-axxia.c
+++ b/drivers/i2c/busses/i2c-axxia.c
@@ -532,23 +532,23 @@ static int axxia_i2c_probe(struct platform_device *pdev)
 	if (idev->bus_clk_rate == 0)
 		idev->bus_clk_rate = 100000;	/* default clock rate */
 
+	ret = clk_prepare_enable(idev->i2c_clk);
+	if (ret) {
+		dev_err(&pdev->dev, "failed to enable clock\n");
+		return ret;
+	}
+
 	ret = axxia_i2c_init(idev);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to initialize\n");
-		return ret;
+		goto error_disable_clk;
 	}
 
 	ret = devm_request_irq(&pdev->dev, irq, axxia_i2c_isr, 0,
 			       pdev->name, idev);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to claim IRQ%d\n", irq);
-		return ret;
-	}
-
-	ret = clk_prepare_enable(idev->i2c_clk);
-	if (ret) {
-		dev_err(&pdev->dev, "failed to enable clock\n");
-		return ret;
+		goto error_disable_clk;
 	}
 
 	i2c_set_adapdata(&idev->adapter, idev);
@@ -563,12 +563,14 @@ static int axxia_i2c_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, idev);
 
 	ret = i2c_add_adapter(&idev->adapter);
-	if (ret) {
-		clk_disable_unprepare(idev->i2c_clk);
-		return ret;
-	}
+	if (ret)
+		goto error_disable_clk;
 
 	return 0;
+
+error_disable_clk:
+	clk_disable_unprepare(idev->i2c_clk);
+	return ret;
 }
 
 static int axxia_i2c_remove(struct platform_device *pdev)
-- 
2.11.0

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] i2c: axxia: enable clock before calling clk_get_rate()
  2018-04-30 14:49 [PATCH v2] i2c: axxia: enable clock before calling clk_get_rate() Tobias Jordan
@ 2018-05-08 21:15 ` Wolfram Sang
  0 siblings, 0 replies; 2+ messages in thread
From: Wolfram Sang @ 2018-05-08 21:15 UTC (permalink / raw)
  To: Tobias Jordan; +Cc: linux-i2c, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 520 bytes --]

On Mon, Apr 30, 2018 at 04:49:29PM +0200, Tobias Jordan wrote:
> axxia_i2c_init() uses clk_get_rate() for idev->i2c_clk. clk_get_rate()
> should only be called if the clock is enabled, so ensure that by moving
> the clk_prepare_enable() call before the call to axxia_i2c_init().
> 
> Found by Linux Driver Verification project (linuxtesting.org).
> 
> Fixes: 08678b850cd0 ("i2c: axxia: Add I2C driver for AXM55xx")
> Signed-off-by: Tobias Jordan <Tobias.Jordan@elektrobit.com>

Applied to for-next, thanks!


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-05-08 21:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-30 14:49 [PATCH v2] i2c: axxia: enable clock before calling clk_get_rate() Tobias Jordan
2018-05-08 21:15 ` Wolfram Sang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).