Skip to content

Commit 0718e56

Browse files
hramamu1Jeff Kirsher
authored andcommitted
virtchnl: Add a macro to check the size of a union
This patch adds a macro to check if the size of a union is correct. It throws a divide by zero error if the union is not of the correct size. Signed-off-by: Harshitha Ramamurthy <[email protected]> Tested-by: Andrew Bowers <[email protected]> Signed-off-by: Jeff Kirsher <[email protected]>
1 parent 0c483bd commit 0718e56

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

include/linux/avf/virtchnl.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,15 @@ enum virtchnl_ops {
140140
VIRTCHNL_OP_DISABLE_CHANNELS = 31,
141141
};
142142

143-
/* This macro is used to generate a compilation error if a structure
143+
/* These macros are used to generate compilation errors if a structure/union
144144
* is not exactly the correct length. It gives a divide by zero error if the
145-
* structure is not of the correct size, otherwise it creates an enum that is
146-
* never used.
145+
* structure/union is not of the correct size, otherwise it creates an enum
146+
* that is never used.
147147
*/
148148
#define VIRTCHNL_CHECK_STRUCT_LEN(n, X) enum virtchnl_static_assert_enum_##X \
149149
{ virtchnl_static_assert_##X = (n)/((sizeof(struct X) == (n)) ? 1 : 0) }
150+
#define VIRTCHNL_CHECK_UNION_LEN(n, X) enum virtchnl_static_asset_enum_##X \
151+
{ virtchnl_static_assert_##X = (n)/((sizeof(union X) == (n)) ? 1 : 0) }
150152

151153
/* Virtual channel message descriptor. This overlays the admin queue
152154
* descriptor. All other data is passed in external buffers.

0 commit comments

Comments
 (0)