From: sashiko-bot@kernel.org
To: "Christian Marangi" <ansuelsmth@gmail.com>, linux-clk@vger.kernel.org
Subject: Re: [PATCH v6 2/2] clk: en7523: add support for .set_rate for en7581
Date: Tue, 17 Nov 2026 18:15:20 +0000 [thread overview]
Message-ID: <sashiko-outbox-219321@kernel.org> (raw)
In-Reply-To: <20261117180213.88046-3-ansuelsmth@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] clk: en7523: en7581_determine_rate() fails on unrounded
div_table rates
--
commit 2aba0750bb722a13abf74ccd375ad0f3b952c3b5
Author: Christian Marangi <ansuelsmth@gmail.com>
clk: en7523: add support for .set_rate for en7581
This commit adds .determine_rate and .set_rate clock operations for the
Airoha EN7581 SoC and converts the BUS, SLIC, and SPI clock dividers to use
clk_div_table arrays with the standard clock divider helpers.
> diff --git a/drivers/clk/clk-en7523.c b/drivers/clk/clk-en7523.c
> index 27ead83b639eb..a41eabd40401d 100644
> --- a/drivers/clk/clk-en7523.c
> +++ b/drivers/clk/clk-en7523.c
[ ... ]
> @@ -774,11 +847,192 @@ static unsigned long en7581_recalc_rate(struct clk_hw *hw,
[ ... ]
> +static unsigned long en7581_get_div_for_rate(struct clk_hw *hw,
> + unsigned long rate,
> + unsigned long parent_rate,
> + const struct en_clk_desc *desc,
> + int *div_val)
> +{
> + *div_val = divider_get_val(rate, parent_rate, desc->div_table,
> + desc->div_bits, 0);
> + if (*div_val < 0)
> + return 0;
> +
> + return divider_recalc_rate(hw, parent_rate, *div_val,
> + desc->div_table, 0,
> + desc->div_bits);
> +}
[ ... ]
> +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)
> +{
> + unsigned long tmp_rate, diff;
> + int tmp_div_val;
> +
> + tmp_rate = parent_rate;
> + if (desc->div_bits)
> + tmp_rate = en7581_get_div_for_rate(hw, requested_rate, parent_rate,
> + desc, &tmp_div_val);
> +
> + if (!tmp_rate || tmp_rate < req->min_rate ||
> + tmp_rate > req->max_rate)
> + return;
> +
> + diff = abs_diff(requested_rate, tmp_rate);
> + if (diff < *best_diff) {
> + *best_diff = diff;
> + req->rate = tmp_rate;
> + }
> +}
> +
> +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);
> +
> +exit:
> + return best_diff == ULONG_MAX ? -EINVAL : 0;
> +}
[Severity: Medium]
As reported by Brian Masney on v5 [1], can en7581_determine_rate() fail with
-EINVAL when a caller requests an unrounded rate on a clock with a
div_table?
en7581_find_best_rate() passes the unrounded requested_rate to
en7581_get_div_for_rate(), which calls divider_get_val():
drivers/clk/clk-divider.c:divider_get_val() {
div = DIV_ROUND_UP_ULL((u64)parent_rate, rate);
if (!_is_valid_div(table, div, flags))
return -EINVAL;
...
}
Unlike divider_determine_rate() or divider_ro_round_rate(), divider_get_val()
does not round or clamp div to the closest entry in desc->div_table; it
requires DIV_ROUND_UP_ULL(parent_rate, rate) to match a table divisor
exactly. For EN7523_CLK_SPI (400 MHz base, spi_div containing only even
divisors 2..62), requesting a rate such as 150 MHz (div = 3) or 400 MHz
(div = 1) makes divider_get_val() return -EINVAL, causing clk_round_rate()
and clk_set_rate() to fail instead of rounding to the nearest supported
rate.
[1] https://lore.kernel.org/r/179444135864.1126566.13931750325129218557.b4-review@b4
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117180213.88046-1-ansuelsmth@gmail.com?part=2
prev parent reply other threads:[~2026-11-17 18:15 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 18:02 [PATCH v6 0/2] clk: en7523: full clk_hw + set_rate for en7581 Christian Marangi
2026-11-17 18:02 ` [PATCH v6 1/2] clk: en7523: convert to full clk_hw implementation " Christian Marangi
2026-11-17 18:02 ` [PATCH v6 2/2] clk: en7523: add support for .set_rate " Christian Marangi
2026-11-17 18:15 ` 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-219321@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox