public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] MIPS: ralink: Use min() to fix Coccinelle warning
@ 2024-04-09 15:35 Thorsten Blum
  2024-04-10 10:43 ` Sergio Paracuellos
  0 siblings, 1 reply; 3+ messages in thread
From: Thorsten Blum @ 2024-04-09 15:35 UTC (permalink / raw)
  To: John Crispin, Sergio Paracuellos, Thomas Bogendoerfer
  Cc: linux-mips, linux-kernel, Thorsten Blum

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)
 {
-	if (rt->timer_freq < divisor)
-		rt->timer_div = rt->timer_freq;
-	else
-		rt->timer_div = divisor;
-
+	rt->timer_div = min(rt->timer_freq, divisor);
 	rt_timer_w32(rt, TIMER_REG_TMR0LOAD, rt->timer_freq / rt->timer_div);
 
 	return 0;
-- 
2.44.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] MIPS: ralink: Use min() to fix Coccinelle warning
  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
  0 siblings, 1 reply; 3+ messages in thread
From: Sergio Paracuellos @ 2024-04-10 10:43 UTC (permalink / raw)
  To: Thorsten Blum; +Cc: John Crispin, Thomas Bogendoerfer, linux-mips, linux-kernel

Hi Thorsten,

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)
>  {
> -       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.

Best regards,
    Sergio Paracuellos

>         rt_timer_w32(rt, TIMER_REG_TMR0LOAD, rt->timer_freq / rt->timer_div);
>
>         return 0;
> --
> 2.44.0
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: [PATCH] MIPS: ralink: Use min() to fix Coccinelle warning
  2024-04-10 10:43 ` Sergio Paracuellos
@ 2024-04-15  8:42   ` David Laight
  0 siblings, 0 replies; 3+ messages in thread
From: David Laight @ 2024-04-15  8:42 UTC (permalink / raw)
  To: 'Sergio Paracuellos', Thorsten Blum
  Cc: John Crispin, Thomas Bogendoerfer, linux-mips@vger.kernel.org,
	linux-kernel@vger.kernel.org

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)

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-04-15  8:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox