aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/CodingStyle
diff options
context:
space:
mode:
authorXi Wang <xi.wang@gmail.com>2012-05-31 19:26:04 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-05-31 20:49:26 -0400
commit15837294d4ce717f69942f7366e99d4d1d3d9923 (patch)
tree41a7047f7f4bf3747fa162aaeec6a1e0a18fd848 /Documentation/CodingStyle
parent1cefe28f95da307287a05a6a0c10213f01055e2a (diff)
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: Xi Wang <xi.wang@gmail.com> Acked-by: Jesper Juhl <jj@chaosbits.net> Acked-by: Pekka Enberg <penberg@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'Documentation/CodingStyle')
-rw-r--r--Documentation/CodingStyle16
1 files changed, 14 insertions, 2 deletions
diff --git a/Documentation/CodingStyle b/Documentation/CodingStyle
index c58b236bbe04..cb9258b8fd35 100644
--- a/Documentation/CodingStyle
+++ b/Documentation/CodingStyle
@@ -671,8 +671,9 @@ ones already enabled by DEBUG.
671 Chapter 14: Allocating memory 671 Chapter 14: Allocating memory
672 672
673The kernel provides the following general purpose memory allocators: 673The kernel provides the following general purpose memory allocators:
674kmalloc(), kzalloc(), kcalloc(), vmalloc(), and vzalloc(). Please refer to 674kmalloc(), kzalloc(), kmalloc_array(), kcalloc(), vmalloc(), and
675the API documentation for further information about them. 675vzalloc(). Please refer to the API documentation for further information
676about them.
676 677
677The preferred form for passing a size of a struct is the following: 678The preferred form for passing a size of a struct is the following:
678 679
@@ -686,6 +687,17 @@ Casting the return value which is a void pointer is redundant. The conversion
686from void pointer to any other pointer type is guaranteed by the C programming 687from void pointer to any other pointer type is guaranteed by the C programming
687language. 688language.
688 689
690The preferred form for allocating an array is the following:
691
692 p = kmalloc_array(n, sizeof(...), ...);
693
694The preferred form for allocating a zeroed array is the following:
695
696 p = kcalloc(n, sizeof(...), ...);
697
698Both forms check for overflow on the allocation size n * sizeof(...),
699and return NULL if that occurred.
700
689 701
690 Chapter 15: The inline disease 702 Chapter 15: The inline disease
691 703