Subject: Re: [PATCH linux-next] net: smc911x: replace ternary operator with min()

From: Jakub Kicinski <[email-masked]>
Date: Wed, 18 May 2022 08:33:44 -0700

On Wed, 18 May 2022 11:07:08 +0200 Geert Uytterhoeven wrote:
> On Mon, May 16, 2022 at 10:36 PM Guo Zhengkui <[email-masked]> wrote:
> > Fix the following coccicheck warning:
> >
> > drivers/net/ethernet/smsc/smc911x.c:483:20-22: WARNING opportunity for min()
> >
> > Signed-off-by: Guo Zhengkui <[email-masked]>  
> 
> Thanks for your patch, which is now commit 5ff0348b7f755aac ("net:
> smc911x: replace ternary operator with min()") in net-next/master.
> 
> > --- a/drivers/net/ethernet/smsc/smc911x.c
> > +++ b/drivers/net/ethernet/smsc/smc911x.c
> > @@ -480,7 +480,7 @@ static void smc911x_hardware_send_pkt(struct net_device *dev)
> >         SMC_SET_TX_FIFO(lp, cmdB);
> >
> >         DBG(SMC_DEBUG_PKTS, dev, "Transmitted packet\n");
> > -       PRINT_PKT(buf, len <= 64 ? len : 64);
> > +       PRINT_PKT(buf, min(len, 64));  
> 
> Unfortunately you forgot to test-compile this with
> ENABLE_SMC_DEBUG_PKTS=1, which triggers:
> 
>         drivers/net/ethernet/smsc/smc911x.c: In function
> ‘smc911x_hardware_send_pkt’:
>         include/linux/minmax.h:20:28: error: comparison of distinct
> pointer types lacks a cast [-Werror]
>            20 |  (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
>               |                            ^~
>         drivers/net/ethernet/smsc/smc911x.c:483:17: note: in expansion
> of macro ‘min’
>           483 |  PRINT_PKT(buf, min(len, 64));
> 
> "len" is "unsigned int", while "64" is "(signed) int".

Ah, damn. I did double check that the build test actually compiles
smc911x.o 'cause this patch looked suspicious. Didn't realize that
more than allmodconfig is needed to trigger this :/

How do you enable ENABLE_SMC_DEBUG_PKTS? You edit the source?

> I have sent a fix
> https://lore.kernel.org/r/ca032[email-masked]/

Thanks a lot!