From: sashiko-bot@kernel.org
To: Prabhakar <prabhakar.csengg@gmail.com>
Cc: wsa+renesas@sang-engineering.com, devicetree@vger.kernel.org,
krzk+dt@kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH 1/4] clk: renesas: rzv2h-cpg: Use per-SoC PLL reference frequency for calculations
Date: Wed, 13 May 2026 00:02:41 +0000 [thread overview]
Message-ID: <20260513000241.D0482C2BCB0@smtp.kernel.org> (raw)
In-Reply-To: <20260511191910.1945705-2-prabhakar.mahadev-lad.rj@bp.renesas.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] On 32-bit architectures, the calculation `output += p.k * input_fref;` performs an incorrect zero-extended addition when `p.k` is negative, corrupting the PLL calculation.
- [Low] The newly added `input_fref` field is documented as being in MHz, but the code initializes and expects it in Hz.
--
commit a6beaf951f9f846b0e14a16acf1b5de978587208
Author: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
clk: renesas: rzv2h-cpg: Use per-SoC PLL reference frequency for calculations
This commit modifies the rzv2h-cpg driver to use a per-SoC PLL reference
input frequency instead of a hardcoded 24MHz constant. It adds an
input_fref field to struct rzv2h_pll_limits and updates the PLL parameter
calculations to use it.
> diff --git a/drivers/clk/renesas/rzv2h-cpg.c b/drivers/clk/renesas/rzv2h-cpg.c
> index f6c47fb89bca5..cd990dc10fa96 100644
> --- a/drivers/clk/renesas/rzv2h-cpg.c
> +++ b/drivers/clk/renesas/rzv2h-cpg.c
[ ... ]
> @@ -330,9 +331,9 @@ bool rzv2h_get_pll_pars(const struct rzv2h_pll_limits *limits,
> continue;
>
> /* PLL_M component of (output * 65536 * PLL_P) */
> - output = mul_u32_u32(p.m * 65536, RZ_V2H_OSC_CLK_IN_MEGA);
> + output = mul_u32_u32(p.m * 65536, input_fref);
> /* PLL_K component of (output * 65536 * PLL_P) */
> - output += p.k * RZ_V2H_OSC_CLK_IN_MEGA;
> + output += p.k * input_fref;
On 32-bit architectures, does this calculation perform an incorrect
zero-extended addition when p.k is negative?
Since p.k is a signed 16-bit integer (s16) and input_fref is unsigned long
(32-bit on ARM32 architectures), negative values of p.k might get promoted to
a 32-bit unsigned integer before multiplication.
This would yield a 32-bit unsigned result. When added to the u64 output
variable, this result would be zero-extended to 64 bits instead of being
sign-extended, adding a large positive value rather than subtracting the
frequency offset.
While this existed prior to this patch, replacing the RZ_V2H_OSC_CLK_IN_MEGA
constant with input_fref maintains the same integer promotion behavior.
Could p.k be explicitly cast to a signed 64-bit integer here?
> /* Make it in mHz */
> output *= MILLI;
> output = DIV_U64_ROUND_CLOSEST(output, 65536 * p.p * divider);
> diff --git a/include/linux/clk/renesas.h b/include/linux/clk/renesas.h
> index c360df9fa735c..402bfeaffdfc4 100644
> --- a/include/linux/clk/renesas.h
> +++ b/include/linux/clk/renesas.h
> @@ -53,6 +53,8 @@ static inline void rzg2l_cpg_dsi_div_set_divider(u8 divider, int target) { }
> * various parameters used to configure a PLL. These limits ensure
> * the PLL operates within valid and stable ranges.
> *
> + * @input_fref: Reference input frequency to the PLL (in MHz)
This isn't a bug, but is the documentation correct about the unit being in MHz?
Looking later in the diff, the field appears to be initialized in Hz:
[ ... ]
> @@ -156,6 +160,7 @@ struct rzv2h_pll_div_pars {
>
> #define RZV2H_CPG_PLL_DSI_LIMITS(name) \
> static const struct rzv2h_pll_limits (name) = { \
> + .input_fref = 24 * MEGA, \
> .fout = { .min = 25 * MEGA, .max = 375 * MEGA }, \
It seems the field is initialized and expected in Hz (24,000,000 Hz) rather
than MHz. Should the documentation be updated to state (in Hz) to match the
implementation?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260511191910.1945705-1-prabhakar.mahadev-lad.rj@bp.renesas.com?part=1
next prev parent reply other threads:[~2026-05-13 0:02 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-11 19:19 [PATCH 0/4] Add PLL3 and LCDC_CLKD support for RZ/T2H and RZ/N2H Prabhakar
2026-05-11 19:19 ` [PATCH 1/4] clk: renesas: rzv2h-cpg: Use per-SoC PLL reference frequency for calculations Prabhakar
2026-05-13 0:02 ` sashiko-bot [this message]
2026-05-11 19:19 ` [PATCH 2/4] clk: renesas: cpg-mssr: Add table-driven MSTP dummy-read delay for LCDC on RZ/T2H Prabhakar
2026-05-13 0:18 ` sashiko-bot
2026-05-11 19:19 ` [PATCH 3/4] dt-bindings: clock: renesas,r9a09g077/87: Add LCDC_CLKD clock ID Prabhakar
2026-05-12 17:16 ` Conor Dooley
2026-05-11 19:19 ` [PATCH 4/4] clk: renesas: r9a09g077: Add LCDC and PLL3 clock support for RZ/T2H display pipeline Prabhakar
2026-05-13 0:56 ` sashiko-bot
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=20260513000241.D0482C2BCB0@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=krzk+dt@kernel.org \
--cc=prabhakar.csengg@gmail.com \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=wsa+renesas@sang-engineering.com \
/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