From: Andy Shevchenko <andy@black.fi.intel.com>
To: Biju Das <biju.das.jz@bp.renesas.com>
Cc: Michael Turquette <mturquette@baylibre.com>,
Stephen Boyd <sboyd@kernel.org>,
linux-clk@vger.kernel.org,
Geert Uytterhoeven <geert+renesas@glider.be>,
Prabhakar Mahadev Lad <prabhakar.mahadev-lad.rj@bp.renesas.com>,
linux-renesas-soc@vger.kernel.org,
Julia Lawall <julia.lawall@inria.fr>
Subject: Re: [PATCH v5 2/4] clk: vc3: Fix 64 by 64 division
Date: Wed, 13 Sep 2023 00:11:00 +0300 [thread overview]
Message-ID: <ZQDT5Indg/md+KXt@black.fi.intel.com> (raw)
In-Reply-To: <20230824104812.147775-3-biju.das.jz@bp.renesas.com>
On Thu, Aug 24, 2023 at 11:48:10AM +0100, Biju Das wrote:
> Fix the below cocci warnings by replacing do_div()->div64_ul() and
> bound the result with a max value of U16_MAX.
>
> cocci warnings:
> drivers/clk/clk-versaclock3.c:404:2-8: WARNING: do_div() does a
> 64-by-32 division, please consider using div64_ul instead.
It's nice, but there is a room for a couple of improvements. See below.
...
> /* Determine best fractional part, which is 16 bit wide */
> div_frc = rate % *parent_rate;
> div_frc *= BIT(16) - 1;
> - do_div(div_frc, *parent_rate);
>
> - vc3->div_frc = (u32)div_frc;
> + vc3->div_frc = min_t(u64, div64_ul(div_frc, *parent_rate), U16_MAX);
First of all, as Linus Torvalds pointed out [1] min_t() is often used as
a shortcut for clamp(). Second one, the BIT(16) - 1 is specifically used
as the value related to the bits in the hardware and u16 is a software
type that coincidentially has the same maximum as the above mentioned
bitfield.
That said, here this should be clamped to the [0 .. BIT(16) - 1] range.
Since the patch is applied perhaps you can cook a followup.
To everyone the message is simple: try to not use typed version of min()
and clamp() at all.
> rate = (*parent_rate *
> - (vc3->div_int * VC3_2_POW_16 + div_frc) / VC3_2_POW_16);
> + (vc3->div_int * VC3_2_POW_16 + vc3->div_frc) / VC3_2_POW_16);
[1]: https://lore.kernel.org/lkml/CAHk-=whwEAc22wm8h9FESPB5X+P4bLDgv0erBQMa1buTNQW7tA@mail.gmail.com/
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2023-09-12 21:11 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-24 10:48 [PATCH v5 0/4] Fix Versa3 clock mapping Biju Das
2023-08-24 10:48 ` [PATCH v5 1/4] dt-bindings: clock: versaclock3: Add description for #clock-cells property Biju Das
2023-09-07 7:14 ` Geert Uytterhoeven
2023-09-11 20:31 ` Stephen Boyd
2023-08-24 10:48 ` [PATCH v5 2/4] clk: vc3: Fix 64 by 64 division Biju Das
2023-09-11 20:32 ` Stephen Boyd
2023-09-12 21:11 ` Andy Shevchenko [this message]
2023-09-13 7:22 ` Biju Das
2023-08-24 10:48 ` [PATCH v5 3/4] clk: vc3: Fix output clock mapping Biju Das
2023-09-11 20:32 ` Stephen Boyd
2023-08-24 10:48 ` [PATCH v5 4/4] clk: vc3: Make vc3_clk_mux enum values based on vc3_clk enum values Biju Das
2023-09-07 7:15 ` Geert Uytterhoeven
2023-09-11 20:32 ` Stephen Boyd
2023-09-06 10:05 ` [PATCH v5 0/4] Fix Versa3 clock mapping Biju Das
[not found] ` <991ce762a3a8fec7ecc832f95f023193.sboyd@kernel.org>
2023-09-07 7:20 ` 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=ZQDT5Indg/md+KXt@black.fi.intel.com \
--to=andy@black.fi.intel.com \
--cc=biju.das.jz@bp.renesas.com \
--cc=geert+renesas@glider.be \
--cc=julia.lawall@inria.fr \
--cc=linux-clk@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=mturquette@baylibre.com \
--cc=prabhakar.mahadev-lad.rj@bp.renesas.com \
--cc=sboyd@kernel.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.