diff mbox series

[29/38] backports: add DECLARE_FLEX_ARRAY()

Message ID 20221011230356.1a1a6ae0dace.I5042a985a702b7a8b4dcb4116997b2a53749f6ca@changeid (mailing list archive)
State New, archived
Headers show
Series backports updates | expand

Commit Message

Johannes Berg Oct. 11, 2022, 9:04 p.m. UTC
From: Johannes Berg <johannes.berg@intel.com>

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
---
 backport/backport-include/linux/stddef.h | 31 ++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
diff mbox series

Patch

diff --git a/backport/backport-include/linux/stddef.h b/backport/backport-include/linux/stddef.h
index a6cdc67d2727..54afbd556467 100644
--- a/backport/backport-include/linux/stddef.h
+++ b/backport/backport-include/linux/stddef.h
@@ -23,4 +23,35 @@ 
 	(offsetof(TYPE, MEMBER)	+ sizeof_field(TYPE, MEMBER))
 #endif
 
+#ifndef DECLARE_FLEX_ARRAY
+/**
+ * __DECLARE_FLEX_ARRAY() - Declare a flexible array usable in a union
+ *
+ * @TYPE: The type of each flexible array element
+ * @NAME: The name of the flexible array member
+ *
+ * In order to have a flexible array member in a union or alone in a
+ * struct, it needs to be wrapped in an anonymous struct with at least 1
+ * named member, but that member can be empty.
++ */
+#define __DECLARE_FLEX_ARRAY(TYPE, NAME)       \
+	struct {			       \
+		struct { } __empty_ ## NAME;   \
+		TYPE NAME[];		       \
+	}
+
+/**
+ * DECLARE_FLEX_ARRAY() - Declare a flexible array usable in a union
+ *
+ * @TYPE: The type of each flexible array element
+ * @NAME: The name of the flexible array member
+ *
+ * In order to have a flexible array member in a union or alone in a
+ * struct, it needs to be wrapped in an anonymous struct with at least 1
+ * named member, but that member can be empty.
+ */
+#define DECLARE_FLEX_ARRAY(TYPE, NAME) \
+	__DECLARE_FLEX_ARRAY(TYPE, NAME)
+#endif
+
 #endif /* __BACKPORT_LINUX_STDDEF_H */