On 6/12/2024 5:52 AM, Soumyadeep Hore wrote:
Instead of using 'divide by 0' to check the struct length,
use the static_assert macro
Signed-off-by: Soumyadeep Hore <soumyadeep.h...@intel.com>
---
drivers/common/idpf/base/virtchnl2.h | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/drivers/common/idpf/base/virtchnl2.h
b/drivers/common/idpf/base/virtchnl2.h
index 1f59730297..f8b97f2e06 100644
--- a/drivers/common/idpf/base/virtchnl2.h
+++ b/drivers/common/idpf/base/virtchnl2.h
@@ -41,15 +41,12 @@
/* State Machine error - Command sequence problem */
#define VIRTCHNL2_STATUS_ERR_ESM 201
-/* These macros are used to generate compilation errors if a structure/union
- * is not exactly the correct length. It gives a divide by zero error if the
- * structure/union is not of the correct size, otherwise it creates an enum
- * that is never used.
+/* This macro is used to generate compilation errors if a structure
+ * is not exactly the correct length.
*/
-#define VIRTCHNL2_CHECK_STRUCT_LEN(n, X) enum virtchnl2_static_assert_enum_##X
\
- { virtchnl2_static_assert_##X = (n)/((sizeof(struct X) == (n)) ? 1 : 0)
}
-#define VIRTCHNL2_CHECK_UNION_LEN(n, X) enum virtchnl2_static_asset_enum_##X \
- { virtchnl2_static_assert_##X = (n)/((sizeof(union X) == (n)) ? 1 : 0) }
+#define VIRTCHNL2_CHECK_STRUCT_LEN(n, X) \
+ static_assert((n) == sizeof(struct X), \
+ "Structure length does not match with the expected value")
It appears that the patch also removed CHECK_UNION_LEN macro (presumably
because it is unused and no longer needed). Would be good to add this to
commit message.
/* New major set of opcodes introduced and so leaving room for
* old misc opcodes to be added in future. Also these opcodes may only
--
Thanks,
Anatoly