Skip to content

Commit 5575014

Browse files
tititiou36Andi Shyti
authored andcommitted
i2c: synquacer: Fix an error handling path in synquacer_i2c_probe()
If an error occurs after the clk_prepare_enable() call, it should be undone by a corresponding clk_disable_unprepare() call, as already done in the remove() function. As devm_clk_get() is used, we can switch to devm_clk_get_enabled() to handle it automatically and fix the probe. Update the remove() function accordingly and remove the now useless clk_disable_unprepare() call. Fixes: 0d676a6 ("i2c: add support for Socionext SynQuacer I2C controller") Signed-off-by: Christophe JAILLET <[email protected]> Acked-by: Ard Biesheuvel <[email protected]> Signed-off-by: Andi Shyti <[email protected]>
1 parent c2e55b4 commit 5575014

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

drivers/i2c/busses/i2c-synquacer.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -550,17 +550,13 @@ static int synquacer_i2c_probe(struct platform_device *pdev)
550550
device_property_read_u32(&pdev->dev, "socionext,pclk-rate",
551551
&i2c->pclkrate);
552552

553-
i2c->pclk = devm_clk_get(&pdev->dev, "pclk");
554-
if (PTR_ERR(i2c->pclk) == -EPROBE_DEFER)
555-
return -EPROBE_DEFER;
556-
if (!IS_ERR_OR_NULL(i2c->pclk)) {
557-
dev_dbg(&pdev->dev, "clock source %p\n", i2c->pclk);
558-
559-
ret = clk_prepare_enable(i2c->pclk);
560-
if (ret)
561-
return dev_err_probe(&pdev->dev, ret, "failed to enable clock\n");
562-
i2c->pclkrate = clk_get_rate(i2c->pclk);
563-
}
553+
i2c->pclk = devm_clk_get_enabled(&pdev->dev, "pclk");
554+
if (IS_ERR(i2c->pclk))
555+
return dev_err_probe(&pdev->dev, PTR_ERR(i2c->pclk),
556+
"failed to get and enable clock\n");
557+
558+
dev_dbg(&pdev->dev, "clock source %p\n", i2c->pclk);
559+
i2c->pclkrate = clk_get_rate(i2c->pclk);
564560

565561
if (i2c->pclkrate < SYNQUACER_I2C_MIN_CLK_RATE ||
566562
i2c->pclkrate > SYNQUACER_I2C_MAX_CLK_RATE)
@@ -615,8 +611,6 @@ static void synquacer_i2c_remove(struct platform_device *pdev)
615611
struct synquacer_i2c *i2c = platform_get_drvdata(pdev);
616612

617613
i2c_del_adapter(&i2c->adapter);
618-
if (!IS_ERR(i2c->pclk))
619-
clk_disable_unprepare(i2c->pclk);
620614
};
621615

622616
static const struct of_device_id synquacer_i2c_dt_ids[] __maybe_unused = {

0 commit comments

Comments
 (0)