linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] docs: deprecated.rst: Add note about DECLARE_FLEX_ARRAY() usage
@ 2023-01-06 20:06 Kees Cook
  2023-01-11 23:11 ` Jonathan Corbet
  0 siblings, 1 reply; 3+ messages in thread
From: Kees Cook @ 2023-01-06 20:06 UTC (permalink / raw)
  To: Jonathan Corbet
  Cc: Kees Cook, Vincent Mailhol, Gustavo A. R. Silva, linux-doc,
	linux-kernel, linux-hardening

There wasn't any mention of when/where DECLARE_FLEX_ARRAY() should be
used, so add the rationale and an example to the deprecation docs.

Suggested-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: linux-doc@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 Documentation/process/deprecated.rst | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/Documentation/process/deprecated.rst b/Documentation/process/deprecated.rst
index c8fd53a11a20..fcac0a929efa 100644
--- a/Documentation/process/deprecated.rst
+++ b/Documentation/process/deprecated.rst
@@ -346,3 +346,29 @@ struct_size() and flex_array_size() helpers::
         instance->count = count;
 
         memcpy(instance->items, source, flex_array_size(instance, items, instance->count));
+
+There are two special cases of replacement where the DECLARE_FLEX_ARRAY()
+helper needs to be used. (Note that it is named __DECLARE_FLEX_ARRAY() for
+use in UAPI headers.) When the flexible array is either alone in a struct,
+or is part of a union. These are disallowed by the C99 specification,
+but for no technical reason (as can be seen by both the existing use of
+such arrays in those places and the work-around that DECLARE_FLEX_ARRAY()
+uses). For example, to convert this::
+
+	struct something {
+		...
+		union {
+			struct type1 one[0];
+			struct type2 two[0];
+		};
+	};
+
+The helper must be used::
+
+	struct something {
+		...
+		union {
+			DECLARE_FLEX_ARRAY(struct type1, one);
+			DECLARE_FLEX_ARRAY(struct type2, two);
+		};
+	};
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-01-12 19:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-06 20:06 [PATCH] docs: deprecated.rst: Add note about DECLARE_FLEX_ARRAY() usage Kees Cook
2023-01-11 23:11 ` Jonathan Corbet
2023-01-12 19:38   ` Kees Cook

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).