netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] lib8390: Replace panic() call with BUILD_BUG_ON
@ 2020-09-27 19:56 Armin Wolf
  2020-09-28 23:03 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Armin Wolf @ 2020-09-27 19:56 UTC (permalink / raw)
  To: davem; +Cc: netdev

Replace panic() call in lib8390.c with BUILD_BUG_ON()
since checking the size of struct e8390_pkt_hdr should
happen at compile-time. Also add __packed to e8390_pkt_hdr
to prevent padding.

Signed-off-by: Armin Wolf <W_Armin@gmx.de>
---
 drivers/net/ethernet/8390/8390.h    | 2 +-
 drivers/net/ethernet/8390/lib8390.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/8390/8390.h b/drivers/net/ethernet/8390/8390.h
index e52264465998..e7d6fd55f6a5 100644
--- a/drivers/net/ethernet/8390/8390.h
+++ b/drivers/net/ethernet/8390/8390.h
@@ -21,7 +21,7 @@ struct e8390_pkt_hdr {
 	unsigned char status; /* status */
 	unsigned char next;   /* pointer to next packet. */
 	unsigned short count; /* header + packet length in bytes */
-};
+} __packed;

 #ifdef CONFIG_NET_POLL_CONTROLLER
 void ei_poll(struct net_device *dev);
diff --git a/drivers/net/ethernet/8390/lib8390.c b/drivers/net/ethernet/8390/lib8390.c
index 1f48d7f6365c..deba94d2c909 100644
--- a/drivers/net/ethernet/8390/lib8390.c
+++ b/drivers/net/ethernet/8390/lib8390.c
@@ -50,6 +50,7 @@

   */

+#include <linux/build_bug.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/jiffies.h>
@@ -1018,8 +1019,7 @@ static void __NS8390_init(struct net_device *dev, int startp)
 	    ? (0x48 | ENDCFG_WTS | (ei_local->bigendian ? ENDCFG_BOS : 0))
 	    : 0x48;

-	if (sizeof(struct e8390_pkt_hdr) != 4)
-		panic("8390.c: header struct mispacked\n");
+	BUILD_BUG_ON(sizeof(struct e8390_pkt_hdr) != 4);
 	/* Follow National Semi's recommendations for initing the DP83902. */
 	ei_outb_p(E8390_NODMA+E8390_PAGE0+E8390_STOP, e8390_base+E8390_CMD); /* 0x21 */
 	ei_outb_p(endcfg, e8390_base + EN0_DCFG);	/* 0x48 or 0x49 */
--
2.20.1


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

* Re: [PATCH net-next] lib8390: Replace panic() call with BUILD_BUG_ON
  2020-09-27 19:56 [PATCH net-next] lib8390: Replace panic() call with BUILD_BUG_ON Armin Wolf
@ 2020-09-28 23:03 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2020-09-28 23:03 UTC (permalink / raw)
  To: W_Armin; +Cc: netdev

From: Armin Wolf <W_Armin@gmx.de>
Date: Sun, 27 Sep 2020 21:56:59 +0200

> Replace panic() call in lib8390.c with BUILD_BUG_ON()
> since checking the size of struct e8390_pkt_hdr should
> happen at compile-time. Also add __packed to e8390_pkt_hdr
> to prevent padding.
> 
> Signed-off-by: Armin Wolf <W_Armin@gmx.de>
> ---
>  drivers/net/ethernet/8390/8390.h    | 2 +-
>  drivers/net/ethernet/8390/lib8390.c | 4 ++--
>  2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/ethernet/8390/8390.h b/drivers/net/ethernet/8390/8390.h
> index e52264465998..e7d6fd55f6a5 100644
> --- a/drivers/net/ethernet/8390/8390.h
> +++ b/drivers/net/ethernet/8390/8390.h
> @@ -21,7 +21,7 @@ struct e8390_pkt_hdr {
>  	unsigned char status; /* status */
>  	unsigned char next;   /* pointer to next packet. */
>  	unsigned short count; /* header + packet length in bytes */
> -};
> +} __packed;

This is completely unnecessary and hurts performance on some cpus as
__packed forces the compiler to be unable to assume the alignment of
any member of said data structure.

I'm not applying this.

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

end of thread, other threads:[~2020-09-28 23:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-27 19:56 [PATCH net-next] lib8390: Replace panic() call with BUILD_BUG_ON Armin Wolf
2020-09-28 23:03 ` David Miller

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