Skip to content

Commit 9e1a1ee

Browse files
hotencodewsakernel
authored andcommitted
i2c: ocores: use devm_ managed clks
Smatch complains that: drivers/i2c/busses/i2c-ocores.c:704 ocores_i2c_probe() warn: missing unwind goto? If any wrong occurs in ocores_i2c_of_probe, the i2c->clk needs to be released. But the function returns directly without freeing the clock. Fix this by updating the code to use devm_clk_get_optional_enabled() instead. Use dev_err_probe() where appropriate as well since we are changing those statements. Fixes: f5f35a9 ("i2c: ocores: Add irq support for sparc") Signed-off-by: Wang Zhang <[email protected]> Reviewed-by: Andi Shyti <[email protected]> Reviewed-by: Andrew Lunn <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
1 parent e653810 commit 9e1a1ee

File tree

1 file changed

+21
-43
lines changed

1 file changed

+21
-43
lines changed

drivers/i2c/busses/i2c-ocores.c

Lines changed: 21 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -552,28 +552,20 @@ static int ocores_i2c_of_probe(struct platform_device *pdev,
552552
&clock_frequency);
553553
i2c->bus_clock_khz = 100;
554554

555-
i2c->clk = devm_clk_get(&pdev->dev, NULL);
556-
557-
if (!IS_ERR(i2c->clk)) {
558-
int ret = clk_prepare_enable(i2c->clk);
559-
560-
if (ret) {
561-
dev_err(&pdev->dev,
562-
"clk_prepare_enable failed: %d\n", ret);
563-
return ret;
564-
}
565-
i2c->ip_clock_khz = clk_get_rate(i2c->clk) / 1000;
566-
if (clock_frequency_present)
567-
i2c->bus_clock_khz = clock_frequency / 1000;
568-
}
569-
555+
i2c->clk = devm_clk_get_optional_enabled(&pdev->dev, NULL);
556+
if (IS_ERR(i2c->clk))
557+
return dev_err_probe(&pdev->dev, PTR_ERR(i2c->clk),
558+
"devm_clk_get_optional_enabled failed\n");
559+
560+
i2c->ip_clock_khz = clk_get_rate(i2c->clk) / 1000;
561+
if (clock_frequency_present)
562+
i2c->bus_clock_khz = clock_frequency / 1000;
570563
if (i2c->ip_clock_khz == 0) {
571564
if (of_property_read_u32(np, "opencores,ip-clock-frequency",
572565
&val)) {
573566
if (!clock_frequency_present) {
574567
dev_err(&pdev->dev,
575568
"Missing required parameter 'opencores,ip-clock-frequency'\n");
576-
clk_disable_unprepare(i2c->clk);
577569
return -ENODEV;
578570
}
579571
i2c->ip_clock_khz = clock_frequency / 1000;
@@ -678,8 +670,7 @@ static int ocores_i2c_probe(struct platform_device *pdev)
678670
default:
679671
dev_err(&pdev->dev, "Unsupported I/O width (%d)\n",
680672
i2c->reg_io_width);
681-
ret = -EINVAL;
682-
goto err_clk;
673+
return -EINVAL;
683674
}
684675
}
685676

@@ -710,13 +701,13 @@ static int ocores_i2c_probe(struct platform_device *pdev)
710701
pdev->name, i2c);
711702
if (ret) {
712703
dev_err(&pdev->dev, "Cannot claim IRQ\n");
713-
goto err_clk;
704+
return ret;
714705
}
715706
}
716707

717708
ret = ocores_init(&pdev->dev, i2c);
718709
if (ret)
719-
goto err_clk;
710+
return ret;
720711

721712
/* hook up driver to tree */
722713
platform_set_drvdata(pdev, i2c);
@@ -728,7 +719,7 @@ static int ocores_i2c_probe(struct platform_device *pdev)
728719
/* add i2c adapter to i2c tree */
729720
ret = i2c_add_adapter(&i2c->adap);
730721
if (ret)
731-
goto err_clk;
722+
return ret;
732723

733724
/* add in known devices to the bus */
734725
if (pdata) {
@@ -737,10 +728,6 @@ static int ocores_i2c_probe(struct platform_device *pdev)
737728
}
738729

739730
return 0;
740-
741-
err_clk:
742-
clk_disable_unprepare(i2c->clk);
743-
return ret;
744731
}
745732

746733
static void ocores_i2c_remove(struct platform_device *pdev)
@@ -754,9 +741,6 @@ static void ocores_i2c_remove(struct platform_device *pdev)
754741

755742
/* remove adapter & data */
756743
i2c_del_adapter(&i2c->adap);
757-
758-
if (!IS_ERR(i2c->clk))
759-
clk_disable_unprepare(i2c->clk);
760744
}
761745

762746
#ifdef CONFIG_PM_SLEEP
@@ -769,28 +753,22 @@ static int ocores_i2c_suspend(struct device *dev)
769753
ctrl &= ~(OCI2C_CTRL_EN | OCI2C_CTRL_IEN);
770754
oc_setreg(i2c, OCI2C_CONTROL, ctrl);
771755

772-
if (!IS_ERR(i2c->clk))
773-
clk_disable_unprepare(i2c->clk);
756+
clk_disable_unprepare(i2c->clk);
774757
return 0;
775758
}
776759

777760
static int ocores_i2c_resume(struct device *dev)
778761
{
779762
struct ocores_i2c *i2c = dev_get_drvdata(dev);
763+
unsigned long rate;
764+
int ret;
780765

781-
if (!IS_ERR(i2c->clk)) {
782-
unsigned long rate;
783-
int ret = clk_prepare_enable(i2c->clk);
784-
785-
if (ret) {
786-
dev_err(dev,
787-
"clk_prepare_enable failed: %d\n", ret);
788-
return ret;
789-
}
790-
rate = clk_get_rate(i2c->clk) / 1000;
791-
if (rate)
792-
i2c->ip_clock_khz = rate;
793-
}
766+
ret = clk_prepare_enable(i2c->clk);
767+
if (ret)
768+
return dev_err_probe(dev, ret, "clk_prepare_enable failed\n");
769+
rate = clk_get_rate(i2c->clk) / 1000;
770+
if (rate)
771+
i2c->ip_clock_khz = rate;
794772
return ocores_init(dev, i2c);
795773
}
796774

0 commit comments

Comments
 (0)