linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] docs/core-api: memory-allocation: mention size helpers
@ 2019-10-21 21:27 Chris Packham
  2019-10-22 13:19 ` Jonathan Corbet
  0 siblings, 1 reply; 4+ messages in thread
From: Chris Packham @ 2019-10-21 21:27 UTC (permalink / raw)
  To: corbet, willy; +Cc: linux-doc, linux-kernel, Chris Packham

Mention struct_size(), array_size() and array3_size() in the same place
as kmalloc() and friends.

Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
---
 Documentation/core-api/memory-allocation.rst | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/Documentation/core-api/memory-allocation.rst b/Documentation/core-api/memory-allocation.rst
index e59779aa7615..6a131767becd 100644
--- a/Documentation/core-api/memory-allocation.rst
+++ b/Documentation/core-api/memory-allocation.rst
@@ -91,7 +91,9 @@ The most straightforward way to allocate memory is to use a function
 from the :c:func:`kmalloc` family. And, to be on the safe side it's
 best to use routines that set memory to zero, like
 :c:func:`kzalloc`. If you need to allocate memory for an array, there
-are :c:func:`kmalloc_array` and :c:func:`kcalloc` helpers.
+are :c:func:`kmalloc_array` and :c:func:`kcalloc` helpers. The helpers
+:c:func:`struct_size`, :c:func:`array_size` and :c:func:`array3_size` can be
+used to safely calculate object sizes without overflowing.
 
 The maximal size of a chunk that can be allocated with `kmalloc` is
 limited. The actual limit depends on the hardware and the kernel
-- 
2.23.0


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

* Re: [PATCH] docs/core-api: memory-allocation: mention size helpers
  2019-10-21 21:27 [PATCH] docs/core-api: memory-allocation: mention size helpers Chris Packham
@ 2019-10-22 13:19 ` Jonathan Corbet
  2019-10-22 20:05   ` Chris Packham
  0 siblings, 1 reply; 4+ messages in thread
From: Jonathan Corbet @ 2019-10-22 13:19 UTC (permalink / raw)
  To: Chris Packham; +Cc: willy, linux-doc, linux-kernel

On Tue, 22 Oct 2019 10:27:47 +1300
Chris Packham <chris.packham@alliedtelesis.co.nz> wrote:

> Mention struct_size(), array_size() and array3_size() in the same place
> as kmalloc() and friends.
> 
> Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
> ---
>  Documentation/core-api/memory-allocation.rst | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/Documentation/core-api/memory-allocation.rst b/Documentation/core-api/memory-allocation.rst
> index e59779aa7615..6a131767becd 100644
> --- a/Documentation/core-api/memory-allocation.rst
> +++ b/Documentation/core-api/memory-allocation.rst
> @@ -91,7 +91,9 @@ The most straightforward way to allocate memory is to use a function
>  from the :c:func:`kmalloc` family. And, to be on the safe side it's
>  best to use routines that set memory to zero, like
>  :c:func:`kzalloc`. If you need to allocate memory for an array, there
> -are :c:func:`kmalloc_array` and :c:func:`kcalloc` helpers.
> +are :c:func:`kmalloc_array` and :c:func:`kcalloc` helpers. The helpers
> +:c:func:`struct_size`, :c:func:`array_size` and :c:func:`array3_size` can be
> +used to safely calculate object sizes without overflowing.

Quick comment: we don't need :c:func: anymore; the markup happens anyway.
So rather than adding more of them, could I ask you to please take out the
ones that are there now?

Thanks,

jon

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

* Re: [PATCH] docs/core-api: memory-allocation: mention size helpers
  2019-10-22 13:19 ` Jonathan Corbet
@ 2019-10-22 20:05   ` Chris Packham
  2019-10-22 20:38     ` Jonathan Corbet
  0 siblings, 1 reply; 4+ messages in thread
From: Chris Packham @ 2019-10-22 20:05 UTC (permalink / raw)
  To: corbet; +Cc: linux-kernel, willy, linux-doc

Hi Jon,

On Tue, 2019-10-22 at 07:19 -0600, Jonathan Corbet wrote:
> On Tue, 22 Oct 2019 10:27:47 +1300
> Chris Packham <chris.packham@alliedtelesis.co.nz> wrote:
> 
> > Mention struct_size(), array_size() and array3_size() in the same place
> > as kmalloc() and friends.
> > 
> > Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
> > ---
> >  Documentation/core-api/memory-allocation.rst | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/Documentation/core-api/memory-allocation.rst b/Documentation/core-api/memory-allocation.rst
> > index e59779aa7615..6a131767becd 100644
> > --- a/Documentation/core-api/memory-allocation.rst
> > +++ b/Documentation/core-api/memory-allocation.rst
> > @@ -91,7 +91,9 @@ The most straightforward way to allocate memory is to use a function
> >  from the :c:func:`kmalloc` family. And, to be on the safe side it's
> >  best to use routines that set memory to zero, like
> >  :c:func:`kzalloc`. If you need to allocate memory for an array, there
> > -are :c:func:`kmalloc_array` and :c:func:`kcalloc` helpers.
> > +are :c:func:`kmalloc_array` and :c:func:`kcalloc` helpers. The helpers
> > +:c:func:`struct_size`, :c:func:`array_size` and :c:func:`array3_size` can be
> > +used to safely calculate object sizes without overflowing.
> 
> Quick comment: we don't need :c:func: anymore; the markup happens anyway.
> So rather than adding more of them, could I ask you to please take out the
> ones that are there now?

So just with backquotes i.e. :c:func:`kmalloc` becomes `kmalloc`?

> 
> Thanks,
> 
> jon

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

* Re: [PATCH] docs/core-api: memory-allocation: mention size helpers
  2019-10-22 20:05   ` Chris Packham
@ 2019-10-22 20:38     ` Jonathan Corbet
  0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Corbet @ 2019-10-22 20:38 UTC (permalink / raw)
  To: Chris Packham; +Cc: linux-kernel, willy, linux-doc

On Tue, 22 Oct 2019 20:05:38 +0000
Chris Packham <Chris.Packham@alliedtelesis.co.nz> wrote:

> > Quick comment: we don't need :c:func: anymore; the markup happens anyway.
> > So rather than adding more of them, could I ask you to please take out the
> > ones that are there now?  
> 
> So just with backquotes i.e. :c:func:`kmalloc` becomes `kmalloc`?

No, just:

	kmalloc()

will do the trick.  See:

	https://www.kernel.org/doc/html/latest/doc-guide/sphinx.html#the-c-domain

Thanks,

jon

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

end of thread, other threads:[~2019-10-22 20:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-21 21:27 [PATCH] docs/core-api: memory-allocation: mention size helpers Chris Packham
2019-10-22 13:19 ` Jonathan Corbet
2019-10-22 20:05   ` Chris Packham
2019-10-22 20:38     ` Jonathan Corbet

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).