Skip to contentSkip to conversation

CodingStyle: add kmalloc_array() to memory allocators

PATCH In review Xi Wang 3 participants 3 messages Apr 14, 2012 – Apr 15, 2012 Documentation

lore
Share & tools
lore

Xi Wang

author
#0 lore raw

PATCH 1/1 CodingStyle: add kmalloc_array() to memory allocators

Add the new kmalloc_array() to the list of general-purpose memory allocators in chapter 14.

Cc Jesper Juhl <[email protected]>
Cc Jens Axboe <[email protected]>
Cc Dan Carpenter <[email protected]>
Cc David Rientjes <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Pekka Enberg <[email protected]>
---
 Documentation/CodingStyle |   16 ++++++++++++++--
 1 files changed, 14 insertions(+), 2 deletions(-)
Documentation/CodingStyle +14 -2
index c58b236..cb9258b 100644
@@ -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
 
Signature · 1 line
1.7.5.4
Acked-by on v1 1/1
#2 lore raw
In reply to Xi Wang
Quoted 10 lines · Xi Wang

Add the new kmalloc_array() to the list of general-purpose memory allocators in chapter 14.

Cc Jesper Juhl <[email protected]>
Cc Jens Axboe <[email protected]>
Cc Dan Carpenter <[email protected]>
Cc David Rientjes <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Pekka Enberg <[email protected]>

Looks OK to me.

Signature · 3 lines
Jesper Juhl <[email protected]>       http://www.chaosbits.net/
Don't top-post http://www.catb.org/jargon/html/T/top-post.html
Plain text mails only, please.