diff mbox series

i2c: synquacer: fix missing clk_disable_unprepare() on error path

Message ID 20221115050429.184659-1-tanghui20@huawei.com
State Needs Review / ACK
Headers show
Series i2c: synquacer: fix missing clk_disable_unprepare() on error path | expand

Commit Message

Hui Tang Nov. 15, 2022, 5:04 a.m. UTC
clk_disable_unprepare() should be invoked on error path after
clk_prepare_enable() in synquacer_i2c_probe.

Fixes: 0d676a6c4390 ("2c: add support for Socionext SynQuacer I2C controller")
Signed-off-by: Hui Tang <tanghui20@huawei.com>
---
 drivers/i2c/busses/i2c-synquacer.c | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/drivers/i2c/busses/i2c-synquacer.c b/drivers/i2c/busses/i2c-synquacer.c
index cba1145ddfac..73d9168573ec 100644
--- a/drivers/i2c/busses/i2c-synquacer.c
+++ b/drivers/i2c/busses/i2c-synquacer.c
@@ -569,22 +569,27 @@  static int synquacer_i2c_probe(struct platform_device *pdev)
 	    i2c->pclkrate > SYNQUACER_I2C_MAX_CLK_RATE) {
 		dev_err(&pdev->dev, "PCLK missing or out of range (%d)\n",
 			i2c->pclkrate);
-		return -EINVAL;
+		ret = -EINVAL;
+		goto clk_free;
 	}
 
 	i2c->base = devm_platform_ioremap_resource(pdev, 0);
-	if (IS_ERR(i2c->base))
-		return PTR_ERR(i2c->base);
+	if (IS_ERR(i2c->base)) {
+		ret = PTR_ERR(i2c->base);
+		goto clk_free;
+	}
 
 	i2c->irq = platform_get_irq(pdev, 0);
-	if (i2c->irq < 0)
-		return i2c->irq;
+	if (i2c->irq < 0) {
+		ret = i2c->irq;
+		goto clk_free;
+	}
 
 	ret = devm_request_irq(&pdev->dev, i2c->irq, synquacer_i2c_isr,
 			       0, dev_name(&pdev->dev), i2c);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "cannot claim IRQ %d\n", i2c->irq);
-		return ret;
+		goto clk_free;
 	}
 
 	i2c->state = STATE_IDLE;
@@ -607,7 +612,7 @@  static int synquacer_i2c_probe(struct platform_device *pdev)
 	ret = i2c_add_numbered_adapter(&i2c->adapter);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to add bus to i2c core\n");
-		return ret;
+		goto clk_free;
 	}
 
 	platform_set_drvdata(pdev, i2c);
@@ -616,6 +621,11 @@  static int synquacer_i2c_probe(struct platform_device *pdev)
 		 dev_name(&i2c->adapter.dev));
 
 	return 0;
+
+clk_free:
+	if (!IS_ERR(i2c->pclk))
+		clk_disable_unprepare(i2c->pclk);
+	return ret;
 }
 
 static int synquacer_i2c_remove(struct platform_device *pdev)