DPDK patches and discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: "Stephen Hemminger" <stephen@networkplumber.org>,
	"Morten Brørup" <mb@smartsharesystems.com>
Subject: [PATCH] common/sfc: replace out of bounds condition with static_assert
Date: Sun, 11 Feb 2024 14:24:15 -0800	[thread overview]
Message-ID: <20240211222543.116113-1-stephen@networkplumber.org> (raw)
In-Reply-To: <20240118201843.189978-1-stephen@networkplumber.org>

The sfc base code had its own definition of static assertions
using the out of bound array access hack.  This method does
not force the condition to be const and can have false negatives.
Better to use static_assert() like other places in DPDK.

Fixes: f67e4719147d ("net/sfc/base: fix coding style")
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
Reviewed-by: Morten Brørup <mb@smartsharesystems.com>
---
v3 - change the macro to workaround issues with older clang.
     Compiles on Debian testing with Gcc and Clang.

 drivers/common/sfc_efx/base/efx.h | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/common/sfc_efx/base/efx.h b/drivers/common/sfc_efx/base/efx.h
index 3312c2fa8f81..d2fa6bf49396 100644
--- a/drivers/common/sfc_efx/base/efx.h
+++ b/drivers/common/sfc_efx/base/efx.h
@@ -7,6 +7,8 @@
 #ifndef	_SYS_EFX_H
 #define	_SYS_EFX_H
 
+#include <assert.h>
+
 #include "efx_annote.h"
 #include "efsys.h"
 #include "efx_types.h"
@@ -17,8 +19,14 @@
 extern "C" {
 #endif
 
-#define	EFX_STATIC_ASSERT(_cond)		\
-	((void)sizeof (char[(_cond) ? 1 : -1]))
+/*
+ * Triggers an error at compilation time if the condition is false.
+ *
+ * The  { } exists to workaround a bug in clang (#55821)
+ * where it would not handle _Static_assert in a switch case.
+ */
+#define	EFX_STATIC_ASSERT(_cond) \
+	{ static_assert((_cond), #_cond); }
 
 #define	EFX_ARRAY_SIZE(_array)			\
 	(sizeof (_array) / sizeof ((_array)[0]))
-- 
2.43.0


  parent reply	other threads:[~2024-02-11 22:25 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-18 20:18 Stephen Hemminger
2024-01-18 23:05 ` Morten Brørup
2024-02-13  7:47   ` Andrew Rybchenko
2024-01-19 22:13 ` [PATCH v2] " Stephen Hemminger
2024-01-20  7:53   ` Morten Brørup
2024-02-07 19:10   ` Ferruh Yigit
2024-02-07 22:34     ` Stephen Hemminger
2024-02-07 22:36     ` Stephen Hemminger
2024-02-07 23:30       ` Ferruh Yigit
2024-02-11 17:41         ` Stephen Hemminger
2024-02-11 22:24 ` Stephen Hemminger [this message]
2024-02-12  5:48 ` [PATCH v4] " Stephen Hemminger
2024-02-12 12:09   ` Ferruh Yigit
2024-02-13  9:39   ` Ferruh Yigit

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=20240211222543.116113-1-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    --cc=mb@smartsharesystems.com \
    /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 NNTP newsgroup(s).