aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/CodingStyle
diff options
context:
space:
mode:
Diffstat (limited to 'Documentation/CodingStyle')
-rw-r--r--Documentation/CodingStyle18
1 files changed, 18 insertions, 0 deletions
diff --git a/Documentation/CodingStyle b/Documentation/CodingStyle
index 0ad6dcb5d45f..9069189e78ef 100644
--- a/Documentation/CodingStyle
+++ b/Documentation/CodingStyle
@@ -682,6 +682,24 @@ result. Typical examples would be functions that return pointers; they use
682NULL or the ERR_PTR mechanism to report failure. 682NULL or the ERR_PTR mechanism to report failure.
683 683
684 684
685 Chapter 17: Don't re-invent the kernel macros
686
687The header file include/linux/kernel.h contains a number of macros that
688you should use, rather than explicitly coding some variant of them yourself.
689For example, if you need to calculate the length of an array, take advantage
690of the macro
691
692 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
693
694Similarly, if you need to calculate the size of some structure member, use
695
696 #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
697
698There are also min() and max() macros that do strict type checking if you
699need them. Feel free to peruse that header file to see what else is already
700defined that you shouldn't reproduce in your code.
701
702
685 703
686 Appendix I: References 704 Appendix I: References
687 705