Re: [PATCH v8 05/16] hwrng: meson - Don't open-code devm_clk_get_optional_enabled()

Neil Armstrong
2022-03-16T08:32:53Z

On 14/03/2022 15:16, Uwe Kleine-König wrote:
> devm_clk_get_enabled() returns a clock prepared and enabled and already
> registers a devm exit handler to disable (and unprepare) the clock.
>
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
> drivers/char/hw_random/meson-rng.c | 20 ++------------------
> 1 file changed, 2 insertions(+), 18 deletions(-)
>
> diff --git a/drivers/char/hw_random/meson-rng.c b/drivers/char/hw_random/meson-rng.c
> index 8bb30282ca46..06db5a93e257 100644
> --- a/drivers/char/hw_random/meson-rng.c
> +++ b/drivers/char/hw_random/meson-rng.c
> @@ -33,16 +33,10 @@ static int meson_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait)
> return sizeof(u32);
> }
>
> -static void meson_rng_clk_disable(void *data)
> -{
> - clk_disable_unprepare(data);
> -}
> -
> static int meson_rng_probe(struct platform_device *pdev)
> {
> struct device *dev = &pdev->dev;
> struct meson_rng_data *data;
> - int ret;
>
> data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
> if (!data)
> @@ -54,20 +48,10 @@ static int meson_rng_probe(struct platform_device *pdev)
> if (IS_ERR(data->base))
> return PTR_ERR(data->base);
>
> - data->core_clk = devm_clk_get_optional(dev, "core");
> + data->core_clk = devm_clk_get_optional_enabled(dev, "core");
> if (IS_ERR(data->core_clk))
> return dev_err_probe(dev, PTR_ERR(data->core_clk),
> - "Failed to get core clock\n");
> -
> - if (data->core_clk) {
> - ret = clk_prepare_enable(data->core_clk);
> - if (ret)
> - return ret;
> - ret = devm_add_action_or_reset(dev, meson_rng_clk_disable,
> - data->core_clk);
> - if (ret)
> - return ret;
> - }
> + "Failed to get enabled core clock\n");
>
> data->rng.name = pdev->name;
> data->rng.read = meson_rng_read;

Acked-by: Neil Armstrong <narmstrong@baylibre.com>