summaryrefslogtreecommitdiff
path: root/Documentation/process
diff options
context:
space:
mode:
authorGustavo A. R. Silva <gustavoars@kernel.org>2020-09-01 04:09:49 +0300
committerJonathan Corbet <corbet@lwn.net>2020-09-09 20:37:49 +0300
commit17dca0502314fa4855fae269dc86a1ce840a4d1a (patch)
tree49d4a558fbdd5aaf30a69910669b9eb817cbae93 /Documentation/process
parent9334e34fe1d5dec2bcfd41a4a1317d284ab1d61f (diff)
downloadlinux-17dca0502314fa4855fae269dc86a1ce840a4d1a.tar.xz
docs: deprecated.rst: Update zero-length/one-element arrays section
Update information in the zero-length and one-element arrays section and illustrate how to make use of the new flex_array_size() helper, together with struct_size() and a flexible-array member. Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> Acked-by: Kees Cook <keescook@chromium.org> Link: https://lore.kernel.org/r/20200901010949.GA21398@embeddedor Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Diffstat (limited to 'Documentation/process')
-rw-r--r--Documentation/process/deprecated.rst6
1 files changed, 3 insertions, 3 deletions
diff --git a/Documentation/process/deprecated.rst b/Documentation/process/deprecated.rst
index 70720f00b9aa..ff71d802b53d 100644
--- a/Documentation/process/deprecated.rst
+++ b/Documentation/process/deprecated.rst
@@ -304,7 +304,8 @@ to allocate for a structure containing an array of this kind as a member::
In the example above, we had to remember to calculate ``count - 1`` when using
the struct_size() helper, otherwise we would have --unintentionally-- allocated
memory for one too many ``items`` objects. The cleanest and least error-prone way
-to implement this is through the use of a `flexible array member`::
+to implement this is through the use of a `flexible array member`, together with
+struct_size() and flex_array_size() helpers::
struct something {
size_t count;
@@ -316,5 +317,4 @@ to implement this is through the use of a `flexible array member`::
instance = kmalloc(struct_size(instance, items, count), GFP_KERNEL);
instance->count = count;
- size = sizeof(instance->items[0]) * instance->count;
- memcpy(instance->items, source, size);
+ memcpy(instance->items, source, flex_array_size(instance, items, instance->count));