From 28abc106339f15f133d5440ded9901e2ecea7401 Mon Sep 17 00:00:00 2001 From: Xi Wang Date: Thu, 31 May 2012 16:26:04 -0700 Subject: [PATCH] --- yaml --- r: 309707 b: refs/heads/master c: 15837294d4ce717f69942f7366e99d4d1d3d9923 h: refs/heads/master i: 309705: 0820995d0217d34275b07b31bf6d31909e17cc39 309703: c2a8177c8eeb5fed0cf3830b2025206a8520f071 v: v3 --- [refs] | 2 +- trunk/Documentation/CodingStyle | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/[refs] b/[refs] index 0d5672dc09be..45d0c9761296 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 1cefe28f95da307287a05a6a0c10213f01055e2a +refs/heads/master: 15837294d4ce717f69942f7366e99d4d1d3d9923 diff --git a/trunk/Documentation/CodingStyle b/trunk/Documentation/CodingStyle index c58b236bbe04..cb9258b8fd35 100644 --- a/trunk/Documentation/CodingStyle +++ b/trunk/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