Skip to content

Commit

Permalink
virtchnl: Add a macro to check the size of a union
Browse files Browse the repository at this point in the history
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 <harshitha.ramamurthy@intel.com>
Tested-by: Andrew Bowers <andrewx.bowers@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
  • Loading branch information
Harshitha Ramamurthy authored and Jeff Kirsher committed Feb 14, 2018
1 parent 0c483bd commit 0718e56
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions include/linux/avf/virtchnl.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,15 @@ enum virtchnl_ops {
VIRTCHNL_OP_DISABLE_CHANNELS = 31,
};

/* This macro is used to generate a compilation error if a structure
/* 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 is not of the correct size, otherwise it creates an enum that is
* never used.
* structure/union is not of the correct size, otherwise it creates an enum
* that is never used.
*/
#define VIRTCHNL_CHECK_STRUCT_LEN(n, X) enum virtchnl_static_assert_enum_##X \
{ virtchnl_static_assert_##X = (n)/((sizeof(struct X) == (n)) ? 1 : 0) }
#define VIRTCHNL_CHECK_UNION_LEN(n, X) enum virtchnl_static_asset_enum_##X \
{ virtchnl_static_assert_##X = (n)/((sizeof(union X) == (n)) ? 1 : 0) }

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

0 comments on commit 0718e56

Please sign in to comment.