From: Jian Hu <jian.hu@amlogic.com>
To: sashiko-reviews@lists.linux.dev
Cc: linux-amlogic@lists.infradead.org, linux-clk@vger.kernel.org,
devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org,
neil.armstrong@linaro.org
Subject: Re: [PATCH RFC RFT v2 2/3] clk: divider: add CLK_DIVIDER_INVALID_ZERO flag
Date: Wed, 4 Nov 2026 17:07:10 +0800 [thread overview]
Message-ID: <02476c54-d8ae-479d-898f-cd89ee2f7c24@amlogic.com> (raw)
In-Reply-To: <sashiko-outbox-189068@kernel.org>
On 10/29/2026 5:47 PM, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [High] clk: divider: unhandled zero divisor in divider_ro_determine_rate()
> --
>
> commit 5ec3118aee2f03855552c58a4a8533e035b565bc
> Author: Jian Hu <jian.hu@amlogic.com>
>
> clk: divider: add CLK_DIVIDER_INVALID_ZERO flag
>
> This commit introduces the CLK_DIVIDER_INVALID_ZERO flag for dividers where
> a zero divisor value represents an invalid hardware state rather than a
> pass-through. When this flag is set and the divisor evaluates to zero,
> divider_recalc_rate() returns 0 without emitting a warning.
>
>> diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c
>> index f68216c65d3df..6c1523d22477c 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;
> [Severity: High]
> Should divider_ro_determine_rate() in drivers/clk/clk-divider.c also handle
> a zero divisor when CLK_DIVIDER_INVALID_ZERO or CLK_DIVIDER_ALLOW_ZERO is
> set?
>
> When a read-only divider has a register value val that maps to div == 0 via
> _get_div() (for example, when CLK_DIVIDER_INVALID_ZERO is combined with
> CLK_DIVIDER_ONE_BASED or an unmapped table entry alongside
> CLK_DIVIDER_READ_ONLY), calling clk_round_rate() or clk_set_rate() invokes
> clk_divider_determine_rate()->divider_ro_determine_rate():
>
> drivers/clk/clk-divider.c:divider_ro_determine_rate() {
> int div;
>
> div = _get_div(table, val, flags, width);
>
> /* Even a read-only clock can propagate a rate change */
> if (clk_hw_get_flags(hw) & CLK_SET_RATE_PARENT) {
> if (!req->best_parent_hw)
> return -EINVAL;
>
> req->best_parent_rate = clk_hw_round_rate(req->best_parent_hw,
> req->rate * div);
> }
>
> req->rate = DIV_ROUND_UP_ULL((u64)req->best_parent_rate, div);
>
> return 0;
> }
>
> Unlike divider_recalc_rate(), divider_ro_determine_rate() does not check for
> !div before calling DIV_ROUND_UP_ULL(), which will trigger a division by zero
> in the kernel when div is 0.
In this patch, the dividers which set CLK_DIVIDER_INVALID_ZERO use
divider_determine_rate(),
not divider_ro_determine_rate().
divider_ro_determine_rate() is used for read-only dividers, which do not
have CLK_DIVIDER_INVALID_ZERO
set in the current implementation.
Therefore, a zero divisor caused by CLK_DIVIDER_INVALID_ZERO cannot occur in
divider_ro_determine_rate(), and no additional check is needed here.
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20261029-meson_refactor_n-v2-0-ff4ac74e527b@amlogic.com?part=2
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
next prev parent reply other threads:[~2026-11-04 9:07 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-29 9:30 [PATCH RFC RFT v2 0/3] clk: meson: Refactor PLL pre-divider as a divider clock Jian Hu via B4 Relay
2026-10-29 9:30 ` [PATCH RFC RFT v2 1/3] dt-bindings: clock: amlogic: Add PLL pre-divider clock IDs Jian Hu via B4 Relay
2026-10-29 9:30 ` [PATCH RFC RFT v2 2/3] clk: divider: add CLK_DIVIDER_INVALID_ZERO flag Jian Hu via B4 Relay
2026-10-29 9:47 ` sashiko-bot
2026-11-04 9:07 ` Jian Hu [this message]
2026-10-29 9:30 ` [PATCH RFC RFT v2 3/3] clk: meson: pll: Remove the dedicated n parameter Jian Hu via B4 Relay
2026-10-29 9:57 ` sashiko-bot
2026-11-04 11:59 ` Jian Hu
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=02476c54-d8ae-479d-898f-cd89ee2f7c24@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®