All of lore.kernel.org
 help / color / mirror / Atom feed
From: Cristian Marussi <cristian.marussi@arm.com>
To: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Cristian Marussi <cristian.marussi@arm.com>,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, arm-scmi@vger.kernel.org,
	linux-clk@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
	sudeep.holla@arm.com, philip.radford@arm.com,
	james.quinlan@broadcom.com, f.fainelli@gmail.com,
	vincent.guittot@linaro.org, etienne.carriere@foss.st.com,
	peng.fan@oss.nxp.com, michal.simek@amd.com,
	dan.carpenter@linaro.org, geert+renesas@glider.be,
	kuninori.morimoto.gx@renesas.com, marek.vasut+renesas@gmail.com,
	Michael Turquette <mturquette@baylibre.com>,
	Stephen Boyd <sboyd@kernel.org>
Subject: Re: [PATCH v2 01/13] clk: scmi: Fix clock rate rounding
Date: Wed, 11 Mar 2026 18:33:15 +0000	[thread overview]
Message-ID: <abG1a_E_7gBmc3ec@pluto> (raw)
In-Reply-To: <CAMuHMdX5T-7ERcjEK_=z7joEftC2cMLqDkyy8iO65U21S-umng@mail.gmail.com>

On Wed, Mar 11, 2026 at 12:30:34PM +0100, Geert Uytterhoeven wrote:
> Hi Cristian,
> 
> On Tue, 10 Mar 2026 at 19:40, Cristian Marussi <cristian.marussi@arm.com> wrote:
> > While the do_div() helper used for rounding expects its divisor argument
> > to be a 32bits quantity, the currently provided divisor parameter is a
> > 64bit value that, as a consequence, is silently truncated and a possible
> > source of bugs.
> >
> > Fix by using the proper div64_ul helper.
> >
> > Cc: Michael Turquette <mturquette@baylibre.com>
> > Cc: Stephen Boyd <sboyd@kernel.org>
> > Cc: linux-clk@vger.kernel.org
> > Fixes: 7a8655e19bdb ("clk: scmi: Fix the rounding of clock rate")
> > Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
> 
> Thanks for your patch!
> 
> > --- a/drivers/clk/clk-scmi.c
> > +++ b/drivers/clk/clk-scmi.c
> 
> > @@ -83,7 +83,7 @@ static int scmi_clk_determine_rate(struct clk_hw *hw,
> >
> >         ftmp = req->rate - fmin;
> >         ftmp += clk->info->range.step_size - 1; /* to round up */
> > -       do_div(ftmp, clk->info->range.step_size);
> > +       ftmp = div64_ul(ftmp, clk->info->range.step_size);
> 
> include/linux/math64.h has:
> 
>     #if BITS_PER_LONG == 64
>     #define div64_ul(x, y)   div64_u64((x), (y))
>     #elif BITS_PER_LONG == 32
>     #define div64_ul(x, y)   div_u64((x), (y))
>     #endif
> 
> I.e. div64_ul() is meant for the case where the divisor is unsigned
> long.  Hence div64_ul() may still truncate step_size on 32-bit
> platforms, and thus should use div64_u64() unconditionally.
> 

Ah...my bad, I missed that...

> I am aware clock rates are "unsigned long" on 32-bit platforms, and
> thus cannot support rates that do not fit in a 32-bit value.
> If that is the reason you are using div64_ul(), it should be documented
> properly.  And probably the SCMI core code should reject any rate values
> (incl. min, max, step) that do not fit in unsigned long, as such clocks
> cannot be used on 32-bit platforms.

As per the SCMI spec Clock rates are reported as 64bit, so I suppose
that, yes I will have to add the checks you mentioned to avoid trying to
fit a reported clock rate where the upper 32bits are not zero into an
unsigned long on a 32bit machine...

Seems like there will be a V3 (together with your other reports..)

Thanks for your reviews !

Cristian

  reply	other threads:[~2026-03-11 18:33 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-10 18:40 [PATCH v2 00/13] SCMI Clock rates discovery rework Cristian Marussi
2026-03-10 18:40 ` [PATCH v2 01/13] clk: scmi: Fix clock rate rounding Cristian Marussi
2026-03-11 11:30   ` Geert Uytterhoeven
2026-03-11 18:33     ` Cristian Marussi [this message]
2026-03-10 18:40 ` [PATCH v2 02/13] firmware: arm_scmi: Add clock determine_rate operation Cristian Marussi
2026-03-10 18:40 ` [PATCH v2 03/13] clk: scmi: Use new determine_rate clock operation Cristian Marussi
2026-03-10 18:40 ` [PATCH v2 04/13] firmware: arm_scmi: Simplify clock rates exposed interface Cristian Marussi
2026-03-17  7:38   ` Peng Fan
2026-03-10 18:40 ` [PATCH v2 05/13] clk: scmi: Use new simplified per-clock rate properties Cristian Marussi
2026-03-18 15:29   ` Sudeep Holla
2026-03-10 18:40 ` [PATCH v2 06/13] firmware: arm_scmi: Drop unused clock rate interfaces Cristian Marussi
2026-03-10 18:40 ` [PATCH v2 07/13] firmware: arm_scmi: Make clock rates allocation dynamic Cristian Marussi
2026-03-17  7:28   ` Peng Fan
2026-03-10 18:40 ` [PATCH v2 08/13] firmware: arm_scmi: Harden clock protocol initialization Cristian Marussi
2026-03-11 16:59   ` Geert Uytterhoeven
2026-03-11 18:45     ` Cristian Marussi
2026-03-12 15:33       ` Sudeep Holla
2026-03-12 16:36         ` Cristian Marussi
2026-03-16 15:50           ` Geert Uytterhoeven
2026-03-16 16:14             ` Cristian Marussi
2026-03-16 16:35               ` Geert Uytterhoeven
2026-03-16 16:38                 ` Cristian Marussi
2026-03-24 13:43                 ` Geert Uytterhoeven
2026-03-25 11:02   ` Marek Szyprowski
2026-03-25 12:27     ` Cristian Marussi
2026-03-26  8:55       ` Alexander Stein
2026-03-26 10:16         ` Sudeep Holla
2026-03-30  5:54         ` Cristian Marussi
2026-04-24 12:07   ` Nicolas Frattaroli
2026-04-24 13:32     ` Cristian Marussi
2026-04-24 13:55       ` Geert Uytterhoeven
2026-04-26 23:10         ` Cristian Marussi
2026-03-10 18:40 ` [PATCH v2 09/13] firmware: arm_scmi: Harden clock parents discovery Cristian Marussi
2026-03-17  7:29   ` Peng Fan
2026-03-10 18:40 ` [PATCH v2 10/13] firmware: arm_scmi: Refactor iterators internal allocation Cristian Marussi
2026-03-17  7:35   ` Peng Fan
2026-03-10 18:40 ` [PATCH v2 11/13] firmware: arm_scmi: Add bound iterators support Cristian Marussi
2026-03-17  7:44   ` Peng Fan
2026-03-17  9:22     ` Cristian Marussi
2026-03-10 18:40 ` [PATCH v2 12/13] firmware: arm_scmi: Use bound iterators to minimize discovered rates Cristian Marussi
2026-03-10 18:40 ` [PATCH v2 13/13] firmware: arm_scmi: Introduce all_rates_get clock operation Cristian Marussi
2026-03-17  7:34   ` Peng Fan
2026-03-17  8:20 ` [PATCH v2 00/13] SCMI Clock rates discovery rework Geert Uytterhoeven

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=abG1a_E_7gBmc3ec@pluto \
    --to=cristian.marussi@arm.com \
    --cc=arm-scmi@vger.kernel.org \
    --cc=dan.carpenter@linaro.org \
    --cc=etienne.carriere@foss.st.com \
    --cc=f.fainelli@gmail.com \
    --cc=geert+renesas@glider.be \
    --cc=geert@linux-m68k.org \
    --cc=james.quinlan@broadcom.com \
    --cc=kuninori.morimoto.gx@renesas.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=marek.vasut+renesas@gmail.com \
    --cc=michal.simek@amd.com \
    --cc=mturquette@baylibre.com \
    --cc=peng.fan@oss.nxp.com \
    --cc=philip.radford@arm.com \
    --cc=sboyd@kernel.org \
    --cc=sudeep.holla@arm.com \
    --cc=vincent.guittot@linaro.org \
    /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.