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

Federico Parola posted 1 patch 3 weeks, 4 days ago
arch/x86/include/uapi/asm/setup_data.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] x86/header: Use __DECLARE_FLEX_ARRAY() for struct setup_data flex array
Posted by Federico Parola 3 weeks, 4 days ago
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")
Signed-off-by: Federico Parola <fparola@amazon.de>
---
 arch/x86/include/uapi/asm/setup_data.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/include/uapi/asm/setup_data.h b/arch/x86/include/uapi/asm/setup_data.h
index 2671c4e1b3a0b..afe1e3a2a6564 100644
--- a/arch/x86/include/uapi/asm/setup_data.h
+++ b/arch/x86/include/uapi/asm/setup_data.h
@@ -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 */
-- 
2.47.3

Re: [PATCH] x86/header: Use __DECLARE_FLEX_ARRAY() for struct setup_data flex array
Posted by H. Peter Anvin 3 weeks, 4 days ago
On September 1, 2026 4:42:39 AM PDT, Federico Parola <fparola@amazon.de> wrote:
>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")
>Signed-off-by: Federico Parola <fparola@amazon.de>
>---
> arch/x86/include/uapi/asm/setup_data.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/arch/x86/include/uapi/asm/setup_data.h b/arch/x86/include/uapi/asm/setup_data.h
>index 2671c4e1b3a0b..afe1e3a2a6564 100644
>--- a/arch/x86/include/uapi/asm/setup_data.h
>+++ b/arch/x86/include/uapi/asm/setup_data.h
>@@ -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?