Re: [PATCH v2 06/15] phy: ti: phy-j721e-wiz: make wiz_clock_init callable multiple times

Andy Shevchenko
2024-01-26T21:39:31Z

On Fri, Jan 26, 2024 at 4:37 PM Thomas Richard
<thomas.richard@bootlin.com> wrote:
>
> For suspend and resume support, wiz_clock_init needs to be called multiple

wiz_clock_init()

> times.
>
> Add a parameter to wiz_clock_init to be able to skip clocks registration.

Ditto.

...to skip the registration of the clocks.

...

> -static int wiz_clock_init(struct wiz *wiz, struct device_node *node)
> +static int wiz_clock_init(struct wiz *wiz, struct device_node *node, bool probe)

So, why not refactor this to two functions first?

...

> + clk = devm_clk_get(dev, "core_ref_clk");
> + if (IS_ERR(clk)) {

> + dev_err(dev, "core_ref_clk clock not found\n");
> + ret = PTR_ERR(clk);
> + return ret;

This is wrong and has to be fixed in the original code.
The correct approach is to use `return dev_err_probe(...)` or open
code it, but since we have a helper, open coding is highly
discouraged.

> + }

...

> + if (wiz->data->pma_cmn_refclk1_int_mode) {
> + clk = devm_clk_get(dev, "core_ref1_clk");
> + if (IS_ERR(clk)) {
> + dev_err(dev, "core_ref1_clk clock not found\n");
> + ret = PTR_ERR(clk);
> + return ret;

Ditto.

> + }

...

> + clk = devm_clk_get(dev, "ext_ref_clk");
> + if (IS_ERR(clk)) {
> + dev_err(dev, "ext_ref_clk clock not found\n");
> + ret = PTR_ERR(clk);
> + return ret;

Ditto.

> + }

...

> + /* What follows is about registering clocks. */
> + if (!probe)
> + return 0;

Just refactor properly, no need to have this ugly mix of devm_*() for
probe stage, parameter and HW related things.

--
With Best Regards,
Andy Shevchenko