From 624ab1ae0c081af6e8269504b7fa9661162e5033 Mon Sep 17 00:00:00 2001 From: "Robert P. J. Day" Date: Fri, 22 Dec 2006 01:09:11 -0800 Subject: [PATCH] --- yaml --- r: 44891 b: refs/heads/master c: 58637ec90b7ceed5909e726ac90118852f79d2b1 h: refs/heads/master i: 44889: cc0de9c01f930e069802ca59361e70153a068a75 44887: 1eaedf61cabc7f174cf71dd1d0b89afae59f9bf2 v: v3 --- [refs] | 2 +- trunk/Documentation/CodingStyle | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/[refs] b/[refs] index b86c07d01ee0..e8afa726a5b4 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 163ca88b9c5858909ee3f8801ae0096b5f94e835 +refs/heads/master: 58637ec90b7ceed5909e726ac90118852f79d2b1 diff --git a/trunk/Documentation/CodingStyle b/trunk/Documentation/CodingStyle index 0ad6dcb5d45f..9069189e78ef 100644 --- a/trunk/Documentation/CodingStyle +++ b/trunk/Documentation/CodingStyle @@ -682,6 +682,24 @@ result. Typical examples would be functions that return pointers; they use NULL or the ERR_PTR mechanism to report failure. + Chapter 17: Don't re-invent the kernel macros + +The header file include/linux/kernel.h contains a number of macros that +you should use, rather than explicitly coding some variant of them yourself. +For example, if you need to calculate the length of an array, take advantage +of the macro + + #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) + +Similarly, if you need to calculate the size of some structure member, use + + #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f)) + +There are also min() and max() macros that do strict type checking if you +need them. Feel free to peruse that header file to see what else is already +defined that you shouldn't reproduce in your code. + + Appendix I: References