X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=Documentation%2FCodingStyle;h=eb7db3c192273aa7b7b5d9244593c4add69bc863;hb=8827cc706861070f8a3a9e839b96e40231b16ce0;hp=22e5f9036f3c193f88d14611b2e5fe669b2c9b9e;hpb=2625c1be3425f5a9d8ef1434449b7d954aaf199d;p=powerpc.git diff --git a/Documentation/CodingStyle b/Documentation/CodingStyle index 22e5f9036f..eb7db3c192 100644 --- a/Documentation/CodingStyle +++ b/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.