diff options
author | Harshitha Ramamurthy <harshitha.ramamurthy@intel.com> | 2018-01-23 11:51:03 -0500 |
---|---|---|
committer | Jeff Kirsher <jeffrey.t.kirsher@intel.com> | 2018-02-14 12:43:22 -0500 |
commit | 0718e560a330599d15fddc37651d693c7a09e49e (patch) | |
tree | 7479205c930d75a9ba84a70f5ba7201a8788abd3 /include/linux/avf | |
parent | 0c483bd4b82619397e7f655eea1ba3ba9d9a15a2 (diff) |
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 <harshitha.ramamurthy@intel.com>
Tested-by: Andrew Bowers <andrewx.bowers@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Diffstat (limited to 'include/linux/avf')
-rw-r--r-- | include/linux/avf/virtchnl.h | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/include/linux/avf/virtchnl.h b/include/linux/avf/virtchnl.h index 1f652ceecf35..6fe630ebbf23 100644 --- a/include/linux/avf/virtchnl.h +++ b/include/linux/avf/virtchnl.h | |||
@@ -140,13 +140,15 @@ enum virtchnl_ops { | |||
140 | VIRTCHNL_OP_DISABLE_CHANNELS = 31, | 140 | VIRTCHNL_OP_DISABLE_CHANNELS = 31, |
141 | }; | 141 | }; |
142 | 142 | ||
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 |
144 | * is not exactly the correct length. It gives a divide by zero error if the | 144 | * 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 | 145 | * structure/union is not of the correct size, otherwise it creates an enum |
146 | * never used. | 146 | * that is never used. |
147 | */ | 147 | */ |
148 | #define VIRTCHNL_CHECK_STRUCT_LEN(n, X) enum virtchnl_static_assert_enum_##X \ | 148 | #define VIRTCHNL_CHECK_STRUCT_LEN(n, X) enum virtchnl_static_assert_enum_##X \ |
149 | { virtchnl_static_assert_##X = (n)/((sizeof(struct X) == (n)) ? 1 : 0) } | 149 | { 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) } | ||
150 | 152 | ||
151 | /* Virtual channel message descriptor. This overlays the admin queue | 153 | /* Virtual channel message descriptor. This overlays the admin queue |
152 | * descriptor. All other data is passed in external buffers. | 154 | * descriptor. All other data is passed in external buffers. |