Re: [PATCH 1/3] clk: Introduce clk_set_spread_spectrum

Dan Carpenter
2025-01-24T13:51:27Z

On Fri, Jan 24, 2025 at 10:25:17PM +0800, Peng Fan (OSS) wrote:
> diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
> index cf7720b9172ff223d86227aad144e15375ddfd86..a4fe4a60f839244b736e3c2751eeb38dc4577b1f 100644
> --- a/drivers/clk/clk.c
> +++ b/drivers/clk/clk.c
> @@ -2790,6 +2790,45 @@ int clk_set_max_rate(struct clk *clk, unsigned long rate)
> }
> EXPORT_SYMBOL_GPL(clk_set_max_rate);
>
> +int clk_set_spread_spectrum(struct clk *clk, unsigned int modfreq,
> + unsigned int spreadpercent, unsigned int method,
> + bool enable)
> +{
> + struct clk_spread_spectrum clk_ss;
> + struct clk_core *core;
> + int ret = 0;
> +
> + if (!clk || !clk->core)
> + return 0;
> +
> + clk_ss.modfreq = modfreq;
> + clk_ss.spreadpercent = spreadpercent;
> + clk_ss.method = method;
> + clk_ss.enable = enable;
> +
> + clk_prepare_lock();
> +
> + core = clk->core;
> +
> + if (core->prepare_count) {
> + ret = -EBUSY;
> + goto fail;

fail is too vague to be useful as a name. Also this should be
goto unlock;

> + }
> +
> + ret = clk_pm_runtime_get(core);
> + if (ret)
> + goto fail;
> +
> + if (core->ops->set_spread_spectrum)
> + ret = core->ops->set_spread_spectrum(core->hw, &clk_ss);
> +
> + clk_pm_runtime_put(core);
unlock:

> + clk_prepare_unlock();
> +fail:
> + return ret;
> +}

regards,
dan carpenter