* [PATCH] CodingStyle: add kmalloc_array() to memory allocators
@ 2012-04-14 9:48 Xi Wang
2012-04-15 16:04 ` Pekka Enberg
2012-04-15 21:27 ` Jesper Juhl
0 siblings, 2 replies; 3+ messages in thread
From: Xi Wang @ 2012-04-14 9:48 UTC (permalink / raw)
To: Randy Dunlap
Cc: linux-doc, linux-kernel, Xi Wang, Jesper Juhl, Jens Axboe,
Dan Carpenter, David Rientjes, Andrew Morton, Pekka Enberg
Add the new kmalloc_array() to the list of general-purpose memory
allocators in chapter 14.
Signed-off-by: Xi Wang <xi.wang@gmail.com>
Cc: Jesper Juhl <jj@chaosbits.net>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Pekka Enberg <penberg@kernel.org>
---
Documentation/CodingStyle | 16 ++++++++++++++--
1 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/Documentation/CodingStyle b/Documentation/CodingStyle
index c58b236..cb9258b 100644
--- a/Documentation/CodingStyle
+++ b/Documentation/CodingStyle
@@ -671,8 +671,9 @@ ones already enabled by DEBUG.
Chapter 14: Allocating memory
The kernel provides the following general purpose memory allocators:
-kmalloc(), kzalloc(), kcalloc(), vmalloc(), and vzalloc(). Please refer to
-the API documentation for further information about them.
+kmalloc(), kzalloc(), kmalloc_array(), kcalloc(), vmalloc(), and
+vzalloc(). Please refer to the API documentation for further information
+about them.
The preferred form for passing a size of a struct is the following:
@@ -686,6 +687,17 @@ Casting the return value which is a void pointer is redundant. The conversion
from void pointer to any other pointer type is guaranteed by the C programming
language.
+The preferred form for allocating an array is the following:
+
+ p = kmalloc_array(n, sizeof(...), ...);
+
+The preferred form for allocating a zeroed array is the following:
+
+ p = kcalloc(n, sizeof(...), ...);
+
+Both forms check for overflow on the allocation size n * sizeof(...),
+and return NULL if that occurred.
+
Chapter 15: The inline disease
--
1.7.5.4
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] CodingStyle: add kmalloc_array() to memory allocators
2012-04-14 9:48 [PATCH] CodingStyle: add kmalloc_array() to memory allocators Xi Wang
@ 2012-04-15 16:04 ` Pekka Enberg
2012-04-15 21:27 ` Jesper Juhl
1 sibling, 0 replies; 3+ messages in thread
From: Pekka Enberg @ 2012-04-15 16:04 UTC (permalink / raw)
To: Xi Wang
Cc: Randy Dunlap, linux-doc, linux-kernel, Jesper Juhl, Jens Axboe,
Dan Carpenter, David Rientjes, Andrew Morton
On Sat, 14 Apr 2012, Xi Wang wrote:
> Add the new kmalloc_array() to the list of general-purpose memory
> allocators in chapter 14.
>
> Signed-off-by: Xi Wang <xi.wang@gmail.com>
> Cc: Jesper Juhl <jj@chaosbits.net>
> Cc: Jens Axboe <axboe@kernel.dk>
> Cc: Dan Carpenter <dan.carpenter@oracle.com>
> Cc: David Rientjes <rientjes@google.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Pekka Enberg <penberg@kernel.org>
> ---
Acked-by: Pekka Enberg <penberg@kernel.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] CodingStyle: add kmalloc_array() to memory allocators
2012-04-14 9:48 [PATCH] CodingStyle: add kmalloc_array() to memory allocators Xi Wang
2012-04-15 16:04 ` Pekka Enberg
@ 2012-04-15 21:27 ` Jesper Juhl
1 sibling, 0 replies; 3+ messages in thread
From: Jesper Juhl @ 2012-04-15 21:27 UTC (permalink / raw)
To: Xi Wang
Cc: Randy Dunlap, linux-doc, linux-kernel, Jens Axboe, Dan Carpenter,
David Rientjes, Andrew Morton, Pekka Enberg
On Sat, 14 Apr 2012, Xi Wang wrote:
> Add the new kmalloc_array() to the list of general-purpose memory
> allocators in chapter 14.
>
> Signed-off-by: Xi Wang <xi.wang@gmail.com>
> Cc: Jesper Juhl <jj@chaosbits.net>
> Cc: Jens Axboe <axboe@kernel.dk>
> Cc: Dan Carpenter <dan.carpenter@oracle.com>
> Cc: David Rientjes <rientjes@google.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Pekka Enberg <penberg@kernel.org>
Looks OK to me.
Acked-by: Jesper Juhl <jj@chaosbits.net>
--
Jesper Juhl <jj@chaosbits.net> http://www.chaosbits.net/
Don't top-post http://www.catb.org/jargon/html/T/top-post.html
Plain text mails only, please.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-04-15 21:27 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-14 9:48 [PATCH] CodingStyle: add kmalloc_array() to memory allocators Xi Wang
2012-04-15 16:04 ` Pekka Enberg
2012-04-15 21:27 ` Jesper Juhl
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®