Linux clock framework development
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Geert Uytterhoeven <geert@linux-m68k.org>,
	David Laight <David.Laight@aculab.com>
Cc: Biju Das <biju.das.jz@bp.renesas.com>,
	Michael Turquette <mturquette@baylibre.com>,
	Stephen Boyd <sboyd@kernel.org>,
	linux-clk@vger.kernel.org,
	Prabhakar Mahadev Lad <prabhakar.mahadev-lad.rj@bp.renesas.com>,
	Biju Das <biju.das.au@gmail.com>,
	linux-renesas-soc@vger.kernel.org
Subject: Re: [PATCH] clk: vc3: Use clamp() instead of min_t()
Date: Thu, 5 Oct 2023 12:07:04 +0300	[thread overview]
Message-ID: <ZR58uDLC99WUwkr2@smile.fi.intel.com> (raw)
In-Reply-To: <CAMuHMdXageyQyqaGXJbmmpcKyjoO-VHWGzGk_WJ1YsAne+iiSw@mail.gmail.com>

+David

On Wed, Oct 04, 2023 at 09:50:09AM +0200, Geert Uytterhoeven wrote:
> On Wed, Oct 4, 2023 at 8:42 AM Biju Das <biju.das.jz@bp.renesas.com> wrote:
> > The min_t() is often used as a shortcut for clamp(). Secondly, the
> > BIT(16) - 1 is specifically used as the value related to the bits in the
> > hardware and u16 is a software type that coincidentally has the same
> > maximum as the above mentioned bitfield.
> 
> Technically it is two byte-sized registers forming a 16-bit field ;-)
> 
> > Replace min_t()->clamp() in vc3_pll_round_rate().
> >
> > Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
> > ---
> >  drivers/clk/clk-versaclock3.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/clk/clk-versaclock3.c b/drivers/clk/clk-versaclock3.c
> > index 3d7de355f8f6..50772f61096f 100644
> > --- a/drivers/clk/clk-versaclock3.c
> > +++ b/drivers/clk/clk-versaclock3.c
> > @@ -402,7 +402,7 @@ static long vc3_pll_round_rate(struct clk_hw *hw, unsigned long rate,
> >                 div_frc = rate % *parent_rate;
> >                 div_frc *= BIT(16) - 1;
> >
> > -               vc3->div_frc = min_t(u64, div64_ul(div_frc, *parent_rate), U16_MAX);
> > +               vc3->div_frc = clamp(div64_ul(div_frc, *parent_rate), 0, BIT(16) - 1);
> 
> I'm not sure this is actually an improvement...

That's what Linus actually suggested to do.

> While I agree "BIT(16) - 1" matches the expression two lines above,
> I find it harder to read.
> Perhaps introducing a VC3_PLL2_FB_FRC_DIV_MAX definition may help.

Either way, but U16_MAX is really semantically wrong here.

> BTW, if the hardware wouldn't use two byte-sized registers, but a real
> bitifield, one could use FIELD_GET(mask, mask) instead.

> Second, clamping an unsigned value to zero is futile, and opens us to
> warnings like:
> 
>     warning: comparison of unsigned expression in ‘>= 0’ is always
> true [-Wtype-limits]

David, is your series fix this as well?

> >                 rate = (*parent_rate *
> >                         (vc3->div_int * VC3_2_POW_16 + vc3->div_frc) / VC3_2_POW_16);
> >         } else {

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2023-10-05 14:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-04  6:42 [PATCH] clk: vc3: Use clamp() instead of min_t() Biju Das
2023-10-04  7:50 ` Geert Uytterhoeven
2023-10-05  9:07   ` Andy Shevchenko [this message]
2023-10-05  9:40     ` David Laight

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=ZR58uDLC99WUwkr2@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=David.Laight@aculab.com \
    --cc=biju.das.au@gmail.com \
    --cc=biju.das.jz@bp.renesas.com \
    --cc=geert@linux-m68k.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox