Linux-MIPS Archive mirror
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: 'Sergio Paracuellos' <sergio.paracuellos@gmail.com>,
	Thorsten Blum <thorsten.blum@toblux.com>
Cc: John Crispin <john@phrozen.org>,
	Thomas Bogendoerfer <tsbogend@alpha.franken.de>,
	"linux-mips@vger.kernel.org" <linux-mips@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH] MIPS: ralink: Use min() to fix Coccinelle warning
Date: Mon, 15 Apr 2024 08:42:13 +0000	[thread overview]
Message-ID: <e6ff2dbaf23d4d66bd8ea1bf1b87a26c@AcuMS.aculab.com> (raw)
In-Reply-To: <CAMhs-H8EByNhBAkhDvtHL_ZUgLnMFQcR1zeYhaKQSg-13uFnVQ@mail.gmail.com>

From: Sergio Paracuellos
> Sent: 10 April 2024 11:44
> On Tue, Apr 9, 2024 at 5:36 PM Thorsten Blum <thorsten.blum@toblux.com> wrote:
> >
> > Fixes the following Coccinelle/coccicheck warning reported by
> > minmax.cocci:
> >
> >         WARNING opportunity for min()
> >
> > Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
> > ---
> >  arch/mips/ralink/timer.c | 6 +-----
> >  1 file changed, 1 insertion(+), 5 deletions(-)
> >
> > diff --git a/arch/mips/ralink/timer.c b/arch/mips/ralink/timer.c
> > index 54094f6e033e..d271ac98312a 100644
> > --- a/arch/mips/ralink/timer.c
> > +++ b/arch/mips/ralink/timer.c
> > @@ -75,11 +75,7 @@ static int rt_timer_request(struct rt_timer *rt)
> >
> >  static int rt_timer_config(struct rt_timer *rt, unsigned long divisor)

I doubt 'unsigned long' is the best type there.
It should probably be u32 - so still 32bit on 64bit systems.

> >  {
> > -       if (rt->timer_freq < divisor)
> > -               rt->timer_div = rt->timer_freq;
> > -       else
> > -               rt->timer_div = divisor;
> > -
> > +       rt->timer_div = min(rt->timer_freq, divisor);
> 
> I do find the original code more readable.

Probably because it isn't really a 'min()' but avoiding a division
generating a quotient of zero.
It might be better to explicitly avoid the x/x below.

	David
> 
> Best regards,
>     Sergio Paracuellos
> 
> >         rt_timer_w32(rt, TIMER_REG_TMR0LOAD, rt->timer_freq / rt->timer_div);
> >
> >         return 0;
> > --
> > 2.44.0
> >

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

      reply	other threads:[~2024-04-15  8:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-09 15:35 [PATCH] MIPS: ralink: Use min() to fix Coccinelle warning Thorsten Blum
2024-04-10 10:43 ` Sergio Paracuellos
2024-04-15  8:42   ` David Laight [this message]

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=e6ff2dbaf23d4d66bd8ea1bf1b87a26c@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=john@phrozen.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=sergio.paracuellos@gmail.com \
    --cc=thorsten.blum@toblux.com \
    --cc=tsbogend@alpha.franken.de \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).