Skip to content

Commit b1a3459

Browse files
mchehabJonathan Corbet
authored andcommitted
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>
1 parent d8dbbbc commit b1a3459

1 file changed

Lines changed: 49 additions & 49 deletions

File tree

‎Documentation/CodingStyle‎

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ benefit of warning you when you're nesting your functions too deep.
3737
Heed that warning.
3838

3939
The preferred way to ease multiple indentation levels in a switch statement is
40-
to align the "switch" and its subordinate "case" labels in the same column
41-
instead of "double-indenting" the "case" labels. E.g.:
40+
to align the ``switch`` and its subordinate ``case`` labels in the same column
41+
instead of ``double-indenting`` the ``case`` labels. E.g.:
4242

4343
.. code-block:: c
4444

@@ -141,7 +141,7 @@ special anyway (you can't nest them in C).
141141

142142
Note that the closing brace is empty on a line of its own, _except_ in
143143
the cases where it is followed by a continuation of the same statement,
144-
ie a "while" in a do-statement or an "else" in an if-statement, like
144+
ie a ``while`` in a do-statement or an ``else`` in an if-statement, like
145145
this:
146146

147147
.. code-block:: c
@@ -228,7 +228,7 @@ Do not add spaces around (inside) parenthesized expressions. This example is
228228
s = sizeof( struct file );
229229

230230
When declaring pointer data or a function that returns a pointer type, the
231-
preferred use of '\*' is adjacent to the data name or function name and not
231+
preferred use of ``*`` is adjacent to the data name or function name and not
232232
adjacent to the type name. Examples:
233233

234234
.. code-block:: c
@@ -255,10 +255,10 @@ no space after the prefix increment & decrement unary operators::
255255

256256
++ --
257257

258-
and no space around the '.' and "->" structure member operators.
258+
and no space around the ``.`` and ``->`` structure member operators.
259259

260260
Do 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
262262
appropriate, so you can start typing the next line of code right away.
263263
However, some such editors do not remove the whitespace if you end up not
264264
putting a line of code there, such as if you leave a blank line. As a result,
@@ -276,27 +276,27 @@ context lines.
276276
C is a Spartan language, and so should your naming be. Unlike Modula-2
277277
and Pascal programmers, C programmers do not use cute names like
278278
ThisVariableIsATemporaryCounter. A C programmer would call that
279-
variable "tmp", which is much easier to write, and not the least more
279+
variable ``tmp``, which is much easier to write, and not the least more
280280
difficult to understand.
281281

282282
HOWEVER, while mixed-case names are frowned upon, descriptive names for
283-
global variables are a must. To call a global function "foo" is a
283+
global variables are a must. To call a global function ``foo`` is a
284284
shooting offense.
285285

286286
GLOBAL variables (to be used only if you _really_ need them) need to
287287
have descriptive names, as do global functions. If you have a function
288288
that 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()``.
290290

291291
Encoding the type of a function into the name (so-called Hungarian
292292
notation) is brain damaged - the compiler knows the types anyway and can
293293
check those, and it only confuses the programmer. No wonder MicroSoft
294294
makes buggy programs.
295295

296296
LOCAL variable names should be short, and to the point. If you have
297-
some random integer loop counter, it should probably be called "i".
298-
Calling it "loop_counter" is non-productive, if there is no chance of it
299-
being mis-understood. Similarly, "tmp" can be just about any type of
297+
some random integer loop counter, it should probably be called ``i``.
298+
Calling it ``loop_counter`` is non-productive, if there is no chance of it
299+
being mis-understood. Similarly, ``tmp`` can be just about any type of
300300
variable that is used to hold a temporary value.
301301

302302
If you are afraid to mix up your local variable names, you have another
@@ -307,7 +307,7 @@ See chapter 6 (Functions).
307307
5) Typedefs
308308
-----------
309309

310-
Please don't use things like "vps_t".
310+
Please don't use things like ``vps_t``.
311311
It's a _mistake_ to use typedef for structures and pointers. When you see a
312312

313313
.. code-block:: c
@@ -322,35 +322,35 @@ In contrast, if it says
322322

323323
struct virtual_container *a;
324324

325-
you can actually tell what "a" is.
325+
you can actually tell what ``a`` is.
326326

327-
Lots of people think that typedefs "help readability". Not so. They are
327+
Lots of people think that typedefs ``help readability``. Not so. They are
328328
useful only for:
329329

330330
(a) totally opaque objects (where the typedef is actively used to _hide_
331331
what the object is).
332332

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
334334
the proper accessor functions.
335335

336-
NOTE! Opaqueness and "accessor functions" are not good in themselves.
336+
NOTE! Opaqueness and ``accessor functions`` are not good in themselves.
337337
The reason we have them for things like pte_t etc. is that there
338338
really is absolutely _zero_ portably accessible information there.
339339

340340
(b) Clear integer types, where the abstraction _helps_ avoid confusion
341-
whether it is "int" or "long".
341+
whether it is ``int`` or ``long``.
342342

343343
u8/u16/u32 are perfectly fine typedefs, although they fit into
344344
category (d) better than here.
345345

346346
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
348348

349349
typedef unsigned long myflags_t;
350350

351351
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
353-
"unsigned long", then by all means go ahead and use a typedef.
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.
354354

355355
(c) when you use sparse to literally create a _new_ type for
356356
type-checking.
@@ -359,10 +359,10 @@ useful only for:
359359
exceptional circumstances.
360360

361361
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``,
363363
some people object to their use anyway.
364364

365-
Therefore, the Linux-specific 'u8/u16/u32/u64' types and their
365+
Therefore, the Linux-specific ``u8/u16/u32/u64`` types and their
366366
signed equivalents which are identical to standard types are
367367
permitted -- although they are not mandatory in new code of your
368368
own.
@@ -373,7 +373,7 @@ useful only for:
373373
(e) Types safe for use in userspace.
374374

375375
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
377377
use __u32 and similar types in all structures which are shared
378378
with userspace.
379379

@@ -440,13 +440,13 @@ locations and some common work such as cleanup has to be done. If there is no
440440
cleanup needed then just return directly.
441441

442442
Choose label names which say what the goto does or why the goto exists. An
443-
example of a good name could be "out_free_buffer:" if the goto frees "buffer".
444-
Avoid using GW-BASIC names like "err1:" and "err2:", as you would have to
443+
example of a good name could be ``out_free_buffer:`` if the goto frees ``buffer``.
444+
Avoid using GW-BASIC names like ``err1:`` and ``err2:``, as you would have to
445445
renumber them if you ever add or remove exit paths, and they make correctness
446446
difficult to verify anyway.
447447

448448
It 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.
450450

451451
The rationale for using gotos is:
452452

@@ -480,7 +480,7 @@ The rationale for using gotos is:
480480
return result;
481481
}
482482

483-
A common type of bug to be aware of is "one err bugs" which look like this:
483+
A common type of bug to be aware of is ``one err bugs`` which look like this:
484484

485485
.. code-block:: c
486486

@@ -489,9 +489,9 @@ A common type of bug to be aware of is "one err bugs" which look like this:
489489
kfree(foo);
490490
return ret;
491491

492-
The bug in this code is that on some exit paths "foo" is NULL. Normally the
493-
fix for this is to split it up into two error labels "err_free_bar:" and
494-
"err_free_foo:":
492+
The bug in this code is that on some exit paths ``foo`` is NULL. Normally the
493+
fix for this is to split it up into two error labels ``err_free_bar:`` and
494+
``err_free_foo:``:
495495

496496
.. code-block:: c
497497

@@ -560,7 +560,7 @@ item, explaining its use.
560560
---------------------------
561561

562562
That's OK, we all do. You've probably been told by your long-time Unix
563-
user helper that "GNU emacs" automatically formats the C sources for
563+
user helper that ``GNU emacs`` automatically formats the C sources for
564564
you, and you've noticed that yes, it does do that, but the defaults it
565565
uses are less than desirable (in fact, they are worse than random
566566
typing - 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
605605
files below ``~/src/linux-trees``.
606606

607607
But even if you fail in getting emacs to do sane formatting, not
608-
everything is lost: use "indent".
608+
everything is lost: use ``indent``.
609609

610610
Now, again, GNU indent has the same brain-dead settings that GNU emacs
611611
has, which is why you need to give it a few command line options.
612612
However, that's not too bad, because even the makers of GNU indent
613613
recognize the authority of K&R (the GNU people aren't evil, they are
614614
just severely misguided in this matter), so you just give indent the
615-
options "-kr -i8" (stands for "K&R, 8 character indents"), or use
616-
"scripts/Lindent", which indents in the latest style.
615+
options ``-kr -i8`` (stands for ``K&R, 8 character indents``), or use
616+
``scripts/Lindent``, which indents in the latest style.
617617

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
619619
re-formatting you may want to take a look at the man page. But
620-
remember: "indent" is not a fix for bad programming.
620+
remember: ``indent`` is not a fix for bad programming.
621621

622622

623623
10) Kconfig configuration files
624624
-------------------------------
625625

626626
For all of the Kconfig* configuration files throughout the source tree,
627-
the indentation is somewhat different. Lines under a "config" definition
627+
the indentation is somewhat different. Lines under a ``config`` definition
628628
are indented with one tab, while help text is indented an additional two
629629
spaces. Example::
630630

@@ -669,13 +669,13 @@ counting is a memory management technique. Usually both are needed, and
669669
they are not to be confused with each other.
670670

671671
Many data structures can indeed have two levels of reference counting,
672-
when there are users of different "classes". The subclass count counts
672+
when there are users of different ``classes``. The subclass count counts
673673
the number of subclass users, and decrements the global count just once
674674
when the subclass count goes to zero.
675675

676-
Examples of this kind of "multi-level-reference-counting" can be found in
677-
memory management ("struct mm_struct": mm_users and mm_count), and in
678-
filesystem code ("struct super_block": s_count and s_active).
676+
Examples of this kind of ``multi-level-reference-counting`` can be found in
677+
memory management (``struct mm_struct``: mm_users and mm_count), and in
678+
filesystem code (``struct super_block``: s_count and s_active).
679679

680680
Remember: if another thread can find your data structure, and you don't
681681
have a reference count on it, you almost certainly have a bug.
@@ -719,7 +719,7 @@ Things to avoid when using macros:
719719
return -EBUGGERED; \
720720
} while (0)
721721

722-
is a _very_ bad idea. It looks like a function call but exits the "calling"
722+
is a _very_ bad idea. It looks like a function call but exits the ``calling``
723723
function; don't break the internal parsers of those who will read the code.
724724

725725
2) 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.
767767

768768
Kernel developers like to be seen as literate. Do mind the spelling
769769
of kernel messages to make a good impression. Do not use crippled
770-
words like "dont"; use "do not" or "don't" instead. Make the messages
770+
words like ``dont``; use ``do not`` or ``don't`` instead. Make the messages
771771
concise, clear, and unambiguous.
772772

773773
Kernel messages do not have to be terminated with a period.
@@ -839,7 +839,7 @@ and return NULL if that occurred.
839839
----------------------
840840

841841
There appears to be a common misperception that gcc has a magic "make me
842-
faster" speedup option called "inline". While the use of inlines can be
842+
faster" speedup option called ``inline``. While the use of inlines can be
843843
appropriate (for example as a means of replacing macros, see Chapter 12), it
844844
very often is not. Abundant use of the inline keyword leads to a much bigger
845845
kernel, which in turn slows the system as a whole down, due to a bigger
@@ -869,7 +869,7 @@ something it would have done anyway.
869869
Functions can return values of many different kinds, and one of the
870870
most common is a value indicating whether the function succeeded or
871871
failed. 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,
873873
non-zero = success).
874874

875875
Mixing up these two sorts of representations is a fertile source of
@@ -882,8 +882,8 @@ convention::
882882
the function should return an error-code integer. If the name
883883
is a predicate, the function should return a "succeeded" boolean.
884884

885-
For example, "add work" is a command, and the add_work() function returns 0
886-
for success or -EBUSY for failure. In the same way, "PCI device present" is
885+
For example, ``add work`` is a command, and the add_work() function returns 0
886+
for success or -EBUSY for failure. In the same way, ``PCI device present`` is
887887
a predicate, and the pci_dev_present() function returns 1 if it succeeds in
888888
finding a matching device or 0 if it doesn't.
889889

@@ -969,7 +969,7 @@ that inline assembly can use C parameters.
969969

970970
Large, non-trivial assembly functions should go in .S files, with corresponding
971971
C prototypes defined in C header files. The C prototypes for assembly
972-
functions should use "asmlinkage".
972+
functions should use ``asmlinkage``.
973973

974974
You may need to mark your asm statement as volatile, to prevent GCC from
975975
removing it if GCC doesn't notice any side effects. You don't always need to

0 commit comments

Comments
 (0)