diff options
| author | Jeff Garzik <jgarzik@pobox.com> | 2005-09-23 19:03:21 -0400 |
|---|---|---|
| committer | Jeff Garzik <jgarzik@pobox.com> | 2005-09-23 19:03:21 -0400 |
| commit | 536f8098026bde1368bbfcbcb9682a7637b73df2 (patch) | |
| tree | cf83d2e1afa503b6aeba103b55cd1da0af4e7a4c /Documentation/CodingStyle | |
| parent | e86ee6682b649183c11013a98be02f25e9ae399d (diff) | |
| parent | 3fd07d3bf0077dcc0f5a33d2eb1938ea050da8da (diff) | |
Merge /spare/repo/linux-2.6/
Diffstat (limited to 'Documentation/CodingStyle')
| -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. 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. |
