Re: [PATCH v4] i2c: ocores: use devm_ managed clks

Andi Shyti
2023-06-13T23:55:16Z

Hi Wang,

> - i2c->clk = devm_clk_get(&pdev->dev, NULL);
> -
> - if (!IS_ERR(i2c->clk)) {
> - int ret = clk_prepare_enable(i2c->clk);
> -
> - if (ret) {
> - dev_err(&pdev->dev,
> - "clk_prepare_enable failed: %d\n", ret);
> - return ret;
> - }
> - i2c->ip_clock_khz = clk_get_rate(i2c->clk) / 1000;
> - if (clock_frequency_present)
> - i2c->bus_clock_khz = clock_frequency / 1000;
> - }
> -
> + i2c->clk = devm_clk_get_optional_enabled(&pdev->dev, NULL);
> + if (IS_ERR(i2c->clk))
> + return dev_err_probe(&pdev->dev, PTR_ERR(i2c->clk),
> + "devm_clk_get_optional_enabled failed\n");
> +
> + i2c->ip_clock_khz = clk_get_rate(i2c->clk) / 1000;

if devm_clk_get_optional_enabled() returns NULL, clk_get_rate()
returns '0' and op_clk_khz would be '0'...

> + if (clock_frequency_present)
> + i2c->bus_clock_khz = clock_frequency / 1000;
> if (i2c->ip_clock_khz == 0) {

... and we fall inside this 'if', as expected. Looks correct!

Reviewed-by: Andi Shyti <andi.shyti@kernel.org>

Thanks,
Andi