Skip to contentSkip to conversation

x86/header: Use __DECLARE_FLEX_ARRAY() for struct setup_data flex array

PATCH In review Federico Parola 2 participants 2 messages Sep 1 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/header: Use __DECLARE_FLEX_ARRAY() for struct setup_data flex array

After the data member of struct setup_data was switched to a flex array by commit 94dfc73e7cf4 ("treewide: uapi: Replace zero-length arrays with flexible-array members"), the struct can no longer be used as a header in a larger struct in C++, with errors like:
flexible array member ‘setup_data::data’ not at end of ‘struct ...’
This breaks compilation of our userspace code which imports the header in a C++ project.

Similar to commit 2619da73bb2f ("KVM: x86: Use __DECLARE_FLEX_ARRAY() for UAPI structures with VLAs"), declare the member with __DECLARE_FLEX_ARRAY(), which uses [0] for C++ compilation.

Fixes 94dfc73e7cf4 ("treewide: uapi: Replace zero-length arrays with flexible-array members")
---
 arch/x86/include/uapi/asm/setup_data.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/include/uapi/asm/setup_data.h +1 -1
index 2671c4e1b3a0b..afe1e3a2a6564 100644
@@ -28,7 +28,7 @@ struct setup_data {
 	__u64 next;
 	__u32 type;
 	__u32 len;
-	__u8 data[];
+	__DECLARE_FLEX_ARRAY(__u8, data);
 };
 
 /* extensible setup indirect data node */
Signature · 1 line
2.47.3
#1 lore raw
Quoted 23 lines · Federico Parola

After the data member of struct setup_data was switched to a flex array by commit 94dfc73e7cf4 ("treewide: uapi: Replace zero-length arrays with flexible-array members"), the struct can no longer be used as a header in a larger struct in C++, with errors like:
flexible array member ‘setup_data::data’ not at end of ‘struct ...’ This breaks compilation of our userspace code which imports the header in a C++ project.

Similar to commit 2619da73bb2f ("KVM: x86: Use __DECLARE_FLEX_ARRAY() for UAPI structures with VLAs"), declare the member with __DECLARE_FLEX_ARRAY(), which uses [0] for C++ compilation.

Fixes 94dfc73e7cf4 ("treewide: uapi: Replace zero-length arrays with flexible-array members")

---
arch/x86/include/uapi/asm/setup_data.h | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/include/uapi/asm/setup_data.h +0 -0
index 2671c4e1b3a0b..afe1e3a2a6564 100644

arch/x86/include/uapi/asm/setup_data.h struct setup_data { · line 34

Quoted 8 lines
arch/x86/include/uapi/asm/setup_data.h +1 -1
@@ -28,7 +28,7 @@ struct setup_data {
 	__u64 next;
 	__u32 type;
 	__u32 len;
-	__u8 data[];
+	__DECLARE_FLEX_ARRAY(__u8, data);
 };
 
 /* extensible setup indirect data node */

Can we do this in the postprocessing of uapi headers, please?