mirror of https://lore.kernel.org/linux-amlogic/
 help / color / mirror / Atom feed
From: Jian Hu <jian.hu@amlogic.com>
To: sashiko-reviews@lists.linux.dev
Cc: linux-clk@vger.kernel.org, linux-amlogic@lists.infradead.org,
	devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org,
	neil.armstrong@linaro.org
Subject: Re: [PATCH RFC RFT v3 01/13] clk: divider: Add CLK_DIVIDER_INVALID_ZERO flag
Date: Thu, 3 Dec 2026 15:58:16 +0800	[thread overview]
Message-ID: <64c28a7f-9efd-488c-b78c-4f44b90a5d0b@amlogic.com> (raw)
In-Reply-To: <sashiko-outbox-242919@kernel.org>


On 12/1/2026 5:10 PM, sashiko-bot@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@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)?
>
> When CLK_DIVIDER_INVALID_ZERO is not set, divider_recalc_rate() treats
> !div as a pass-through and returns parent_rate, whereas
> divider_ro_determine_rate() now rejects it with -EINVAL instead of treating
> div as 1.  This breaks clk_round_rate(), clk_set_rate() and parent rate
> propagation across read-only bypass dividers when the register reads 0.


You are right. 'CLK_DIVIDER_ALLOW_ZERO' is not taken into account here.

I will update the change like this:

376 int divider_ro_determine_rate(struct clk_hw *hw, struct 
clk_rate_request *req,
377                               const struct clk_div_table *table, u8 
width,
378                               unsigned long flags, unsigned int val)
379 {
380         int div;
381
382         div = _get_div(table, val, flags, width);
383         if (!div) {
384                 if (flags & CLK_DIVIDER_INVALID_ZERO)
385                         return -EINVAL;
386
387                 /* Same as divider_recalc_rate(): a zero divisor is 
a bypass */
388                 WARN(!(flags & CLK_DIVIDER_ALLOW_ZERO),
389                         "%s: Zero divisor and CLK_DIVIDER_ALLOW_ZERO 
not set\n",
390                         clk_hw_get_name(hw));
391                 div = 1;
392         }

Lines 387–391 will be addressed in a separate patch to fix a 
pre-existing division-by-zero issue.

Line 384-385 will be add in the 01/13 patch.


With these modifications, the logic for `recalc_rate` and 
`ro_determine_rate` is as follows:

                                              recalc                     
         ro_determine

INVALID_ZERO                     return 0                return -EINVAL

ALLOW_ZERO                       return parent_rate         div = 1, 
Continue calculation

None                                    WARN + return parent_rate        
WARN + div = 1, Continue calculation


> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20261201-meson_refactor_n-v3-0-f85a4460fd80@amlogic.com?part=1

_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

  reply	other threads:[~2026-12-03  7:58 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  8:56 [PATCH RFC RFT v3 00/13] clk: meson: Refactor PLL pre-divider as a divider clock Jian Hu via B4 Relay
2026-12-01  8:56 ` [PATCH RFC RFT v3 01/13] clk: divider: Add CLK_DIVIDER_INVALID_ZERO flag Jian Hu via B4 Relay
2026-12-01  9:10   ` sashiko-bot
2026-12-03  7:58     ` Jian Hu [this message]
2026-12-01  8:56 ` [PATCH RFC RFT v3 02/13] clk: meson: clk-regmap: Widen the divider flags to 16 bits Jian Hu via B4 Relay
2026-12-01  8:56 ` [PATCH RFC RFT v3 03/13] dt-bindings: clock: amlogic: Add PLL pre-divider clock IDs Jian Hu via B4 Relay
2026-12-01  8:56 ` [PATCH RFC RFT v3 04/13] clk: meson: axg: Model the PLL pre-divider as a divider clock Jian Hu via B4 Relay
2026-12-01  9:11   ` sashiko-bot
2026-12-01  8:56 ` [PATCH RFC RFT v3 05/13] clk: meson: a1: " Jian Hu via B4 Relay
2026-12-01  8:56 ` [PATCH RFC RFT v3 06/13] clk: meson: c3: " Jian Hu via B4 Relay
2026-12-01  8:56 ` [PATCH RFC RFT v3 07/13] clk: meson: gxbb: " Jian Hu via B4 Relay
2026-12-01  9:16   ` sashiko-bot
2026-12-02  9:19     ` Jian Hu
2026-12-01  8:56 ` [PATCH RFC RFT v3 08/13] clk: meson: g12a: " Jian Hu via B4 Relay
2026-12-01  9:19   ` sashiko-bot
2026-12-03  2:30     ` Jian Hu
2026-12-01  8:56 ` [PATCH RFC RFT v3 09/13] clk: meson: meson8: " Jian Hu via B4 Relay
2026-12-01  8:56 ` [PATCH RFC RFT v3 10/13] clk: meson: s4: " Jian Hu via B4 Relay
2026-12-01  8:56 ` [PATCH RFC RFT v3 11/13] clk: meson: s7: " Jian Hu via B4 Relay
2026-12-01 11:37   ` Carlo Caione
2026-12-01  8:56 ` [PATCH RFC RFT v3 12/13] clk: meson: t7: " Jian Hu via B4 Relay
2026-12-01  8:56 ` [PATCH RFC RFT v3 13/13] clk: meson: pll: Remove the dedicated n parameter Jian Hu via B4 Relay
2026-12-01  9:28   ` sashiko-bot
2026-12-01 13:16   ` Carlo Caione

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=64c28a7f-9efd-488c-b78c-4f44b90a5d0b@amlogic.com \
    --to=jian.hu@amlogic.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-amlogic@lists.infradead.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=neil.armstrong@linaro.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®