[PATCH RFC RFT v3 01/13] clk: divider: Add CLK_DIVIDER_INVALID_ZERO flag

Jerome Brunet jbrunet at baylibre.com
Thu Dec 3 07:34:19 PST 2026


On 2026-12-01 09:10:14+00:00, sashiko-bot at kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue to consider:
> - [Medium] clk: divider: divider_ro_determine_rate() ignores
>   CLK_DIVIDER_ALLOW_ZERO
> --
> 
> commit 4e759b85217f16d179883cd2a607d512a8a7c0a5
> Author: Jian Hu <jian.hu at amlogic.com>
> 
> clk: divider: Add CLK_DIVIDER_INVALID_ZERO flag
> 
> This commit adds the CLK_DIVIDER_INVALID_ZERO flag so divider_recalc_rate()
> returns 0 instead of parent_rate when the decoded divisor is zero, and
> makes divider_ro_determine_rate() return -EINVAL on a zero divisor.
> 
> > diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c
> > index f68216c65d3df..74ae203e5ff8a 100644
> > --- a/drivers/clk/clk-divider.c
> > +++ b/drivers/clk/clk-divider.c
> > @@ -143,6 +143,9 @@ unsigned long divider_recalc_rate(struct clk_hw *hw, unsigned long parent_rate,
> >  
> >  	div = _get_div(table, val, flags, width);
> >  	if (!div) {
> > +		if (flags & CLK_DIVIDER_INVALID_ZERO)
> > +			return 0;
> > +
> >  		WARN(!(flags & CLK_DIVIDER_ALLOW_ZERO),
> >  			"%s: Zero divisor and CLK_DIVIDER_ALLOW_ZERO not set\n",
> >  			clk_hw_get_name(hw));
> > @@ -380,6 +383,8 @@ int divider_ro_determine_rate(struct clk_hw *hw, struct clk_rate_request *req,
> >  	int div;
> >  
> >  	div = _get_div(table, val, flags, width);
> > +	if (!div)
> > +		return -EINVAL;
> 
> [Severity: Medium]
> Does returning -EINVAL here unconditionally break read-only dividers where
> a zero divisor is a valid divide-by-one bypass (such as those using
> CLK_DIVIDER_ONE_BASED | CLK_DIVIDER_ALLOW_ZERO, like DEFINE_SG2044_DIV_RO
> in drivers/clk/sophgo/clk-sg2044.c)?

Looks like a pre-existing issue (that needs fixing).

It would have either ask the parent to round to zero is CLK_SET_PARENT_RATE is set
or divided by zero. Probably need to check for ALLOW_ZERO is _get_div()

-- 
Jerome




More information about the linux-amlogic mailing list