aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab@s-opensource.com>2016-09-19 07:07:45 -0400
committerJonathan Corbet <corbet@lwn.net>2016-09-20 20:36:53 -0400
commitb1a3459b00d601149d9171c0075ee35ea2d3bfde (patch)
tree434723e6654e479f03ae025fdd74557c1afc8bb0
parentd8dbbbc54f0e4f70453019d236028c36a482aee9 (diff)
Documentation/CodingStyle: use the proper tag for verbatim font
On Sphinx/ReST notation, ``foo`` means that foo will be will be marked as inline literal, effectively making it to be presented as a monospaced font. As we want this document to be parsed by Sphinx, instead of using "foo", use ``foo`` for the names that are literal, because it is an usual typographic convention to use monospaced fonts for functions and language commands on documents, and we're following such convention on the other ReST books. Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com> Signed-off-by: Jonathan Corbet <corbet@lwn.net>
-rw-r--r--Documentation/CodingStyle98
1 files changed, 49 insertions, 49 deletions
diff --git a/Documentation/CodingStyle b/Documentation/CodingStyle
index f103de7e2028..c25528d76af1 100644
--- a/Documentation/CodingStyle
+++ b/Documentation/CodingStyle
@@ -37,8 +37,8 @@ benefit of warning you when you're nesting your functions too deep.
37Heed that warning. 37Heed that warning.
38 38
39The preferred way to ease multiple indentation levels in a switch statement is 39The preferred way to ease multiple indentation levels in a switch statement is
40to align the "switch" and its subordinate "case" labels in the same column 40to align the ``switch`` and its subordinate ``case`` labels in the same column
41instead of "double-indenting" the "case" labels. E.g.: 41instead of ``double-indenting`` the ``case`` labels. E.g.:
42 42
43.. code-block:: c 43.. code-block:: c
44 44
@@ -141,7 +141,7 @@ special anyway (you can't nest them in C).
141 141
142Note that the closing brace is empty on a line of its own, _except_ in 142Note that the closing brace is empty on a line of its own, _except_ in
143the cases where it is followed by a continuation of the same statement, 143the cases where it is followed by a continuation of the same statement,
144ie a "while" in a do-statement or an "else" in an if-statement, like 144ie a ``while`` in a do-statement or an ``else`` in an if-statement, like
145this: 145this:
146 146
147.. code-block:: c 147.. code-block:: c
@@ -228,7 +228,7 @@ Do not add spaces around (inside) parenthesized expressions. This example is
228 s = sizeof( struct file ); 228 s = sizeof( struct file );
229 229
230When declaring pointer data or a function that returns a pointer type, the 230When declaring pointer data or a function that returns a pointer type, the
231preferred use of '\*' is adjacent to the data name or function name and not 231preferred use of ``*`` is adjacent to the data name or function name and not
232adjacent to the type name. Examples: 232adjacent to the type name. Examples:
233 233
234.. code-block:: c 234.. code-block:: c
@@ -255,10 +255,10 @@ no space after the prefix increment & decrement unary operators::
255 255
256 ++ -- 256 ++ --
257 257
258and no space around the '.' and "->" structure member operators. 258and no space around the ``.`` and ``->`` structure member operators.
259 259
260Do not leave trailing whitespace at the ends of lines. Some editors with 260Do not leave trailing whitespace at the ends of lines. Some editors with
261"smart" indentation will insert whitespace at the beginning of new lines as 261``smart`` indentation will insert whitespace at the beginning of new lines as
262appropriate, so you can start typing the next line of code right away. 262appropriate, so you can start typing the next line of code right away.
263However, some such editors do not remove the whitespace if you end up not 263However, some such editors do not remove the whitespace if you end up not
264putting a line of code there, such as if you leave a blank line. As a result, 264putting a line of code there, such as if you leave a blank line. As a result,
@@ -276,17 +276,17 @@ context lines.
276C is a Spartan language, and so should your naming be. Unlike Modula-2 276C is a Spartan language, and so should your naming be. Unlike Modula-2
277and Pascal programmers, C programmers do not use cute names like 277and Pascal programmers, C programmers do not use cute names like
278ThisVariableIsATemporaryCounter. A C programmer would call that 278ThisVariableIsATemporaryCounter. A C programmer would call that
279variable "tmp", which is much easier to write, and not the least more 279variable ``tmp``, which is much easier to write, and not the least more
280difficult to understand. 280difficult to understand.
281 281
282HOWEVER, while mixed-case names are frowned upon, descriptive names for 282HOWEVER, while mixed-case names are frowned upon, descriptive names for
283global variables are a must. To call a global function "foo" is a 283global variables are a must. To call a global function ``foo`` is a
284shooting offense. 284shooting offense.
285 285
286GLOBAL variables (to be used only if you _really_ need them) need to 286GLOBAL variables (to be used only if you _really_ need them) need to
287have descriptive names, as do global functions. If you have a function 287have descriptive names, as do global functions. If you have a function
288that counts the number of active users, you should call that 288that counts the number of active users, you should call that
289"count_active_users()" or similar, you should _not_ call it "cntusr()". 289``count_active_users()`` or similar, you should _not_ call it ``cntusr()``.
290 290
291Encoding the type of a function into the name (so-called Hungarian 291Encoding the type of a function into the name (so-called Hungarian
292notation) is brain damaged - the compiler knows the types anyway and can 292notation) is brain damaged - the compiler knows the types anyway and can
@@ -294,9 +294,9 @@ check those, and it only confuses the programmer. No wonder MicroSoft
294makes buggy programs. 294makes buggy programs.
295 295
296LOCAL variable names should be short, and to the point. If you have 296LOCAL variable names should be short, and to the point. If you have
297some random integer loop counter, it should probably be called "i". 297some random integer loop counter, it should probably be called ``i``.
298Calling it "loop_counter" is non-productive, if there is no chance of it 298Calling it ``loop_counter`` is non-productive, if there is no chance of it
299being mis-understood. Similarly, "tmp" can be just about any type of 299being mis-understood. Similarly, ``tmp`` can be just about any type of
300variable that is used to hold a temporary value. 300variable that is used to hold a temporary value.
301 301
302If you are afraid to mix up your local variable names, you have another 302If you are afraid to mix up your local variable names, you have another
@@ -307,7 +307,7 @@ See chapter 6 (Functions).
3075) Typedefs 3075) Typedefs
308----------- 308-----------
309 309
310Please don't use things like "vps_t". 310Please don't use things like ``vps_t``.
311It's a _mistake_ to use typedef for structures and pointers. When you see a 311It's a _mistake_ to use typedef for structures and pointers. When you see a
312 312
313.. code-block:: c 313.. code-block:: c
@@ -322,35 +322,35 @@ In contrast, if it says
322 322
323 struct virtual_container *a; 323 struct virtual_container *a;
324 324
325you can actually tell what "a" is. 325you can actually tell what ``a`` is.
326 326
327Lots of people think that typedefs "help readability". Not so. They are 327Lots of people think that typedefs ``help readability``. Not so. They are
328useful only for: 328useful only for:
329 329
330 (a) totally opaque objects (where the typedef is actively used to _hide_ 330 (a) totally opaque objects (where the typedef is actively used to _hide_
331 what the object is). 331 what the object is).
332 332
333 Example: "pte_t" etc. opaque objects that you can only access using 333 Example: ``pte_t`` etc. opaque objects that you can only access using
334 the proper accessor functions. 334 the proper accessor functions.
335 335
336 NOTE! Opaqueness and "accessor functions" are not good in themselves. 336 NOTE! Opaqueness and ``accessor functions`` are not good in themselves.
337 The reason we have them for things like pte_t etc. is that there 337 The reason we have them for things like pte_t etc. is that there
338 really is absolutely _zero_ portably accessible information there. 338 really is absolutely _zero_ portably accessible information there.
339 339
340 (b) Clear integer types, where the abstraction _helps_ avoid confusion 340 (b) Clear integer types, where the abstraction _helps_ avoid confusion
341 whether it is "int" or "long". 341 whether it is ``int`` or ``long``.
342 342
343 u8/u16/u32 are perfectly fine typedefs, although they fit into 343 u8/u16/u32 are perfectly fine typedefs, although they fit into
344 category (d) better than here. 344 category (d) better than here.
345 345
346 NOTE! Again - there needs to be a _reason_ for this. If something is 346 NOTE! Again - there needs to be a _reason_ for this. If something is
347 "unsigned long", then there's no reason to do 347 ``unsigned long``, then there's no reason to do
348 348
349 typedef unsigned long myflags_t; 349 typedef unsigned long myflags_t;
350 350
351 but if there is a clear reason for why it under certain circumstances 351 but if there is a clear reason for why it under certain circumstances
352 might be an "unsigned int" and under other configurations might be 352 might be an ``unsigned int`` and under other configurations might be
353 "unsigned long", then by all means go ahead and use a typedef. 353 ``unsigned long``, then by all means go ahead and use a typedef.
354 354
355 (c) when you use sparse to literally create a _new_ type for 355 (c) when you use sparse to literally create a _new_ type for
356 type-checking. 356 type-checking.
@@ -359,10 +359,10 @@ useful only for:
359 exceptional circumstances. 359 exceptional circumstances.
360 360
361 Although it would only take a short amount of time for the eyes and 361 Although it would only take a short amount of time for the eyes and
362 brain to become accustomed to the standard types like 'uint32_t', 362 brain to become accustomed to the standard types like ``uint32_t``,
363 some people object to their use anyway. 363 some people object to their use anyway.
364 364
365 Therefore, the Linux-specific 'u8/u16/u32/u64' types and their 365 Therefore, the Linux-specific ``u8/u16/u32/u64`` types and their
366 signed equivalents which are identical to standard types are 366 signed equivalents which are identical to standard types are
367 permitted -- although they are not mandatory in new code of your 367 permitted -- although they are not mandatory in new code of your
368 own. 368 own.
@@ -373,7 +373,7 @@ useful only for:
373 (e) Types safe for use in userspace. 373 (e) Types safe for use in userspace.
374 374
375 In certain structures which are visible to userspace, we cannot 375 In certain structures which are visible to userspace, we cannot
376 require C99 types and cannot use the 'u32' form above. Thus, we 376 require C99 types and cannot use the ``u32`` form above. Thus, we
377 use __u32 and similar types in all structures which are shared 377 use __u32 and similar types in all structures which are shared
378 with userspace. 378 with userspace.
379 379
@@ -440,13 +440,13 @@ locations and some common work such as cleanup has to be done. If there is no
440cleanup needed then just return directly. 440cleanup needed then just return directly.
441 441
442Choose label names which say what the goto does or why the goto exists. An 442Choose label names which say what the goto does or why the goto exists. An
443example of a good name could be "out_free_buffer:" if the goto frees "buffer". 443example of a good name could be ``out_free_buffer:`` if the goto frees ``buffer``.
444Avoid using GW-BASIC names like "err1:" and "err2:", as you would have to 444Avoid using GW-BASIC names like ``err1:`` and ``err2:``, as you would have to
445renumber them if you ever add or remove exit paths, and they make correctness 445renumber them if you ever add or remove exit paths, and they make correctness
446difficult to verify anyway. 446difficult to verify anyway.
447 447
448It is advised to indent labels with a single space (not tab), so that 448It is advised to indent labels with a single space (not tab), so that
449"diff -p" does not confuse labels with functions. 449``diff -p`` does not confuse labels with functions.
450 450
451The rationale for using gotos is: 451The rationale for using gotos is:
452 452
@@ -480,7 +480,7 @@ The rationale for using gotos is:
480 return result; 480 return result;
481 } 481 }
482 482
483A common type of bug to be aware of is "one err bugs" which look like this: 483A common type of bug to be aware of is ``one err bugs`` which look like this:
484 484
485.. code-block:: c 485.. code-block:: c
486 486
@@ -489,9 +489,9 @@ A common type of bug to be aware of is "one err bugs" which look like this:
489 kfree(foo); 489 kfree(foo);
490 return ret; 490 return ret;
491 491
492The bug in this code is that on some exit paths "foo" is NULL. Normally the 492The bug in this code is that on some exit paths ``foo`` is NULL. Normally the
493fix for this is to split it up into two error labels "err_free_bar:" and 493fix for this is to split it up into two error labels ``err_free_bar:`` and
494"err_free_foo:": 494``err_free_foo:``:
495 495
496.. code-block:: c 496.. code-block:: c
497 497
@@ -560,7 +560,7 @@ item, explaining its use.
560--------------------------- 560---------------------------
561 561
562That's OK, we all do. You've probably been told by your long-time Unix 562That's OK, we all do. You've probably been told by your long-time Unix
563user helper that "GNU emacs" automatically formats the C sources for 563user helper that ``GNU emacs`` automatically formats the C sources for
564you, and you've noticed that yes, it does do that, but the defaults it 564you, and you've noticed that yes, it does do that, but the defaults it
565uses are less than desirable (in fact, they are worse than random 565uses are less than desirable (in fact, they are worse than random
566typing - an infinite number of monkeys typing into GNU emacs would never 566typing - an infinite number of monkeys typing into GNU emacs would never
@@ -605,26 +605,26 @@ This will make emacs go better with the kernel coding style for C
605files below ``~/src/linux-trees``. 605files below ``~/src/linux-trees``.
606 606
607But even if you fail in getting emacs to do sane formatting, not 607But even if you fail in getting emacs to do sane formatting, not
608everything is lost: use "indent". 608everything is lost: use ``indent``.
609 609
610Now, again, GNU indent has the same brain-dead settings that GNU emacs 610Now, again, GNU indent has the same brain-dead settings that GNU emacs
611has, which is why you need to give it a few command line options. 611has, which is why you need to give it a few command line options.
612However, that's not too bad, because even the makers of GNU indent 612However, that's not too bad, because even the makers of GNU indent
613recognize the authority of K&R (the GNU people aren't evil, they are 613recognize the authority of K&R (the GNU people aren't evil, they are
614just severely misguided in this matter), so you just give indent the 614just severely misguided in this matter), so you just give indent the
615options "-kr -i8" (stands for "K&R, 8 character indents"), or use 615options ``-kr -i8`` (stands for ``K&R, 8 character indents``), or use
616"scripts/Lindent", which indents in the latest style. 616``scripts/Lindent``, which indents in the latest style.
617 617
618"indent" has a lot of options, and especially when it comes to comment 618``indent`` has a lot of options, and especially when it comes to comment
619re-formatting you may want to take a look at the man page. But 619re-formatting you may want to take a look at the man page. But
620remember: "indent" is not a fix for bad programming. 620remember: ``indent`` is not a fix for bad programming.
621 621
622 622
62310) Kconfig configuration files 62310) Kconfig configuration files
624------------------------------- 624-------------------------------
625 625
626For all of the Kconfig* configuration files throughout the source tree, 626For all of the Kconfig* configuration files throughout the source tree,
627the indentation is somewhat different. Lines under a "config" definition 627the indentation is somewhat different. Lines under a ``config`` definition
628are indented with one tab, while help text is indented an additional two 628are indented with one tab, while help text is indented an additional two
629spaces. Example:: 629spaces. Example::
630 630
@@ -669,13 +669,13 @@ counting is a memory management technique. Usually both are needed, and
669they are not to be confused with each other. 669they are not to be confused with each other.
670 670
671Many data structures can indeed have two levels of reference counting, 671Many data structures can indeed have two levels of reference counting,
672when there are users of different "classes". The subclass count counts 672when there are users of different ``classes``. The subclass count counts
673the number of subclass users, and decrements the global count just once 673the number of subclass users, and decrements the global count just once
674when the subclass count goes to zero. 674when the subclass count goes to zero.
675 675
676Examples of this kind of "multi-level-reference-counting" can be found in 676Examples of this kind of ``multi-level-reference-counting`` can be found in
677memory management ("struct mm_struct": mm_users and mm_count), and in 677memory management (``struct mm_struct``: mm_users and mm_count), and in
678filesystem code ("struct super_block": s_count and s_active). 678filesystem code (``struct super_block``: s_count and s_active).
679 679
680Remember: if another thread can find your data structure, and you don't 680Remember: if another thread can find your data structure, and you don't
681have a reference count on it, you almost certainly have a bug. 681have a reference count on it, you almost certainly have a bug.
@@ -719,7 +719,7 @@ Things to avoid when using macros:
719 return -EBUGGERED; \ 719 return -EBUGGERED; \
720 } while (0) 720 } while (0)
721 721
722is a _very_ bad idea. It looks like a function call but exits the "calling" 722is a _very_ bad idea. It looks like a function call but exits the ``calling``
723function; don't break the internal parsers of those who will read the code. 723function; don't break the internal parsers of those who will read the code.
724 724
7252) macros that depend on having a local variable with a magic name: 7252) macros that depend on having a local variable with a magic name:
@@ -767,7 +767,7 @@ covers RTL which is used frequently with assembly language in the kernel.
767 767
768Kernel developers like to be seen as literate. Do mind the spelling 768Kernel developers like to be seen as literate. Do mind the spelling
769of kernel messages to make a good impression. Do not use crippled 769of kernel messages to make a good impression. Do not use crippled
770words like "dont"; use "do not" or "don't" instead. Make the messages 770words like ``dont``; use ``do not`` or ``don't`` instead. Make the messages
771concise, clear, and unambiguous. 771concise, clear, and unambiguous.
772 772
773Kernel messages do not have to be terminated with a period. 773Kernel messages do not have to be terminated with a period.
@@ -839,7 +839,7 @@ and return NULL if that occurred.
839---------------------- 839----------------------
840 840
841There appears to be a common misperception that gcc has a magic "make me 841There appears to be a common misperception that gcc has a magic "make me
842faster" speedup option called "inline". While the use of inlines can be 842faster" speedup option called ``inline``. While the use of inlines can be
843appropriate (for example as a means of replacing macros, see Chapter 12), it 843appropriate (for example as a means of replacing macros, see Chapter 12), it
844very often is not. Abundant use of the inline keyword leads to a much bigger 844very often is not. Abundant use of the inline keyword leads to a much bigger
845kernel, which in turn slows the system as a whole down, due to a bigger 845kernel, which in turn slows the system as a whole down, due to a bigger
@@ -869,7 +869,7 @@ something it would have done anyway.
869Functions can return values of many different kinds, and one of the 869Functions can return values of many different kinds, and one of the
870most common is a value indicating whether the function succeeded or 870most common is a value indicating whether the function succeeded or
871failed. Such a value can be represented as an error-code integer 871failed. Such a value can be represented as an error-code integer
872(-Exxx = failure, 0 = success) or a "succeeded" boolean (0 = failure, 872(-Exxx = failure, 0 = success) or a ``succeeded`` boolean (0 = failure,
873non-zero = success). 873non-zero = success).
874 874
875Mixing up these two sorts of representations is a fertile source of 875Mixing up these two sorts of representations is a fertile source of
@@ -882,8 +882,8 @@ convention::
882 the function should return an error-code integer. If the name 882 the function should return an error-code integer. If the name
883 is a predicate, the function should return a "succeeded" boolean. 883 is a predicate, the function should return a "succeeded" boolean.
884 884
885For example, "add work" is a command, and the add_work() function returns 0 885For example, ``add work`` is a command, and the add_work() function returns 0
886for success or -EBUSY for failure. In the same way, "PCI device present" is 886for success or -EBUSY for failure. In the same way, ``PCI device present`` is
887a predicate, and the pci_dev_present() function returns 1 if it succeeds in 887a predicate, and the pci_dev_present() function returns 1 if it succeeds in
888finding a matching device or 0 if it doesn't. 888finding a matching device or 0 if it doesn't.
889 889
@@ -969,7 +969,7 @@ that inline assembly can use C parameters.
969 969
970Large, non-trivial assembly functions should go in .S files, with corresponding 970Large, non-trivial assembly functions should go in .S files, with corresponding
971C prototypes defined in C header files. The C prototypes for assembly 971C prototypes defined in C header files. The C prototypes for assembly
972functions should use "asmlinkage". 972functions should use ``asmlinkage``.
973 973
974You may need to mark your asm statement as volatile, to prevent GCC from 974You may need to mark your asm statement as volatile, to prevent GCC from
975removing it if GCC doesn't notice any side effects. You don't always need to 975removing it if GCC doesn't notice any side effects. You don't always need to