Skip to content

Commit db5871e

Browse files
GustavoARSilvaliuw
authored andcommitted
vmbus: Replace zero-length array with flexible-array
The current codebase makes use of the zero-length array language extension to the C90 standard, but the preferred mechanism to declare variable-length types such as these ones is a flexible array member[1][2], introduced in C99: struct foo { int stuff; struct boo array[]; }; By making use of the mechanism above, we will get a compiler warning in case the flexible array does not occur last in the structure, which will help us prevent some kind of undefined behavior bugs from being inadvertently introduced[3] to the codebase from now on. Also, notice that, dynamic memory allocations won't be affected by this change: "Flexible array members have incomplete type, and so the sizeof operator may not be applied. As a quirk of the original implementation of zero-length arrays, sizeof evaluates to zero."[1] sizeof(flexible-array-member) triggers a warning because flexible array members have incomplete type[1]. There are some instances of code in which the sizeof operator is being incorrectly/erroneously applied to zero-length arrays and the result is zero. Such instances may be hiding some bugs. So, this work (flexible-array member conversions) will also help to get completely rid of those sorts of issues. This issue was found with the help of Coccinelle. [1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html [2] KSPP#21 [3] commit 7649773 ("cxgb3/l2t: Fix undefined behaviour") Signed-off-by: Gustavo A. R. Silva <[email protected]> Link: https://lore.kernel.org/r/20200507185323.GA14416@embeddedor Signed-off-by: Wei Liu <[email protected]>
1 parent 723c425 commit db5871e

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

include/linux/hyperv.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ struct hv_ring_buffer {
117117
* Ring data starts here + RingDataStartOffset
118118
* !!! DO NOT place any fields below this !!!
119119
*/
120-
u8 buffer[0];
120+
u8 buffer[];
121121
} __packed;
122122

123123
struct hv_ring_buffer_info {
@@ -313,7 +313,7 @@ struct vmadd_remove_transfer_page_set {
313313
struct gpa_range {
314314
u32 byte_count;
315315
u32 byte_offset;
316-
u64 pfn_array[0];
316+
u64 pfn_array[];
317317
};
318318

319319
/*
@@ -563,15 +563,15 @@ struct vmbus_channel_gpadl_header {
563563
u32 gpadl;
564564
u16 range_buflen;
565565
u16 rangecount;
566-
struct gpa_range range[0];
566+
struct gpa_range range[];
567567
} __packed;
568568

569569
/* This is the followup packet that contains more PFNs. */
570570
struct vmbus_channel_gpadl_body {
571571
struct vmbus_channel_message_header header;
572572
u32 msgnumber;
573573
u32 gpadl;
574-
u64 pfn[0];
574+
u64 pfn[];
575575
} __packed;
576576

577577
struct vmbus_channel_gpadl_created {
@@ -679,7 +679,7 @@ struct vmbus_channel_msginfo {
679679
* The channel message that goes out on the "wire".
680680
* It will contain at minimum the VMBUS_CHANNEL_MESSAGE_HEADER header
681681
*/
682-
unsigned char msg[0];
682+
unsigned char msg[];
683683
};
684684

685685
struct vmbus_close_msg {

0 commit comments

Comments
 (0)