Linux clock framework development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Joey Lu" <a0987203069@gmail.com>
Cc: linux-clk@vger.kernel.org
Subject: Re: [PATCH 2/3] clk: nuvoton: ma35d1: use the generic divider for the ADC clock
Date: Mon, 12 Oct 2026 06:38:01 +0000	[thread overview]
Message-ID: <sashiko-outbox-167746@kernel.org> (raw)
In-Reply-To: <20261012063020.3331443-3-a0987203069@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] clk: core: underflow and incorrect rounding for CLK_DIVIDER_EVEN_INTEGERS without a table
--

commit c5f5b7cbd52c161c065e9dedca522e878812d14a
Author: Joey Lu <a0987203069@gmail.com>

clk: nuvoton: ma35d1: use the generic divider for the ADC clock

This patch migrates the ADC clock divider in the Nuvoton MA35D1 driver to use
the generic divider with CLK_DIVIDER_EVEN_INTEGERS and
CLK_DIVIDER_ROUND_CLOSEST. It replaces a custom implementation and drops an
out-of-range bitmask that was previously OR'd into the register.

> diff --git a/drivers/clk/nuvoton/clk-ma35d1.c b/drivers/clk/nuvoton/clk-ma35d1.c
> index 3102c65bfe9a0..94a3e904202b2 100644
> --- a/drivers/clk/nuvoton/clk-ma35d1.c
> +++ b/drivers/clk/nuvoton/clk-ma35d1.c
> @@ -1017,10 +1017,11 @@ static int ma35d1_clocks_probe(struct platform_device *pdev)
>  	hws[QEI2_GATE] = ma35d1_clk_gate(dev, "qei2_gate", "pclk1",
>  					 clk_base + REG_CLK_APBCLK2, 14);
>  
> -	hws[ADC_DIV] = ma35d1_reg_adc_clkdiv(dev, "adc_div", hws[PCLK0],
> -					     &ma35d1_lock, 0,
> -					     clk_base + REG_CLK_CLKDIV4,
> -					     4, 17, 0x1ffff);
> +	hws[ADC_DIV] = devm_clk_hw_register_divider_parent_hw(dev, "adc_div", hws[PCLK0], 0,
> +							      clk_base + REG_CLK_CLKDIV4, 4, 17,
> +							      CLK_DIVIDER_EVEN_INTEGERS |
> +							      CLK_DIVIDER_ROUND_CLOSEST,
> +							      &ma35d1_lock);

[Severity: High]
Does migrating to the table-less generic CLK_DIVIDER_EVEN_INTEGERS expose this
clock to an underflow bug?

If the clock framework computes an odd divisor (for example, if a requested
rate yields div=1 or div=3), the generic _get_val function in
drivers/clk/clk-divider.c evaluates this as:

    if (flags & CLK_DIVIDER_EVEN_INTEGERS)
        return (div >> 1) - 1;

If div is 1, this results in (1 >> 1) - 1 = -1. Because this is evaluated as an
unsigned integer, it underflows to the maximum possible value, programming the
hardware to its maximum division instead of the desired rate. If div is 3, it
computes 0, configuring the hardware for /2 instead of /4.

Could this lead to a misconfiguration of the ADC clock? Would it be safer to
explicitly provide a clk_div_table to restrict the valid even divisors and
prevent this framework math issue?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261012063020.3331443-1-a0987203069@gmail.com?part=2

  reply	other threads:[~2026-10-12  6:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-12  6:30 [PATCH 0/3] clk: nuvoton: ma35d1: fix parent lookup and use the generic ADC divider Joey Lu
2026-10-12  6:30 ` [PATCH 1/3] clk: nuvoton: ma35d1: fix parent lookup for clk_parent_data entries Joey Lu
2026-10-12  6:30 ` [PATCH 2/3] clk: nuvoton: ma35d1: use the generic divider for the ADC clock Joey Lu
2026-10-12  6:38   ` sashiko-bot [this message]
2026-10-12  6:30 ` [PATCH 3/3] clk: nuvoton: ma35d1: remove the unused ADC divider driver Joey Lu

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-167746@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=a0987203069@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