Skip to contentSkip to conversation

docs: deprecated.rst: Update zero-length/one-element arrays section

PATCH Applied Gustavo A. R. Silva 3 participants 4 messages Sep 1, 2020 – Sep 11, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 Documentation/process/deprecated.rst | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Documentation/process/deprecated.rst +3 -3
index 918e32d76fc4..9731704b3f3d 100644
@@ -322,7 +322,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;
@@ -334,5 +335,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));
Signature · 1 line
2.27.0
maintainer Applied
#2 lore raw
In reply to Gustavo A. R. Silva
Quoted 8 lines · On Mon, 31 Aug 2020 20:09:49 -0500 "Gustavo A. R. Silva"…

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.

---
 Documentation/process/deprecated.rst | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Applied, thanks.

jon

#3 lore raw
Quoted 7 lines · Jonathan Corbet
Quoted 4 lines · On Mon, 31 Aug 2020 20:09:49 -0500 "Gustavo A. R. Silva"…

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.

Quoted 6 lines
Quoted 4 lines
---
 Documentation/process/deprecated.rst | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Applied, thanks.

Thank you, both. :)

--
Gustavo