X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;ds=sidebyside;f=Documentation%2FCodingStyle;h=9069189e78ef3c7ec272bbeebda291d509b2b66a;hb=5f3162f0664be49c72c1e6ce4a46848f9d96d790;hp=0ad6dcb5d45ffd0f9f7e5ae1d64044afa51b1b8b;hpb=741441ab7800f1eb031e74fd720f4f8f361678ed;p=powerpc.git diff --git a/Documentation/CodingStyle b/Documentation/CodingStyle index 0ad6dcb5d4..9069189e78 100644 --- a/Documentation/CodingStyle +++ b/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