Re: [PATCH v11 1/2] clk: validate spread spectrum configuration
From: Peng Fan
Date: Wed Sep 02 2026 - 04:46:27 EST
On Tue, Sep 01, 2026 at 11:05:17AM +0200, Dario Binacchi wrote:
>The spread spectrum configuration is passed to the provider's
>set_spread_spectrum() callback without any validation, as clk-conf.c
>only skips all-zero triplets from "assigned-clock-sscs". An invalid
>device tree can hand providers a zero modulation frequency or a spread
>ratio above 100%, and each provider would have to add the same checks
>to protect e.g. divisions in its rate computations.
>
>Fixes: c86814e70390 ("clk: Introduce clk_hw_set_spread_spectrum")
>Signed-off-by: Dario Binacchi <dario.binacchi@xxxxxxxxxxxxxxxxxxxx>
>---
>
>(no changes since v1)
>
> drivers/clk/clk.c | 14 ++++++++++++++
> 1 file changed, 14 insertions(+)
>
>diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
>index fef87167a60b..208caf60eeb5 100644
>--- a/drivers/clk/clk.c
>+++ b/drivers/clk/clk.c
>@@ -2851,6 +2851,20 @@ int clk_hw_set_spread_spectrum(struct clk_hw *hw, const struct clk_spread_spectr
> if (!hw)
> return 0;
>
>+ switch (ss_conf->method) {
>+ case CLK_SPREAD_NO:
>+ break;
>+ case CLK_SPREAD_CENTER:
>+ case CLK_SPREAD_UP:
>+ case CLK_SPREAD_DOWN:
>+ if (!ss_conf->modfreq_hz || !ss_conf->spread_bp ||
>+ ss_conf->spread_bp > 10000)
>+ return -EINVAL;
I think sashiko comment is wrong.
In [1], we reached an agreement that spread "in permyriad, i.e. 0.01%".
So the input value must be the real value * 10000, saying 0.01% * 10000
[1] https://github.com/devicetree-org/dt-schema/pull/154
Regards
Peng
>+ break;
>+ default:
>+ return -EINVAL;
>+ }
>+
> core = hw->core;
>
> clk_prepare_lock();
>--
>2.43.0
>
>