linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH linux-next] net: smc911x: replace ternary operator with min()
@ 2022-05-16 11:56 Guo Zhengkui
  2022-05-18  0:50 ` patchwork-bot+netdevbpf
  2022-05-18  9:07 ` Geert Uytterhoeven
  0 siblings, 2 replies; 5+ messages in thread
From: Guo Zhengkui @ 2022-05-16 11:56 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Colin Ian King, Guo Zhengkui, Jiasheng Jiang,
	open list:NETWORKING DRIVERS, open list
  Cc: zhengkui_guo

Fix the following coccicheck warning:

drivers/net/ethernet/smsc/smc911x.c:483:20-22: WARNING opportunity for min()

Signed-off-by: Guo Zhengkui <guozhengkui@vivo.com>
---
 drivers/net/ethernet/smsc/smc911x.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/smsc/smc911x.c b/drivers/net/ethernet/smsc/smc911x.c
index fc9cef9dcefc..2694287770e6 100644
--- 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));
 
 	/* Send pkt via PIO or DMA */
 #ifdef SMC_USE_DMA
-- 
2.20.1


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

* Re: [PATCH linux-next] net: smc911x: replace ternary operator with min()
  2022-05-16 11:56 [PATCH linux-next] net: smc911x: replace ternary operator with min() Guo Zhengkui
@ 2022-05-18  0:50 ` patchwork-bot+netdevbpf
  2022-05-18  9:07 ` Geert Uytterhoeven
  1 sibling, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-05-18  0:50 UTC (permalink / raw)
  To: Guo Zhengkui
  Cc: davem, edumazet, kuba, pabeni, colin.king, jiasheng, netdev,
	linux-kernel, zhengkui_guo

Hello:

This patch was applied to netdev/net-next.git (master)
by Jakub Kicinski <kuba@kernel.org>:

On Mon, 16 May 2022 19:56:25 +0800 you wrote:
> Fix the following coccicheck warning:
> 
> drivers/net/ethernet/smsc/smc911x.c:483:20-22: WARNING opportunity for min()
> 
> Signed-off-by: Guo Zhengkui <guozhengkui@vivo.com>
> ---
>  drivers/net/ethernet/smsc/smc911x.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Here is the summary with links:
  - [linux-next] net: smc911x: replace ternary operator with min()
    https://git.kernel.org/netdev/net-next/c/5ff0348b7f75

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

* Re: [PATCH linux-next] net: smc911x: replace ternary operator with min()
  2022-05-16 11:56 [PATCH linux-next] net: smc911x: replace ternary operator with min() Guo Zhengkui
  2022-05-18  0:50 ` patchwork-bot+netdevbpf
@ 2022-05-18  9:07 ` Geert Uytterhoeven
  2022-05-18 15:33   ` Jakub Kicinski
  1 sibling, 1 reply; 5+ messages in thread
From: Geert Uytterhoeven @ 2022-05-18  9:07 UTC (permalink / raw)
  To: Guo Zhengkui
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Colin Ian King, Jiasheng Jiang, open list:NETWORKING DRIVERS,
	open list, zhengkui_guo

Hi Guo,

On Mon, May 16, 2022 at 10:36 PM Guo Zhengkui <guozhengkui@vivo.com> wrote:
> Fix the following coccicheck warning:
>
> drivers/net/ethernet/smsc/smc911x.c:483:20-22: WARNING opportunity for min()
>
> Signed-off-by: Guo Zhengkui <guozhengkui@vivo.com>

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".

I have sent a fix
https://lore.kernel.org/r/ca032d4122fc70d3a56a524e5944a8eff9a329e8.1652864652.git.geert+renesas@glider.be/

>
>         /* Send pkt via PIO or DMA */
>  #ifdef SMC_USE_DMA

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH linux-next] net: smc911x: replace ternary operator with min()
  2022-05-18  9:07 ` Geert Uytterhoeven
@ 2022-05-18 15:33   ` Jakub Kicinski
  2022-05-18 15:38     ` Geert Uytterhoeven
  0 siblings, 1 reply; 5+ messages in thread
From: Jakub Kicinski @ 2022-05-18 15:33 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Guo Zhengkui, David S. Miller, Eric Dumazet, Paolo Abeni,
	Colin Ian King, Jiasheng Jiang, open list:NETWORKING DRIVERS,
	open list, zhengkui_guo

On Wed, 18 May 2022 11:07:08 +0200 Geert Uytterhoeven wrote:
> On Mon, May 16, 2022 at 10:36 PM Guo Zhengkui <guozhengkui@vivo.com> wrote:
> > Fix the following coccicheck warning:
> >
> > drivers/net/ethernet/smsc/smc911x.c:483:20-22: WARNING opportunity for min()
> >
> > Signed-off-by: Guo Zhengkui <guozhengkui@vivo.com>  
> 
> 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/ca032d4122fc70d3a56a524e5944a8eff9a329e8.1652864652.git.geert+renesas@glider.be/

Thanks a lot!

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

* Re: [PATCH linux-next] net: smc911x: replace ternary operator with min()
  2022-05-18 15:33   ` Jakub Kicinski
@ 2022-05-18 15:38     ` Geert Uytterhoeven
  0 siblings, 0 replies; 5+ messages in thread
From: Geert Uytterhoeven @ 2022-05-18 15:38 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: Guo Zhengkui, David S. Miller, Eric Dumazet, Paolo Abeni,
	Colin Ian King, Jiasheng Jiang, open list:NETWORKING DRIVERS,
	open list, zhengkui_guo

Hi Jakub,

On Wed, May 18, 2022 at 5:33 PM Jakub Kicinski <kuba@kernel.org> wrote:
> On Wed, 18 May 2022 11:07:08 +0200 Geert Uytterhoeven wrote:
> > On Mon, May 16, 2022 at 10:36 PM Guo Zhengkui <guozhengkui@vivo.com> wrote:
> > > Fix the following coccicheck warning:
> > >
> > > drivers/net/ethernet/smsc/smc911x.c:483:20-22: WARNING opportunity for min()
> > >
> > > Signed-off-by: Guo Zhengkui <guozhengkui@vivo.com>
> >
> > 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?

Yes you do.

To avoid missing stuff like this in the future, my fix also includes
a change to the dummy PRINT_PKT(), so you don't have to enable
ENABLE_SMC_DEBUG_PKTS anymore to trigger the issue.

> > I have sent a fix
> > https://lore.kernel.org/r/ca032d4122fc70d3a56a524e5944a8eff9a329e8.1652864652.git.geert+renesas@glider.be/
>
> Thanks a lot!

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

end of thread, other threads:[~2022-05-18 15:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-16 11:56 [PATCH linux-next] net: smc911x: replace ternary operator with min() Guo Zhengkui
2022-05-18  0:50 ` patchwork-bot+netdevbpf
2022-05-18  9:07 ` Geert Uytterhoeven
2022-05-18 15:33   ` Jakub Kicinski
2022-05-18 15:38     ` Geert Uytterhoeven

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 NNTP newsgroup(s).