diff options
author | Pekka J Enberg <penberg@cs.Helsinki.FI> | 2005-09-16 22:28:11 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2005-09-17 14:50:02 -0400 |
commit | af4e5a218e18ad588d60a4f9d6f8fb5db1a32587 (patch) | |
tree | 39f6737bb96998199144382cdb4eb867be180873 /Documentation | |
parent | f647e08a55d2c88c4e7ab17a0a8e3fcf568fbc65 (diff) |
[PATCH] CodingStyle: memory allocation
This patch adds a new chapter on memory allocation to
Documentation/CodingStyle.
Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'Documentation')
-rw-r--r-- | Documentation/CodingStyle | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/Documentation/CodingStyle b/Documentation/CodingStyle index 22e5f9036f3c..eb7db3c19227 100644 --- a/Documentation/CodingStyle +++ b/Documentation/CodingStyle | |||
@@ -410,7 +410,26 @@ Kernel messages do not have to be terminated with a period. | |||
410 | Printing numbers in parentheses (%d) adds no value and should be avoided. | 410 | Printing numbers in parentheses (%d) adds no value and should be avoided. |
411 | 411 | ||
412 | 412 | ||
413 | Chapter 13: References | 413 | Chapter 13: Allocating memory |
414 | |||
415 | The kernel provides the following general purpose memory allocators: | ||
416 | kmalloc(), kzalloc(), kcalloc(), and vmalloc(). Please refer to the API | ||
417 | documentation for further information about them. | ||
418 | |||
419 | The preferred form for passing a size of a struct is the following: | ||
420 | |||
421 | p = kmalloc(sizeof(*p), ...); | ||
422 | |||
423 | The alternative form where struct name is spelled out hurts readability and | ||
424 | introduces an opportunity for a bug when the pointer variable type is changed | ||
425 | but the corresponding sizeof that is passed to a memory allocator is not. | ||
426 | |||
427 | Casting the return value which is a void pointer is redundant. The conversion | ||
428 | from void pointer to any other pointer type is guaranteed by the C programming | ||
429 | language. | ||
430 | |||
431 | |||
432 | Chapter 14: References | ||
414 | 433 | ||
415 | The C Programming Language, Second Edition | 434 | The C Programming Language, Second Edition |
416 | by Brian W. Kernighan and Dennis M. Ritchie. | 435 | by Brian W. Kernighan and Dennis M. Ritchie. |