Linux clock framework development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Lee Jones" <lee@kernel.org>, linux-clk@vger.kernel.org
Subject: Re: [PATCH 05/10] clk: divider: Avoid division by zero in _div_round_closest()
Date: Mon, 23 Nov 2026 17:13:39 +0000	[thread overview]
Message-ID: <sashiko-outbox-229709@kernel.org> (raw)
In-Reply-To: <20261123164834.3330320-6-lee@kernel.org>

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] clk: divider: 64-bit addition overflow in _div_round() and
  divider_get_val() [1]
--

commit 794cea87b2763d8416c120885c5c264136bf9dfd
Author: Lee Jones <lee@kernel.org>

clk: divider: Avoid division by zero in _div_round_closest()

This commit returns the minimum valid divisor from _div_round_closest()
when the requested rate is greater than or equal to parent_rate, avoiding
a zero divisor and subsequent division by zero.

> diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c
> index f68216c65d3df..d05dc595ec4c7 100644
> --- a/drivers/clk/clk-divider.c
> +++ b/drivers/clk/clk-divider.c
> @@ -244,6 +244,9 @@ static int _div_round_closest(const struct clk_div_table *table,
>  	int up, down;
>  	unsigned long up_rate, down_rate;
>  
> +	if (rate >= parent_rate)
> +		return table ? _round_up_table(table, 1) : 1;
> +
>  	up = DIV_ROUND_UP_ULL((u64)parent_rate, rate);
>  	down = parent_rate / rate;

[Severity: High]
This problem wasn't introduced by this patch, but can DIV_ROUND_UP_ULL()
still overflow 64-bit addition in _div_round_up() and divider_get_val()
[1]?

drivers/clk/clk-divider.c:_div_round_up() {
	int div = DIV_ROUND_UP_ULL((u64)parent_rate, rate);

	if (flags & CLK_DIVIDER_POWER_OF_TWO)
		div = __roundup_pow_of_two(div);
	...
}

On 64-bit platforms, when rate > U64_MAX - parent_rate + 1 (for example,
via clk_round_rate(clk, ULONG_MAX) or when clk_divider_bestdiv() clamps an
overflowing target_parent_rate to ULONG_MAX), (u64)parent_rate + rate - 1
wraps around and DIV_ROUND_UP_ULL() evaluates to 0 instead of 1.  That
passes 0 to __roundup_pow_of_two() when CLK_DIVIDER_POWER_OF_TWO is set
(triggering an undefined shift) or underflows div - 1 in _get_val() when
called from divider_get_val().

[1] https://sashiko.dev/#/bug/linux-4e20dfb7-a4d5-4b44-bb0d-e7b8ced3408c

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261123164834.3330320-1-lee@kernel.org?part=5

  reply	other threads:[~2026-11-23 17:13 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 16:47 [PATCH 00/10] clk: Assorted bug fixes across clock core and drivers Lee Jones
2026-11-23 16:47 ` [PATCH 01/10] clk: imx: imx8qxp-lpcg: Prevent stack overflow when parsing clocks Lee Jones
2026-11-23 17:25   ` Frank Li
2026-11-23 16:47 ` [PATCH 02/10] clk: lmk04832: Validate child reg index in lmk04832_probe() Lee Jones
2026-11-23 16:47 ` [PATCH 03/10] clk: tegra: bpmp: Bound num_parents by MRQ_CLK_MAX_PARENTS Lee Jones
2026-11-23 16:47 ` [PATCH 04/10] clk: composite: Initialise sub-hw pointers in determine_rate() Lee Jones
2026-11-23 16:47 ` [PATCH 05/10] clk: divider: Avoid division by zero in _div_round_closest() Lee Jones
2026-11-23 17:13   ` sashiko-bot [this message]
2026-11-23 16:47 ` [PATCH 06/10] clk: gpio: Reject gate clocks with multiple parents Lee Jones
2026-11-23 16:47 ` [PATCH 07/10] clk: samsung: exynos5420: Terminate PLL rate tables with sentinels Lee Jones
2026-11-23 17:26   ` Krzysztof Kozlowski
2026-11-23 16:47 ` [PATCH 08/10] clk: tenstorrent: Poll atomically in atlantis_clk_pll_enable() Lee Jones
2026-11-23 16:47 ` [PATCH 09/10] clk: cdce925: Use devm_of_clk_add_hw_provider() to avoid UAF on unbind Lee Jones
2026-11-23 16:47 ` [PATCH 10/10] clk: mmp: audio: Use devm_of_clk_add_hw_provider() to prevent UAF Lee Jones

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=sashiko-outbox-229709@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=lee@kernel.org \
    --cc=linux-clk@vger.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