Skip to content

Commit

Permalink
[PATCH] CodingStyle: memory allocation
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Pekka J Enberg authored and Linus Torvalds committed Sep 17, 2005
1 parent f647e08 commit af4e5a2
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion Documentation/CodingStyle
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit af4e5a2

Please sign in to comment.