summaryrefslogtreecommitdiffstats
path: root/Documentation/process/deprecated.rst
diff options
context:
space:
mode:
authorKees Cook <keescook@chromium.org>2023-01-06 12:06:04 -0800
committerJonathan Corbet <corbet@lwn.net>2023-01-13 09:26:19 -0700
commit8763a30bc15b36c3bd90d6da7272d972b995f318 (patch)
tree3671cecf70a641d4b5dbd130a5d7b9862da15a21 /Documentation/process/deprecated.rst
parent5a37deab42ad1630b39bf9bca13aa55e94310b01 (diff)
downloadlinux-stable-8763a30bc15b36c3bd90d6da7272d972b995f318.tar.gz
linux-stable-8763a30bc15b36c3bd90d6da7272d972b995f318.tar.bz2
linux-stable-8763a30bc15b36c3bd90d6da7272d972b995f318.zip
docs: deprecated.rst: Add note about DECLARE_FLEX_ARRAY() usage
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: "Gustavo A. R. Silva" <gustavoars@kernel.org> Signed-off-by: Kees Cook <keescook@chromium.org> Link: https://lore.kernel.org/r/20230106200600.never.735-kees@kernel.org [jc: minor wording tweaks] Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Diffstat (limited to 'Documentation/process/deprecated.rst')
-rw-r--r--Documentation/process/deprecated.rst26
1 files changed, 26 insertions, 0 deletions
diff --git a/Documentation/process/deprecated.rst b/Documentation/process/deprecated.rst
index c8fd53a11a20..f91b8441f2ef 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.) Those cases are 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);
+ };
+ };