From cab24582d5682b339ca8fe7c87d9dd415f923d6c Mon Sep 17 00:00:00 2001 From: Pekka J Enberg Date: Fri, 16 Sep 2005 19:28:11 -0700 Subject: [PATCH] --- yaml --- r: 9039 b: refs/heads/master c: af4e5a218e18ad588d60a4f9d6f8fb5db1a32587 h: refs/heads/master i: 9037: 0dc9d0d850439e602dac2fa2842c41188b6d4bf0 9035: ac1a2911f58c2cbf008967548976356a54837390 9031: e8c62ddf3ca2070c4753fa24c292334261bafa77 9023: f8231b4264145d45023feb333651ba94a892b740 v: v3 --- [refs] | 2 +- trunk/Documentation/CodingStyle | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/[refs] b/[refs] index b183da16be09..591ead0f8de9 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: f647e08a55d2c88c4e7ab17a0a8e3fcf568fbc65 +refs/heads/master: af4e5a218e18ad588d60a4f9d6f8fb5db1a32587 diff --git a/trunk/Documentation/CodingStyle b/trunk/Documentation/CodingStyle index 22e5f9036f3c..eb7db3c19227 100644 --- a/trunk/Documentation/CodingStyle +++ b/trunk/Documentation/CodingStyle @@ -410,7 +410,26 @@ Kernel messages do not have to be terminated with a period. Printing numbers in parentheses (%d) adds no value and should be avoided. - Chapter 13: References + Chapter 13: Allocating memory + +The kernel provides the following general purpose memory allocators: +kmalloc(), kzalloc(), kcalloc(), and vmalloc(). Please refer to the API +documentation for further information about them. + +The preferred form for passing a size of a struct is the following: + + p = kmalloc(sizeof(*p), ...); + +The alternative form where struct name is spelled out hurts readability and +introduces an opportunity for a bug when the pointer variable type is changed +but the corresponding sizeof that is passed to a memory allocator is not. + +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. + + + Chapter 14: References The C Programming Language, Second Edition by Brian W. Kernighan and Dennis M. Ritchie.