* [PATCH] docs: deprecated.rst: Update zero-length/one-element arrays section
@ 2020-09-01 1:09 Gustavo A. R. Silva
2020-09-09 17:12 ` Kees Cook
2020-09-09 17:38 ` Jonathan Corbet
0 siblings, 2 replies; 4+ messages in thread
From: Gustavo A. R. Silva @ 2020-09-01 1:09 UTC (permalink / raw)
To: Jonathan Corbet; +Cc: Kees Cook, linux-doc, linux-kernel, 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.
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
Documentation/process/deprecated.rst | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/Documentation/process/deprecated.rst b/Documentation/process/deprecated.rst
index 918e32d76fc4..9731704b3f3d 100644
--- a/Documentation/process/deprecated.rst
+++ b/Documentation/process/deprecated.rst
@@ -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));
--
2.27.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] docs: deprecated.rst: Update zero-length/one-element arrays section
2020-09-01 1:09 [PATCH] docs: deprecated.rst: Update zero-length/one-element arrays section Gustavo A. R. Silva
@ 2020-09-09 17:12 ` Kees Cook
2020-09-09 17:38 ` Jonathan Corbet
1 sibling, 0 replies; 4+ messages in thread
From: Kees Cook @ 2020-09-09 17:12 UTC (permalink / raw)
To: Gustavo A. R. Silva; +Cc: Jonathan Corbet, linux-doc, linux-kernel
On Mon, Aug 31, 2020 at 08:09:49PM -0500, Gustavo A. R. Silva wrote:
> 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>
Looks great!
Acked-by: Kees Cook <keescook@chromium.org>
--
Kees Cook
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] docs: deprecated.rst: Update zero-length/one-element arrays section
2020-09-01 1:09 [PATCH] docs: deprecated.rst: Update zero-length/one-element arrays section Gustavo A. R. Silva
2020-09-09 17:12 ` Kees Cook
@ 2020-09-09 17:38 ` Jonathan Corbet
2020-09-11 12:06 ` Gustavo A. R. Silva
1 sibling, 1 reply; 4+ messages in thread
From: Jonathan Corbet @ 2020-09-09 17:38 UTC (permalink / raw)
To: Gustavo A. R. Silva; +Cc: Kees Cook, linux-doc, linux-kernel
On Mon, 31 Aug 2020 20:09:49 -0500
"Gustavo A. R. Silva" <gustavoars@kernel.org> wrote:
> 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>
> ---
> Documentation/process/deprecated.rst | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
Applied, thanks.
jon
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] docs: deprecated.rst: Update zero-length/one-element arrays section
2020-09-09 17:38 ` Jonathan Corbet
@ 2020-09-11 12:06 ` Gustavo A. R. Silva
0 siblings, 0 replies; 4+ messages in thread
From: Gustavo A. R. Silva @ 2020-09-11 12:06 UTC (permalink / raw)
To: Jonathan Corbet; +Cc: Kees Cook, linux-doc, linux-kernel
On Wed, Sep 09, 2020 at 11:38:23AM -0600, Jonathan Corbet wrote:
> On Mon, 31 Aug 2020 20:09:49 -0500
> "Gustavo A. R. Silva" <gustavoars@kernel.org> wrote:
>
> > 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>
> > ---
> > Documentation/process/deprecated.rst | 6 +++---
> > 1 file changed, 3 insertions(+), 3 deletions(-)
>
> Applied, thanks.
Thank you, both. :)
--
Gustavo
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-09-11 12:01 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-09-01 1:09 [PATCH] docs: deprecated.rst: Update zero-length/one-element arrays section Gustavo A. R. Silva
2020-09-09 17:12 ` Kees Cook
2020-09-09 17:38 ` Jonathan Corbet
2020-09-11 12:06 ` Gustavo A. R. Silva
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.