diff options
40 files changed, 490 insertions, 778 deletions
diff --git a/Documentation/CodingStyle b/Documentation/CodingStyle index 4d4f06d47e06..f4b78eafd92a 100644 --- a/Documentation/CodingStyle +++ b/Documentation/CodingStyle | |||
| @@ -13,7 +13,7 @@ and NOT read it. Burn them, it's a great symbolic gesture. | |||
| 13 | Anyway, here goes: | 13 | Anyway, here goes: |
| 14 | 14 | ||
| 15 | 15 | ||
| 16 | Chapter 1: Indentation | 16 | Chapter 1: Indentation |
| 17 | 17 | ||
| 18 | Tabs are 8 characters, and thus indentations are also 8 characters. | 18 | Tabs are 8 characters, and thus indentations are also 8 characters. |
| 19 | There are heretic movements that try to make indentations 4 (or even 2!) | 19 | There are heretic movements that try to make indentations 4 (or even 2!) |
| @@ -56,7 +56,6 @@ instead of "double-indenting" the "case" labels. E.g.: | |||
| 56 | break; | 56 | break; |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | |||
| 60 | Don't put multiple statements on a single line unless you have | 59 | Don't put multiple statements on a single line unless you have |
| 61 | something to hide: | 60 | something to hide: |
| 62 | 61 | ||
| @@ -156,25 +155,25 @@ comments on. | |||
| 156 | 155 | ||
| 157 | Do not unnecessarily use braces where a single statement will do. | 156 | Do not unnecessarily use braces where a single statement will do. |
| 158 | 157 | ||
| 159 | if (condition) | 158 | if (condition) |
| 160 | action(); | 159 | action(); |
| 161 | 160 | ||
| 162 | and | 161 | and |
| 163 | 162 | ||
| 164 | if (condition) | 163 | if (condition) |
| 165 | do_this(); | 164 | do_this(); |
| 166 | else | 165 | else |
| 167 | do_that(); | 166 | do_that(); |
| 168 | 167 | ||
| 169 | This does not apply if only one branch of a conditional statement is a single | 168 | This does not apply if only one branch of a conditional statement is a single |
| 170 | statement; in the latter case use braces in both branches: | 169 | statement; in the latter case use braces in both branches: |
| 171 | 170 | ||
| 172 | if (condition) { | 171 | if (condition) { |
| 173 | do_this(); | 172 | do_this(); |
| 174 | do_that(); | 173 | do_that(); |
| 175 | } else { | 174 | } else { |
| 176 | otherwise(); | 175 | otherwise(); |
| 177 | } | 176 | } |
| 178 | 177 | ||
| 179 | 3.1: Spaces | 178 | 3.1: Spaces |
| 180 | 179 | ||
| @@ -186,8 +185,11 @@ although they are not required in the language, as in: "sizeof info" after | |||
| 186 | "struct fileinfo info;" is declared). | 185 | "struct fileinfo info;" is declared). |
| 187 | 186 | ||
| 188 | So use a space after these keywords: | 187 | So use a space after these keywords: |
| 188 | |||
| 189 | if, switch, case, for, do, while | 189 | if, switch, case, for, do, while |
| 190 | |||
| 190 | but not with sizeof, typeof, alignof, or __attribute__. E.g., | 191 | but not with sizeof, typeof, alignof, or __attribute__. E.g., |
| 192 | |||
| 191 | s = sizeof(struct file); | 193 | s = sizeof(struct file); |
| 192 | 194 | ||
| 193 | Do not add spaces around (inside) parenthesized expressions. This example is | 195 | Do not add spaces around (inside) parenthesized expressions. This example is |
| @@ -209,12 +211,15 @@ such as any of these: | |||
| 209 | = + - < > * / % | & ^ <= >= == != ? : | 211 | = + - < > * / % | & ^ <= >= == != ? : |
| 210 | 212 | ||
| 211 | but no space after unary operators: | 213 | but no space after unary operators: |
| 214 | |||
| 212 | & * + - ~ ! sizeof typeof alignof __attribute__ defined | 215 | & * + - ~ ! sizeof typeof alignof __attribute__ defined |
| 213 | 216 | ||
| 214 | no space before the postfix increment & decrement unary operators: | 217 | no space before the postfix increment & decrement unary operators: |
| 218 | |||
| 215 | ++ -- | 219 | ++ -- |
| 216 | 220 | ||
| 217 | no space after the prefix increment & decrement unary operators: | 221 | no space after the prefix increment & decrement unary operators: |
| 222 | |||
| 218 | ++ -- | 223 | ++ -- |
| 219 | 224 | ||
| 220 | and no space around the '.' and "->" structure member operators. | 225 | and no space around the '.' and "->" structure member operators. |
| @@ -268,13 +273,11 @@ See chapter 6 (Functions). | |||
| 268 | Chapter 5: Typedefs | 273 | Chapter 5: Typedefs |
| 269 | 274 | ||
| 270 | Please don't use things like "vps_t". | 275 | Please don't use things like "vps_t". |
| 271 | |||
| 272 | It's a _mistake_ to use typedef for structures and pointers. When you see a | 276 | It's a _mistake_ to use typedef for structures and pointers. When you see a |
| 273 | 277 | ||
| 274 | vps_t a; | 278 | vps_t a; |
| 275 | 279 | ||
| 276 | in the source, what does it mean? | 280 | in the source, what does it mean? |
| 277 | |||
| 278 | In contrast, if it says | 281 | In contrast, if it says |
| 279 | 282 | ||
| 280 | struct virtual_container *a; | 283 | struct virtual_container *a; |
| @@ -372,11 +375,11 @@ In source files, separate functions with one blank line. If the function is | |||
| 372 | exported, the EXPORT* macro for it should follow immediately after the closing | 375 | exported, the EXPORT* macro for it should follow immediately after the closing |
| 373 | function brace line. E.g.: | 376 | function brace line. E.g.: |
| 374 | 377 | ||
| 375 | int system_is_up(void) | 378 | int system_is_up(void) |
| 376 | { | 379 | { |
| 377 | return system_state == SYSTEM_RUNNING; | 380 | return system_state == SYSTEM_RUNNING; |
| 378 | } | 381 | } |
| 379 | EXPORT_SYMBOL(system_is_up); | 382 | EXPORT_SYMBOL(system_is_up); |
| 380 | 383 | ||
| 381 | In function prototypes, include parameter names with their data types. | 384 | In function prototypes, include parameter names with their data types. |
| 382 | Although this is not required by the C language, it is preferred in Linux | 385 | Although this is not required by the C language, it is preferred in Linux |
| @@ -405,34 +408,34 @@ The rationale for using gotos is: | |||
| 405 | modifications are prevented | 408 | modifications are prevented |
| 406 | - saves the compiler work to optimize redundant code away ;) | 409 | - saves the compiler work to optimize redundant code away ;) |
