Commit 15837294 authored by Xi Wang's avatar Xi Wang Committed by Linus Torvalds

CodingStyle: add kmalloc_array() to memory allocators

Add the new kmalloc_array() to the list of general-purpose memory
allocators in chapter 14.
Signed-off-by: default avatarXi Wang <xi.wang@gmail.com>
Acked-by: default avatarJesper Juhl <jj@chaosbits.net>
Acked-by: default avatarPekka Enberg <penberg@kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 1cefe28f
...@@ -671,8 +671,9 @@ ones already enabled by DEBUG. ...@@ -671,8 +671,9 @@ ones already enabled by DEBUG.
Chapter 14: Allocating memory Chapter 14: Allocating memory
The kernel provides the following general purpose memory allocators: The kernel provides the following general purpose memory allocators:
kmalloc(), kzalloc(), kcalloc(), vmalloc(), and vzalloc(). Please refer to kmalloc(), kzalloc(), kmalloc_array(), kcalloc(), vmalloc(), and
the API documentation for further information about them. 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: 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 ...@@ -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 from void pointer to any other pointer type is guaranteed by the C programming
language. 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 Chapter 15: The inline disease
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment