Skip to content

Commit 4b56640

Browse files
GustavoARSilvadjbw
authored andcommitted
ACPI: NFIT: Replace zero-length array with flexible-array member
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] 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/[email protected] Signed-off-by: Dan Williams <[email protected]>
1 parent 11a48a5 commit 4b56640

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

drivers/acpi/nfit/nfit.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,32 +144,32 @@ struct nfit_spa {
144144
unsigned long ars_state;
145145
u32 clear_err_unit;
146146
u32 max_ars;
147-
struct acpi_nfit_system_address spa[0];
147+
struct acpi_nfit_system_address spa[];
148148
};
149149

150150
struct nfit_dcr {
151151
struct list_head list;
152-
struct acpi_nfit_control_region dcr[0];
152+
struct acpi_nfit_control_region dcr[];
153153
};
154154

155155
struct nfit_bdw {
156156
struct list_head list;
157-
struct acpi_nfit_data_region bdw[0];
157+
struct acpi_nfit_data_region bdw[];
158158
};
159159

160160
struct nfit_idt {
161161
struct list_head list;
162-
struct acpi_nfit_interleave idt[0];
162+
struct acpi_nfit_interleave idt[];
163163
};
164164

165165
struct nfit_flush {
166166
struct list_head list;
167-
struct acpi_nfit_flush_address flush[0];
167+
struct acpi_nfit_flush_address flush[];
168168
};
169169

170170
struct nfit_memdev {
171171
struct list_head list;
172-
struct acpi_nfit_memory_map memdev[0];
172+
struct acpi_nfit_memory_map memdev[];
173173
};
174174

175175
enum nfit_mem_flags {

0 commit comments

Comments
 (0)