From: sashiko-bot@kernel.org
To: "Christian Marangi" <ansuelsmth@gmail.com>, linux-clk@vger.kernel.org
Subject: Re: [PATCH v7 2/2] clk: en7523: add support for .set_rate for en7581
Date: Fri, 20 Nov 2026 23:13:56 +0000 [thread overview]
Message-ID: <sashiko-outbox-226339@kernel.org> (raw)
In-Reply-To: <20261120225916.158641-3-ansuelsmth@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] clk: en7523: division by zero in _div_round_closest() via
en7581_find_best_rate()
--
commit e6dd4eae87f38e0af65399298c3f7bcf2f939553
Author: Christian Marangi <ansuelsmth@gmail.com>
clk: en7523: add support for .set_rate for en7581
This commit adds .set_rate and .determine_rate support for Airoha EN7581
clocks and switches rate recalculation to the standard clock divider
helpers.
> diff --git a/drivers/clk/clk-en7523.c b/drivers/clk/clk-en7523.c
> index 8c00646ecdc6a..f47f3ee75057e 100644
> --- a/drivers/clk/clk-en7523.c
> +++ b/drivers/clk/clk-en7523.c
[ ... ]
> @@ -773,11 +846,210 @@ static unsigned long en7581_recalc_rate(struct clk_hw *hw,
[ ... ]
> +static void en7581_find_best_rate(struct clk_hw *hw,
> + struct clk_rate_request *req,
> + const struct en_clk_desc *desc,
> + unsigned long parent_rate,
> + unsigned long requested_rate,
> + unsigned long *best_diff)
> +{
> + struct clk_rate_request div_req = *req;
> + int ret;
> +
> + if (!desc->div_bits) {
> + en7581_update_best_rate(req, requested_rate, parent_rate,
> + best_diff);
> + return;
> + }
> +
> + /* Treat each internal base rate as a fixed parent for the divider. */
> + div_req.rate = clamp(requested_rate, req->min_rate, req->max_rate);
> + div_req.best_parent_rate = parent_rate;
> + ret = divider_determine_rate(hw, &div_req, desc->div_table,
> + desc->div_bits,
> + CLK_DIVIDER_ROUND_CLOSEST);
> + if (ret)
> + return;
> +
> + en7581_update_best_rate(req, requested_rate, div_req.rate, best_diff);
> +}
> +
> +static int en7581_determine_rate(struct clk_hw *hw,
> + struct clk_rate_request *req)
> +{
> + struct en_clk *en_clk = container_of(hw, struct en_clk, hw);
> + const struct en_clk_desc *desc = en_clk->desc;
> + unsigned long best_diff = ULONG_MAX;
> + unsigned long rate = req->rate;
> + int tmp_base_val = 0;
> +
> + if (!rate || (!desc->base_bits && !desc->div_bits))
> + return -EINVAL;
> +
> + if (!desc->base_bits) {
> + en7581_find_best_rate(hw, req, desc, desc->base_value,
> + rate, &best_diff);
> + goto exit;
> + }
> +
> + for (; tmp_base_val < desc->n_base_values; tmp_base_val++)
> + en7581_find_best_rate(hw, req, desc,
> + desc->base_values[tmp_base_val],
> + rate, &best_diff);
[Severity: High]
Can this trigger a division by zero in _div_round_closest() when
requested_rate exceeds parent_rate?
en7581_determine_rate() loops over every entry in desc->base_values[], so
requesting e.g. 500 MHz on "gsw" (whose base_values are 400 MHz and
500 MHz, with div_table == NULL) calls en7581_find_best_rate() with
parent_rate = 400 MHz and div_req.rate = 500 MHz. Without clamping
div_req.rate to parent_rate, divider_determine_rate() ->
clk_divider_bestdiv() -> _div_round() reaches _div_round_closest() with
parent_rate < rate:
drivers/clk/clk-divider.c:_div_round_closest() {
up = DIV_ROUND_UP_ULL((u64)parent_rate, rate);
down = parent_rate / rate;
if (flags & CLK_DIVIDER_POWER_OF_TWO) {
up = __roundup_pow_of_two(up);
down = __rounddown_pow_of_two(down);
} else if (table) {
up = _round_up_table(table, up);
down = _round_down_table(table, down);
}
up_rate = DIV_ROUND_UP_ULL((u64)parent_rate, up);
down_rate = DIV_ROUND_UP_ULL((u64)parent_rate, down);
}
When table is NULL and CLK_DIVIDER_POWER_OF_TWO is not set, down is 0 and
computing down_rate divides by zero.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261120225916.158641-1-ansuelsmth@gmail.com?part=2
prev parent reply other threads:[~2026-11-20 23:13 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 22:59 [PATCH v7 0/2] clk: en7523: full clk_hw + set_rate for en7581 Christian Marangi
2026-11-20 22:59 ` [PATCH v7 1/2] clk: en7523: convert to full clk_hw implementation " Christian Marangi
2026-11-20 23:07 ` sashiko-bot
2026-11-20 22:59 ` [PATCH v7 2/2] clk: en7523: add support for .set_rate " Christian Marangi
2026-11-20 23:13 ` sashiko-bot [this message]
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-226339@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=ansuelsmth@gmail.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.