€•Œsphinx.addnodes”Œdocument”“”)�”}”(Œ rawsource”Œ”Œchildren”]”(Œ translations”Œ LanguagesNode”“”)�”}”(hhh]”(hŒ pending_xref”“”)�”}”(hhh]”Œdocutils.nodes”ŒText”“”ŒChinese (Simplified)”…”�”}”Œparent”hsbaŒ attributes”}”(Œids”]”Œclasses”]”Œnames”]”Œdupnames”]”Œbackrefs”]”Œ refdomain”Œstd”Œreftype”Œdoc”Œ reftarget”Œ(/translations/zh_CN/process/coding-style”Œmodname”NŒ classname”NŒ refexplicit”ˆuŒtagname”hhh ubh)�”}”(hhh]”hŒChinese (Traditional)”…”�”}”hh2sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ(/translations/zh_TW/process/coding-style”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)�”}”(hhh]”hŒItalian”…”�”}”hhFsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ(/translations/it_IT/process/coding-style”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)�”}”(hhh]”hŒJapanese”…”�”}”hhZsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ(/translations/ja_JP/process/coding-style”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)�”}”(hhh]”hŒKorean”…”�”}”hhnsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ(/translations/ko_KR/process/coding-style”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)�”}”(hhh]”hŒPortuguese (Brazilian)”…”�”}”hh‚sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ(/translations/pt_BR/process/coding-style”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)�”}”(hhh]”hŒSpanish”…”�”}”hh–sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ(/translations/sp_SP/process/coding-style”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubeh}”(h]”h ]”h"]”h$]”h&]”Œcurrent_language”ŒEnglish”uh1h hhŒ _document”hŒsource”NŒline”NubhŒtarget”“”)�”}”(hŒ.. _codingstyle:”h]”h}”(h]”h ]”h"]”h$]”h&]”Œrefid”Œ codingstyle”uh1hµh´Khhh²hh³ŒB/var/lib/git/docbuild/linux/Documentation/process/coding-style.rst”ubhŒsection”“”)�”}”(hhh]”(hŒtitle”“”)�”}”(hŒLinux kernel coding style”h]”hŒLinux kernel coding style”…”�”}”(hhËh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhhÆh²hh³hÃh´KubhŒ paragraph”“”)�”}”(hXCThis is a short document describing the preferred coding style for the linux kernel. Coding style is very personal, and I won't **force** my views on anybody, but this is what goes for anything that I have to be able to maintain, and I'd prefer it for most other things too. Please at least consider the points made here.”h]”(hŒƒThis is a short document describing the preferred coding style for the linux kernel. Coding style is very personal, and I won’t ”…”�”}”(hhÛh²hh³Nh´NubhŒstrong”“”)�”}”(hŒ **force**”h]”hŒforce”…”�”}”(hhåh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hãhhÛubhŒ» my views on anybody, but this is what goes for anything that I have to be able to maintain, and I’d prefer it for most other things too. Please at least consider the points made here.”…”�”}”(hhÛh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´KhhÆh²hubhÚ)�”}”(hŒƒFirst off, I'd suggest printing out a copy of the GNU coding standards, and NOT read it. Burn them, it's a great symbolic gesture.”h]”hŒ‡First off, I’d suggest printing out a copy of the GNU coding standards, and NOT read it. Burn them, it’s a great symbolic gesture.”…”�”}”(hhýh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´K hhÆh²hubhÚ)�”}”(hŒAnyway, here goes:”h]”hŒAnyway, here goes:”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´KhhÆh²hubhÅ)�”}”(hhh]”(hÊ)�”}”(hŒ1) Indentation”h]”hŒ1) Indentation”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhjh²hh³hÃh´KubhÚ)�”}”(hŒÛTabs are 8 characters, and thus indentations are also 8 characters. There are heretic movements that try to make indentations 4 (or even 2!) characters deep, and that is akin to trying to define the value of PI to be 3.”h]”hŒÛTabs are 8 characters, and thus indentations are also 8 characters. There are heretic movements that try to make indentations 4 (or even 2!) characters deep, and that is akin to trying to define the value of PI to be 3.”…”�”}”(hj*h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´Khjh²hubhÚ)�”}”(hXRationale: The whole idea behind indentation is to clearly define where a block of control starts and ends. Especially when you've been looking at your screen for 20 straight hours, you'll find it a lot easier to see how the indentation works if you have large indentations.”h]”hXRationale: The whole idea behind indentation is to clearly define where a block of control starts and ends. Especially when you’ve been looking at your screen for 20 straight hours, you’ll find it a lot easier to see how the indentation works if you have large indentations.”…”�”}”(hj8h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´Khjh²hubhÚ)�”}”(hX&Now, some people will claim that having 8-character indentations makes the code move too far to the right, and makes it hard to read on a 80-character terminal screen. The answer to that is that if you need more than 3 levels of indentation, you're screwed anyway, and should fix your program.”h]”hX(Now, some people will claim that having 8-character indentations makes the code move too far to the right, and makes it hard to read on a 80-character terminal screen. The answer to that is that if you need more than 3 levels of indentation, you’re screwed anyway, and should fix your program.”…”�”}”(hjFh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´Khjh²hubhÚ)�”}”(hŒžIn short, 8-char indents make things easier to read, and have the added benefit of warning you when you're nesting your functions too deep. Heed that warning.”h]”hŒ In short, 8-char indents make things easier to read, and have the added benefit of warning you when you’re nesting your functions too deep. Heed that warning.”…”�”}”(hjTh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´K%hjh²hubhÚ)�”}”(hŒÙThe preferred way to ease multiple indentation levels in a switch statement is to align the ``switch`` and its subordinate ``case`` labels in the same column instead of ``double-indenting`` the ``case`` labels. E.g.:”h]”(hŒ\The preferred way to ease multiple indentation levels in a switch statement is to align the ”…”�”}”(hjbh²hh³Nh´NubhŒliteral”“”)�”}”(hŒ ``switch``”h]”hŒswitch”…”�”}”(hjlh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhjbubhŒ and its subordinate ”…”�”}”(hjbh²hh³Nh´Nubjk)�”}”(hŒ``case``”h]”hŒcase”…”�”}”(hj~h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhjbubhŒ& labels in the same column instead of ”…”�”}”(hjbh²hh³Nh´Nubjk)�”}”(hŒ``double-indenting``”h]”hŒdouble-indenting”…”�”}”(hj�h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhjbubhŒ the ”…”�”}”(hjbh²hh³Nh´Nubjk)�”}”(hŒ``case``”h]”hŒcase”…”�”}”(hj¢h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhjbubhŒ labels. E.g.:”…”�”}”(hjbh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´K)hjh²hubhŒ literal_block”“”)�”}”(hŒÖswitch (suffix) { case 'G': case 'g': mem <<= 30; break; case 'M': case 'm': mem <<= 20; break; case 'K': case 'k': mem <<= 10; fallthrough; default: break; }”h]”hŒÖswitch (suffix) { case 'G': case 'g': mem <<= 30; break; case 'M': case 'm': mem <<= 20; break; case 'K': case 'k': mem <<= 10; fallthrough; default: break; }”…”�”}”hj¼sbah}”(h]”h ]”h"]”h$]”h&]”Œ xml:space”Œpreserve”Œforce”‰Œlanguage”Œc”Œhighlight_args”}”uh1jºh³hÃh´K-hjh²hubhÚ)�”}”(hŒQDon't put multiple statements on a single line unless you have something to hide:”h]”hŒSDon’t put multiple statements on a single line unless you have something to hide:”…”�”}”(hjÑh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´K@hjh²hubj»)�”}”(hŒ1if (condition) do_this; do_something_everytime;”h]”hŒ1if (condition) do_this; do_something_everytime;”…”�”}”hjßsbah}”(h]”h ]”h"]”h$]”h&]”jÊjËj̉jÍjÎjÏ}”uh1jºh³hÃh´KChjh²hubhÚ)�”}”(hŒ'Don't use commas to avoid using braces:”h]”hŒ)Don’t use commas to avoid using braces:”…”�”}”(hjîh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´KHhjh²hubj»)�”}”(hŒ,if (condition) do_this(), do_that();”h]”hŒ,if (condition) do_this(), do_that();”…”�”}”hjüsbah}”(h]”h ]”h"]”h$]”h&]”jÊjËj̉jÍjÎjÏ}”uh1jºh³hÃh´KJhjh²hubhÚ)�”}”(hŒ*Always use braces for multiple statements:”h]”hŒ*Always use braces for multiple statements:”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´KOhjh²hubj»)�”}”(hŒ8if (condition) { do_this(); do_that(); }”h]”hŒ8if (condition) { do_this(); do_that(); }”…”�”}”hjsbah}”(h]”h ]”h"]”h$]”h&]”jÊjËj̉jÍjÎjÏ}”uh1jºh³hÃh´KQhjh²hubhÚ)�”}”(hŒxDon't put multiple assignments on a single line either. Kernel coding style is super simple. Avoid tricky expressions.”h]”hŒzDon’t put multiple assignments on a single line either. Kernel coding style is super simple. Avoid tricky expressions.”…”�”}”(hj(h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´KXhjh²hubhÚ)�”}”(hŒŽOutside of comments, documentation and except in Kconfig, spaces are never used for indentation, and the above example is deliberately broken.”h]”hŒŽOutside of comments, documentation and except in Kconfig, spaces are never used for indentation, and the above example is deliberately broken.”…”�”}”(hj6h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´K\hjh²hubhÚ)�”}”(hŒCGet a decent editor and don't leave whitespace at the end of lines.”h]”hŒEGet a decent editor and don’t leave whitespace at the end of lines.”…”�”}”(hjDh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´K_hjh²hubeh}”(h]”Œ indentation”ah ]”h"]”Œ1) indentation”ah$]”h&]”uh1hÄhhÆh²hh³hÃh´KubhÅ)�”}”(hhh]”(hÊ)�”}”(hŒ"2) Breaking long lines and strings”h]”hŒ"2) Breaking long lines and strings”…”�”}”(hj]h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhjZh²hh³hÃh´KcubhÚ)�”}”(hŒYCoding style is all about readability and maintainability using commonly available tools.”h]”hŒYCoding style is all about readability and maintainability using commonly available tools.”…”�”}”(hjkh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´KehjZh²hubhÚ)�”}”(hŒAThe preferred limit on the length of a single line is 80 columns.”h]”hŒAThe preferred limit on the length of a single line is 80 columns.”…”�”}”(hjyh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´KhhjZh²hubhÚ)�”}”(hŒ§Statements longer than 80 columns should be broken into sensible chunks, unless exceeding 80 columns significantly increases readability and does not hide information.”h]”hŒ§Statements longer than 80 columns should be broken into sensible chunks, unless exceeding 80 columns significantly increases readability and does not hide information.”…”�”}”(hj‡h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´KjhjZh²hubhÚ)�”}”(hŒ»Descendants are always substantially shorter than the parent and are placed substantially to the right. A very commonly used style is to align descendants to a function open parenthesis.”h]”hŒ»Descendants are always substantially shorter than the parent and are placed substantially to the right. A very commonly used style is to align descendants to a function open parenthesis.”…”�”}”(hj•h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´KnhjZh²hubhÚ)�”}”(hŒKThese same rules are applied to function headers with a long argument list.”h]”hŒKThese same rules are applied to function headers with a long argument list.”…”�”}”(hj£h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´KrhjZh²hubhÚ)�”}”(hŒsHowever, never break user-visible strings such as printk messages because that breaks the ability to grep for them.”h]”hŒsHowever, never break user-visible strings such as printk messages because that breaks the ability to grep for them.”…”�”}”(hj±h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´KthjZh²hubeh}”(h]”Œbreaking-long-lines-and-strings”ah ]”h"]”Œ"2) breaking long lines and strings”ah$]”h&]”uh1hÄhhÆh²hh³hÃh´KcubhÅ)�”}”(hhh]”(hÊ)�”}”(hŒ3) Placing Braces and Spaces”h]”hŒ3) Placing Braces and Spaces”…”�”}”(hjÊh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhjÇh²hh³hÃh´KyubhÚ)�”}”(hX[The other issue that always comes up in C styling is the placement of braces. Unlike the indent size, there are few technical reasons to choose one placement strategy over the other, but the preferred way, as shown to us by the prophets Kernighan and Ritchie, is to put the opening brace last on the line, and put the closing brace first, thusly:”h]”hX[The other issue that always comes up in C styling is the placement of braces. Unlike the indent size, there are few technical reasons to choose one placement strategy over the other, but the preferred way, as shown to us by the prophets Kernighan and Ritchie, is to put the opening brace last on the line, and put the closing brace first, thusly:”…”�”}”(hjØh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´K{hjÇh²hubj»)�”}”(hŒ"if (x is true) { we do y }”h]”hŒ"if (x is true) { we do y }”…”�”}”hjæsbah}”(h]”h ]”h"]”h$]”h&]”jÊjËj̉jÍjÎjÏ}”uh1jºh³hÃh´K�hjÇh²hubhÚ)�”}”(hŒVThis applies to all non-function statement blocks (if, switch, for, while, do). E.g.:”h]”hŒVThis applies to all non-function statement blocks (if, switch, for, while, do). E.g.:”…”�”}”(hjõh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´K‡hjÇh²hubj»)�”}”(hŒ¬switch (action) { case KOBJ_ADD: return "add"; case KOBJ_REMOVE: return "remove"; case KOBJ_CHANGE: return "change"; default: return NULL; }”h]”hŒ¬switch (action) { case KOBJ_ADD: return "add"; case KOBJ_REMOVE: return "remove"; case KOBJ_CHANGE: return "change"; default: return NULL; }”…”�”}”hjsbah}”(h]”h ]”h"]”h$]”h&]”jÊjËj̉jÍjÎjÏ}”uh1jºh³hÃh´KŠhjÇh²hubhÚ)�”}”(hŒzHowever, there is one special case, namely functions: they have the opening brace at the beginning of the next line, thus:”h]”hŒzHowever, there is one special case, namely functions: they have the opening brace at the beginning of the next line, thus:”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´K—hjÇh²hubj»)�”}”(hŒ0int function(int x) { body of function }”h]”hŒ0int function(int x) { body of function }”…”�”}”hj sbah}”(h]”h ]”h"]”h$]”h&]”jÊjËj̉jÍjÎjÏ}”uh1jºh³hÃh´KšhjÇh²hubhÚ)�”}”(hŒþHeretic people all over the world have claimed that this inconsistency is ... well ... inconsistent, but all right-thinking people know that (a) K&R are **right** and (b) K&R are right. Besides, functions are special anyway (you can't nest them in C).”h]”(hŒ›Heretic people all over the world have claimed that this inconsistency is ... well ... inconsistent, but all right-thinking people know that (a) K&R are ”…”�”}”(hj/h²hh³Nh´Nubhä)�”}”(hŒ **right**”h]”hŒright”…”�”}”(hj7h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hãhj/ubhŒ\ and (b) K&R are right. Besides, functions are special anyway (you can’t nest them in C).”…”�”}”(hj/h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´K¡hjÇh²hubhÚ)�”}”(hŒßNote that the closing brace is empty on a line of its own, **except** in the cases where it is followed by a continuation of the same statement, ie a ``while`` in a do-statement or an ``else`` in an if-statement, like this:”h]”(hŒ;Note that the closing brace is empty on a line of its own, ”…”�”}”(hjOh²hh³Nh´Nubhä)�”}”(hŒ **except**”h]”hŒexcept”…”�”}”(hjWh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hãhjOubhŒQ in the cases where it is followed by a continuation of the same statement, ie a ”…”�”}”(hjOh²hh³Nh´Nubjk)�”}”(hŒ ``while``”h]”hŒwhile”…”�”}”(hjih²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhjOubhŒ in a do-statement or an ”…”�”}”(hjOh²hh³Nh´Nubjk)�”}”(hŒ``else``”h]”hŒelse”…”�”}”(hj{h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhjOubhŒ in an if-statement, like this:”…”�”}”(hjOh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´K¦hjÇh²hubj»)�”}”(hŒ1do { body of do-loop } while (condition);”h]”hŒ1do { body of do-loop } while (condition);”…”�”}”hj“sbah}”(h]”h ]”h"]”h$]”h&]”jÊjËj̉jÍjÎjÏ}”uh1jºh³hÃh´K«hjÇh²hubhÚ)�”}”(hŒand”h]”hŒand”…”�”}”(hj¢h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´K±hjÇh²hubj»)�”}”(hŒPif (x == y) { .. } else if (x > y) { ... } else { .... }”h]”hŒPif (x == y) { .. } else if (x > y) { ... } else { .... }”…”�”}”hj°sbah}”(h]”h ]”h"]”h$]”h&]”jÊjËj̉jÍjÎjÏ}”uh1jºh³hÃh´K³hjÇh²hubhÚ)�”}”(hŒRationale: K&R.”h]”hŒRationale: K&R.”…”�”}”(hj¿h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´K½hjÇh²hubhÚ)�”}”(hX#Also, note that this brace-placement also minimizes the number of empty (or almost empty) lines, without any loss of readability. Thus, as the supply of new-lines on your screen is not a renewable resource (think 25-line terminal screens here), you have more empty lines to put comments on.”h]”hX#Also, note that this brace-placement also minimizes the number of empty (or almost empty) lines, without any loss of readability. Thus, as the supply of new-lines on your screen is not a renewable resource (think 25-line terminal screens here), you have more empty lines to put comments on.”…”�”}”(hjÍh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´K¿hjÇh²hubhÚ)�”}”(hŒADo not unnecessarily use braces where a single statement will do.”h]”hŒADo not unnecessarily use braces where a single statement will do.”…”�”}”(hjÛh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´KÅhjÇh²hubj»)�”}”(hŒ if (condition) action();”h]”hŒ if (condition) action();”…”�”}”hjésbah}”(h]”h ]”h"]”h$]”h&]”jÊjËj̉jÍjÎjÏ}”uh1jºh³hÃh´KÇhjÇh²hubhÚ)�”}”(hŒand”h]”hŒand”…”�”}”(hjøh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´KÌhjÇh²hubj»)�”}”(hŒ9if (condition) do_this(); else do_that();”h]”hŒ9if (condition) do_this(); else do_that();”…”�”}”hjsbah}”(h]”h ]”h"]”h$]”h&]”jÊjËj̉jÍjÎjÏ}”uh1jºh³hÃh´KÎhjÇh²hubhÚ)�”}”(hŒˆThis does not apply if only one branch of a conditional statement is a single statement; in the latter case use braces in both branches:”h]”hŒˆThis does not apply if only one branch of a conditional statement is a single statement; in the latter case use braces in both branches:”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´KÕhjÇh²hubj»)�”}”(hŒVif (condition) { do_this(); do_that(); } else { otherwise(); }”h]”hŒVif (condition) { do_this(); do_that(); } else { otherwise(); }”…”�”}”hj#sbah}”(h]”h ]”h"]”h$]”h&]”jÊjËj̉jÍjÎjÏ}”uh1jºh³hÃh´KØhjÇh²hubhÚ)�”}”(hŒJAlso, use braces when a loop contains more than a single simple statement:”h]”hŒJAlso, use braces when a loop contains more than a single simple statement:”…”�”}”(hj2h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´KáhjÇh²hubj»)�”}”(hŒGwhile (condition) { if (test) do_something(); }”h]”hŒGwhile (condition) { if (test) do_something(); }”…”�”}”hj@sbah}”(h]”h ]”h"]”h$]”h&]”jÊjËj̉jÍjÎjÏ}”uh1jºh³hÃh´KãhjÇh²hubhÅ)�”}”(hhh]”(hÊ)�”}”(hŒ 3.1) Spaces”h]”hŒ 3.1) Spaces”…”�”}”(hjRh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhjOh²hh³hÃh´KëubhÚ)�”}”(hXŒLinux kernel style for use of spaces depends (mostly) on function-versus-keyword usage. Use a space after (most) keywords. The notable exceptions are sizeof, typeof, alignof, and __attribute__, which look somewhat like functions (and are usually used with parentheses in Linux, although they are not required in the language, as in: ``sizeof info`` after ``struct fileinfo info;`` is declared).”h]”(hXOLinux kernel style for use of spaces depends (mostly) on function-versus-keyword usage. Use a space after (most) keywords. The notable exceptions are sizeof, typeof, alignof, and __attribute__, which look somewhat like functions (and are usually used with parentheses in Linux, although they are not required in the language, as in: ”…”�”}”(hj`h²hh³Nh´Nubjk)�”}”(hŒ``sizeof info``”h]”hŒ sizeof info”…”�”}”(hjhh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhj`ubhŒ after ”…”�”}”(hj`h²hh³Nh´Nubjk)�”}”(hŒ``struct fileinfo info;``”h]”hŒstruct fileinfo info;”…”�”}”(hjzh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhj`ubhŒ is declared).”…”�”}”(hj`h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´KíhjOh²hubhÚ)�”}”(hŒ%So use a space after these keywords::”h]”hŒ$So use a space after these keywords:”…”�”}”(hj’h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´KôhjOh²hubj»)�”}”(hŒ if, switch, case, for, do, while”h]”hŒ if, switch, case, for, do, while”…”�”}”hj sbah}”(h]”h ]”h"]”h$]”h&]”jÊjËuh1jºh³hÃh´KöhjOh²hubhÚ)�”}”(hŒ>but not with sizeof, typeof, alignof, or __attribute__. E.g.,”h]”hŒ>but not with sizeof, typeof, alignof, or __attribute__. E.g.,”…”�”}”(hj®h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´KøhjOh²hubj»)�”}”(hŒs = sizeof(struct file);”h]”hŒs = sizeof(struct file);”…”�”}”hj¼sbah}”(h]”h ]”h"]”h$]”h&]”jÊjËj̉jÍjÎjÏ}”uh1jºh³hÃh´KúhjOh²hubhÚ)�”}”(hŒVDo not add spaces around (inside) parenthesized expressions. This example is **bad**:”h]”(hŒNDo not add spaces around (inside) parenthesized expressions. This example is ”…”�”}”(hjËh²hh³Nh´Nubhä)�”}”(hŒ**bad**”h]”hŒbad”…”�”}”(hjÓh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hãhjËubhŒ:”…”�”}”(hjËh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´KÿhjOh²hubj»)�”}”(hŒs = sizeof( struct file );”h]”hŒs = sizeof( struct file );”…”�”}”hjësbah}”(h]”h ]”h"]”h$]”h&]”jÊjËj̉jÍjÎjÏ}”uh1jºh³hÃh´MhjOh²hubhÚ)�”}”(hŒ½When declaring pointer data or a function that returns a pointer type, the preferred use of ``*`` is adjacent to the data name or function name and not adjacent to the type name. Examples:”h]”(hŒ\When declaring pointer data or a function that returns a pointer type, the preferred use of ”…”�”}”(hjúh²hh³Nh´Nubjk)�”}”(hŒ``*``”h]”hŒ*”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhjúubhŒ\ is adjacent to the data name or function name and not adjacent to the type name. Examples:”…”�”}”(hjúh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´MhjOh²hubj»)�”}”(hŒnchar *linux_banner; unsigned long long memparse(char *ptr, char **retptr); char *match_strdup(substring_t *s);”h]”hŒnchar *linux_banner; unsigned long long memparse(char *ptr, char **retptr); char *match_strdup(substring_t *s);”…”�”}”hjsbah}”(h]”h ]”h"]”h$]”h&]”jÊjËj̉jÍjÎjÏ}”uh1jºh³hÃh´M hjOh²hubhÚ)�”}”(hŒ`Use one space around (on each side of) most binary and ternary operators, such as any of these::”h]”hŒ_Use one space around (on each side of) most binary and ternary operators, such as any of these:”…”�”}”(hj)h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´MhjOh²hubj»)�”}”(hŒ5= + - < > * / % | & ^ <= >= == != ? :”h]”hŒ5= + - < > * / % | & ^ <= >= == != ? :”…”�”}”hj7sbah}”(h]”h ]”h"]”h$]”h&]”jÊjËuh1jºh³hÃh´MhjOh²hubhÚ)�”}”(hŒ$but no space after unary operators::”h]”hŒ#but no space after unary operators:”…”�”}”(hjEh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´MhjOh²hubj»)�”}”(hŒA& * + - ~ ! sizeof typeof alignof __attribute__ defined”h]”hŒA& * + - ~ ! sizeof typeof alignof __attribute__ defined”…”�”}”hjSsbah}”(h]”h ]”h"]”h$]”h&]”jÊjËuh1jºh³hÃh´MhjOh²hubhÚ)�”}”(hŒCno space before the postfix increment & decrement unary operators::”h]”hŒBno space before the postfix increment & decrement unary operators:”…”�”}”(hjah²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´MhjOh²hubj»)�”}”(hŒ++ --”h]”hŒ++ --”…”�”}”hjosbah}”(h]”h ]”h"]”h$]”h&]”jÊjËuh1jºh³hÃh´MhjOh²hubhÚ)�”}”(hŒAno space after the prefix increment & decrement unary operators::”h]”hŒ@no space after the prefix increment & decrement unary operators:”…”�”}”(hj}h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´MhjOh²hubj»)�”}”(hŒ++ --”h]”hŒ++ --”…”�”}”hj‹sbah}”(h]”h ]”h"]”h$]”h&]”jÊjËuh1jºh³hÃh´M!hjOh²hubhÚ)�”}”(hŒDand no space around the ``.`` and ``->`` structure member operators.”h]”(hŒand no space around the ”…”�”}”(hj™h²hh³Nh´Nubjk)�”}”(hŒ``.``”h]”hŒ.”…”�”}”(hj¡h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhj™ubhŒ and ”…”�”}”(hj™h²hh³Nh´Nubjk)�”}”(hŒ``->``”h]”hŒ->”…”�”}”(hj³h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhj™ubhŒ structure member operators.”…”�”}”(hj™h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M#hjOh²hubhÚ)�”}”(hX­Do not leave trailing whitespace at the ends of lines. Some editors with ``smart`` indentation will insert whitespace at the beginning of new lines as appropriate, so you can start typing the next line of code right away. However, some such editors do not remove the whitespace if you end up not putting a line of code there, such as if you leave a blank line. As a result, you end up with lines containing trailing whitespace.”h]”(hŒJDo not leave trailing whitespace at the ends of lines. Some editors with ”…”�”}”(hjËh²hh³Nh´Nubjk)�”}”(hŒ ``smart``”h]”hŒsmart”…”�”}”(hjÓh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhjËubhXZ indentation will insert whitespace at the beginning of new lines as appropriate, so you can start typing the next line of code right away. However, some such editors do not remove the whitespace if you end up not putting a line of code there, such as if you leave a blank line. As a result, you end up with lines containing trailing whitespace.”…”�”}”(hjËh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M%hjOh²hubhÚ)�”}”(hŒ÷Git will warn you about patches that introduce trailing whitespace, and can optionally strip the trailing whitespace for you; however, if applying a series of patches, this may make later patches in the series fail by changing their context lines.”h]”hŒ÷Git will warn you about patches that introduce trailing whitespace, and can optionally strip the trailing whitespace for you; however, if applying a series of patches, this may make later patches in the series fail by changing their context lines.”…”�”}”(hjëh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M,hjOh²hubeh}”(h]”Œspaces”ah ]”h"]”Œ 3.1) spaces”ah$]”h&]”uh1hÄhjÇh²hh³hÃh´Këubeh}”(h]”Œplacing-braces-and-spaces”ah ]”h"]”Œ3) placing braces and spaces”ah$]”h&]”uh1hÄhhÆh²hh³hÃh´KyubhÅ)�”}”(hhh]”(hÊ)�”}”(hŒ 4) Naming”h]”hŒ 4) Naming”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhj h²hh³hÃh´M3ubhÚ)�”}”(hX:C is a Spartan language, and your naming conventions should follow suit. Unlike Modula-2 and Pascal programmers, C programmers do not use cute names like ThisVariableIsATemporaryCounter. A C programmer would call that variable ``tmp``, which is much easier to write, and not the least more difficult to understand.”h]”(hŒãC is a Spartan language, and your naming conventions should follow suit. Unlike Modula-2 and Pascal programmers, C programmers do not use cute names like ThisVariableIsATemporaryCounter. A C programmer would call that variable ”…”�”}”(hjh²hh³Nh´Nubjk)�”}”(hŒ``tmp``”h]”hŒtmp”…”�”}”(hj"h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhjubhŒP, which is much easier to write, and not the least more difficult to understand.”…”�”}”(hjh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M5hj h²hubhÚ)�”}”(hŒžHOWEVER, while mixed-case names are frowned upon, descriptive names for global variables are a must. To call a global function ``foo`` is a shooting offense.”h]”(hŒ€HOWEVER, while mixed-case names are frowned upon, descriptive names for global variables are a must. To call a global function ”…”�”}”(hj:h²hh³Nh´Nubjk)�”}”(hŒ``foo``”h]”hŒfoo”…”�”}”(hjBh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhj:ubhŒ is a shooting offense.”…”�”}”(hj:h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M;hj h²hubhÚ)�”}”(hXGLOBAL variables (to be used only if you **really** need them) need to have descriptive names, as do global functions. If you have a function that counts the number of active users, you should call that ``count_active_users()`` or similar, you should **not** call it ``cntusr()``.”h]”(hŒ)GLOBAL variables (to be used only if you ”…”�”}”(hjZh²hh³Nh´Nubhä)�”}”(hŒ **really**”h]”hŒreally”…”�”}”(hjbh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hãhjZubhŒ™ need them) need to have descriptive names, as do global functions. If you have a function that counts the number of active users, you should call that ”…”�”}”(hjZh²hh³Nh´Nubjk)�”}”(hŒ``count_active_users()``”h]”hŒcount_active_users()”…”�”}”(hjth²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhjZubhŒ or similar, you should ”…”�”}”(hjZh²hh³Nh´Nubhä)�”}”(hŒ**not**”h]”hŒnot”…”�”}”(hj†h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hãhjZubhŒ call it ”…”�”}”(hjZh²hh³Nh´Nubjk)�”}”(hŒ ``cntusr()``”h]”hŒcntusr()”…”�”}”(hj˜h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhjZubhŒ.”…”�”}”(hjZh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M?hj h²hubhÚ)�”}”(hŒ·Encoding the type of a function into the name (so-called Hungarian notation) is asinine - the compiler knows the types anyway and can check those, and it only confuses the programmer.”h]”hŒ·Encoding the type of a function into the name (so-called Hungarian notation) is asinine - the compiler knows the types anyway and can check those, and it only confuses the programmer.”…”�”}”(hj°h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´MDhj h²hubhÚ)�”}”(hXNLOCAL variable names should be short, and to the point. If you have some random integer loop counter, it should probably be called ``i``. Calling it ``loop_counter`` is non-productive, if there is no chance of it being mis-understood. Similarly, ``tmp`` can be just about any type of variable that is used to hold a temporary value.”h]”(hŒ„LOCAL variable names should be short, and to the point. If you have some random integer loop counter, it should probably be called ”…”�”}”(hj¾h²hh³Nh´Nubjk)�”}”(hŒ``i``”h]”hŒi”…”�”}”(hjÆh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhj¾ubhŒ . Calling it ”…”�”}”(hj¾h²hh³Nh´Nubjk)�”}”(hŒ``loop_counter``”h]”hŒ loop_counter”…”�”}”(hjØh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhj¾ubhŒR is non-productive, if there is no chance of it being mis-understood. Similarly, ”…”�”}”(hj¾h²hh³Nh´Nubjk)�”}”(hŒ``tmp``”h]”hŒtmp”…”�”}”(hjêh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhj¾ubhŒO can be just about any type of variable that is used to hold a temporary value.”…”�”}”(hj¾h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´MHhj h²hubhÚ)�”}”(hŒ«If you are afraid to mix up your local variable names, you have another problem, which is called the function-growth-hormone-imbalance syndrome. See chapter 6 (Functions).”h]”hŒ«If you are afraid to mix up your local variable names, you have another problem, which is called the function-growth-hormone-imbalance syndrome. See chapter 6 (Functions).”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´MNhj h²hubhÚ)�”}”(hŒ•For symbol names and documentation, avoid introducing new usage of 'master / slave' (or 'slave' independent of 'master') and 'blacklist / whitelist'.”h]”hŒ¥For symbol names and documentation, avoid introducing new usage of ‘master / slave’ (or ‘slave’ independent of ‘master’) and ‘blacklist / whitelist’.”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´MRhj h²hubhŒdefinition_list”“”)�”}”(hhh]”(hŒdefinition_list_item”“”)�”}”(hŒêRecommended replacements for 'master / slave' are: '{primary,main} / {secondary,replica,subordinate}' '{initiator,requester} / {target,responder}' '{controller,host} / {device,worker,proxy}' 'leader / follower' 'director / performer' ”h]”(hŒterm”“”)�”}”(hŒ2Recommended replacements for 'master / slave' are:”h]”hŒ6Recommended replacements for ‘master / slave’ are:”…”�”}”(hj+h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j)h³hÃh´M[hj%ubhŒ definition”“”)�”}”(hhh]”hÚ)�”}”(hŒ¶'{primary,main} / {secondary,replica,subordinate}' '{initiator,requester} / {target,responder}' '{controller,host} / {device,worker,proxy}' 'leader / follower' 'director / performer'”h]”hŒÊ‘{primary,main} / {secondary,replica,subordinate}’ ‘{initiator,requester} / {target,responder}’ ‘{controller,host} / {device,worker,proxy}’ ‘leader / follower’ ‘director / performer’”…”�”}”(hj>h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´MWhj;ubah}”(h]”h ]”h"]”h$]”h&]”uh1j9hj%ubeh}”(h]”h ]”h"]”h$]”h&]”uh1j#h³hÃh´M[hj ubj$)�”}”(hŒfRecommended replacements for 'blacklist/whitelist' are: 'denylist / allowlist' 'blocklist / passlist' ”h]”(j*)�”}”(hŒ7Recommended replacements for 'blacklist/whitelist' are:”h]”hŒ;Recommended replacements for ‘blacklist/whitelist’ are:”…”�”}”(hj\h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1j)h³hÃh´M_hjXubj:)�”}”(hhh]”hÚ)�”}”(hŒ-'denylist / allowlist' 'blocklist / passlist'”h]”hŒ5‘denylist / allowlist’ ‘blocklist / passlist’”…”�”}”(hjmh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M^hjjubah}”(h]”h ]”h"]”h$]”h&]”uh1j9hjXubeh}”(h]”h ]”h"]”h$]”h&]”uh1j#h³hÃh´M_hj h²hubeh}”(h]”h ]”h"]”h$]”h&]”uh1jhj h²hh³hÃh´NubhÚ)�”}”(hX/Exceptions for introducing new usage is to maintain a userspace ABI/API, or when updating code for an existing (as of 2020) hardware or protocol specification that mandates those terms. For new specifications translate specification usage of the terminology to the kernel coding standard where possible.”h]”hX/Exceptions for introducing new usage is to maintain a userspace ABI/API, or when updating code for an existing (as of 2020) hardware or protocol specification that mandates those terms. For new specifications translate specification usage of the terminology to the kernel coding standard where possible.”…”�”}”(hj�h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´Mahj h²hubeh}”(h]”Œnaming”ah ]”h"]”Œ 4) naming”ah$]”h&]”uh1hÄhhÆh²hh³hÃh´M3ubhÅ)�”}”(hhh]”(hÊ)�”}”(hŒ 5) Typedefs”h]”hŒ 5) Typedefs”…”�”}”(hj¦h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhj£h²hh³hÃh´MhubhÚ)�”}”(hŒuPlease don't use things like ``vps_t``. It's a **mistake** to use typedef for structures and pointers. When you see a”h]”(hŒPlease don’t use things like ”…”�”}”(hj´h²hh³Nh´Nubjk)�”}”(hŒ ``vps_t``”h]”hŒvps_t”…”�”}”(hj¼h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhj´ubhŒ . It’s a ”…”�”}”(hj´h²hh³Nh´Nubhä)�”}”(hŒ **mistake**”h]”hŒmistake”…”�”}”(hjÎh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hãhj´ubhŒ; to use typedef for structures and pointers. When you see a”…”�”}”(hj´h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´Mjhj£h²hubj»)�”}”(hŒvps_t a;”h]”hŒvps_t a;”…”�”}”hjæsbah}”(h]”h ]”h"]”h$]”h&]”jÊjËj̉jÍjÎjÏ}”uh1jºh³hÃh´Mmhj£h²hubhÚ)�”}”(hŒ9in the source, what does it mean? In contrast, if it says”h]”hŒ9in the source, what does it mean? In contrast, if it says”…”�”}”(hjõh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´Mrhj£h²hubj»)�”}”(hŒstruct virtual_container *a;”h]”hŒstruct virtual_container *a;”…”�”}”hjsbah}”(h]”h ]”h"]”h$]”h&]”jÊjËj̉jÍjÎjÏ}”uh1jºh³hÃh´Muhj£h²hubhÚ)�”}”(hŒ$you can actually tell what ``a`` is.”h]”(hŒyou can actually tell what ”…”�”}”(hjh²hh³Nh´Nubjk)�”}”(hŒ``a``”h]”hŒa”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhjubhŒ is.”…”�”}”(hjh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´Myhj£h²hubhÚ)�”}”(hŒZLots of people think that typedefs ``help readability``. Not so. They are useful only for:”h]”(hŒ#Lots of people think that typedefs ”…”�”}”(hj2h²hh³Nh´Nubjk)�”}”(hŒ``help readability``”h]”hŒhelp readability”…”�”}”(hj:h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhj2ubhŒ#. Not so. They are useful only for:”…”�”}”(hj2h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M{hj£h²hubhŒ block_quote”“”)�”}”(hX(a) totally opaque objects (where the typedef is actively used to **hide** what the object is). Example: ``pte_t`` etc. opaque objects that you can only access using the proper accessor functions. .. note:: Opaqueness and ``accessor functions`` are not good in themselves. The reason we have them for things like pte_t etc. is that there really is absolutely **zero** portably accessible information there. (b) Clear integer types, where the abstraction **helps** avoid confusion whether it is ``int`` or ``long``. u8/u16/u32 are perfectly fine typedefs, although they fit into category (d) better than here. .. note:: Again - there needs to be a **reason** for this. If something is ``unsigned long``, then there's no reason to do typedef unsigned long myflags_t; but if there is a clear reason for why it under certain circumstances might be an ``unsigned int`` and under other configurations might be ``unsigned long``, then by all means go ahead and use a typedef. (c) when you use sparse to literally create a **new** type for type-checking. (d) New types which are identical to standard C99 types, in certain exceptional circumstances. Although it would only take a short amount of time for the eyes and brain to become accustomed to the standard types like ``uint32_t``, some people object to their use anyway. Therefore, the Linux-specific ``u8/u16/u32/u64`` types and their signed equivalents which are identical to standard types are permitted -- although they are not mandatory in new code of your own. When editing existing code which already uses one or the other set of types, you should conform to the existing choices in that code. (e) Types safe for use in userspace. In certain structures which are visible to userspace, we cannot require C99 types and cannot use the ``u32`` form above. Thus, we use __u32 and similar types in all structures which are shared with userspace. ”h]”hŒenumerated_list”“”)�”}”(hhh]”(hŒ list_item”“”)�”}”(hXœtotally opaque objects (where the typedef is actively used to **hide** what the object is). Example: ``pte_t`` etc. opaque objects that you can only access using the proper accessor functions. .. note:: Opaqueness and ``accessor functions`` are not good in themselves. The reason we have them for things like pte_t etc. is that there really is absolutely **zero** portably accessible information there. ”h]”(hÚ)�”}”(hŒ[totally opaque objects (where the typedef is actively used to **hide** what the object is).”h]”(hŒ>totally opaque objects (where the typedef is actively used to ”…”�”}”(hjch²hh³Nh´Nubhä)�”}”(hŒ**hide**”h]”hŒhide”…”�”}”(hjkh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hãhjcubhŒ what the object is).”…”�”}”(hjch²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M~hj_ubhÚ)�”}”(hŒdExample: ``pte_t`` etc. opaque objects that you can only access using the proper accessor functions.”h]”(hŒ Example: ”…”�”}”(hjƒh²hh³Nh´Nubjk)�”}”(hŒ ``pte_t``”h]”hŒpte_t”…”�”}”(hj‹h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhjƒubhŒR etc. opaque objects that you can only access using the proper accessor functions.”…”�”}”(hjƒh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M�hj_ubhŒnote”“”)�”}”(hŒÇOpaqueness and ``accessor functions`` are not good in themselves. The reason we have them for things like pte_t etc. is that there really is absolutely **zero** portably accessible information there.”h]”hÚ)�”}”(hŒÇOpaqueness and ``accessor functions`` are not good in themselves. The reason we have them for things like pte_t etc. is that there really is absolutely **zero** portably accessible information there.”h]”(hŒOpaqueness and ”…”�”}”(hj©h²hh³Nh´Nubjk)�”}”(hŒ``accessor functions``”h]”hŒaccessor functions”…”�”}”(hj±h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhj©ubhŒs are not good in themselves. The reason we have them for things like pte_t etc. is that there really is absolutely ”…”�”}”(hj©h²hh³Nh´Nubhä)�”}”(hŒ**zero**”h]”hŒzero”…”�”}”(hjÃh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hãhj©ubhŒ' portably accessible information there.”…”�”}”(hj©h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M†hj¥ubah}”(h]”h ]”h"]”h$]”h&]”uh1j£hj_ubeh}”(h]”h ]”h"]”h$]”h&]”uh1j]hjZubj^)�”}”(hX:Clear integer types, where the abstraction **helps** avoid confusion whether it is ``int`` or ``long``. u8/u16/u32 are perfectly fine typedefs, although they fit into category (d) better than here. .. note:: Again - there needs to be a **reason** for this. If something is ``unsigned long``, then there's no reason to do typedef unsigned long myflags_t; but if there is a clear reason for why it under certain circumstances might be an ``unsigned int`` and under other configurations might be ``unsigned long``, then by all means go ahead and use a typedef. ”h]”(hÚ)�”}”(hŒgClear integer types, where the abstraction **helps** avoid confusion whether it is ``int`` or ``long``.”h]”(hŒ+Clear integer types, where the abstraction ”…”�”}”(hjëh²hh³Nh´Nubhä)�”}”(hŒ **helps**”h]”hŒhelps”…”�”}”(hjóh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hãhjëubhŒ avoid confusion whether it is ”…”�”}”(hjëh²hh³Nh´Nubjk)�”}”(hŒ``int``”h]”hŒint”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhjëubhŒ or ”…”�”}”(hjëh²hh³Nh´Nubjk)�”}”(hŒ``long``”h]”hŒlong”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhjëubhŒ.”…”�”}”(hjëh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´MŠhjçubhÚ)�”}”(hŒ]u8/u16/u32 are perfectly fine typedefs, although they fit into category (d) better than here.”h]”hŒ]u8/u16/u32 are perfectly fine typedefs, although they fit into category (d) better than here.”…”�”}”(hj/ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M�hjçubj¤)�”}”(hŒ“Again - there needs to be a **reason** for this. If something is ``unsigned long``, then there's no reason to do typedef unsigned long myflags_t;”h]”(hÚ)�”}”(hŒpAgain - there needs to be a **reason** for this. If something is ``unsigned long``, then there's no reason to do”h]”(hŒAgain - there needs to be a ”…”�”}”(hjA h²hh³Nh´Nubhä)�”}”(hŒ **reason**”h]”hŒreason”…”�”}”(hjI h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hãhjA ubhŒ for this. If something is ”…”�”}”(hjA h²hh³Nh´Nubjk)�”}”(hŒ``unsigned long``”h]”hŒ unsigned long”…”�”}”(hj[ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhjA ubhŒ , then there’s no reason to do”…”�”}”(hjA h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M’hj= ubjS)�”}”(hŒ typedef unsigned long myflags_t;”h]”hÚ)�”}”(hju h]”hŒ typedef unsigned long myflags_t;”…”�”}”(hjw h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M•hjs ubah}”(h]”h ]”h"]”h$]”h&]”uh1jRh³hÃh´M•hj= ubeh}”(h]”h ]”h"]”h$]”h&]”uh1j£hjçubhÚ)�”}”(hŒËbut if there is a clear reason for why it under certain circumstances might be an ``unsigned int`` and under other configurations might be ``unsigned long``, then by all means go ahead and use a typedef.”h]”(hŒRbut if there is a clear reason for why it under certain circumstances might be an ”…”�”}”(hj� h²hh³Nh´Nubjk)�”}”(hŒ``unsigned int``”h]”hŒ unsigned int”…”�”}”(hj˜ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhj� ubhŒ) and under other configurations might be ”…”�”}”(hj� h²hh³Nh´Nubjk)�”}”(hŒ``unsigned long``”h]”hŒ unsigned long”…”�”}”(hjª h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhj� ubhŒ/, then by all means go ahead and use a typedef.”…”�”}”(hj� h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M—hjçubeh}”(h]”h ]”h"]”h$]”h&]”uh1j]hjZubj^)�”}”(hŒJwhen you use sparse to literally create a **new** type for type-checking. ”h]”hÚ)�”}”(hŒIwhen you use sparse to literally create a **new** type for type-checking.”h]”(hŒ*when you use sparse to literally create a ”…”�”}”(hjÌ h²hh³Nh´Nubhä)�”}”(hŒ**new**”h]”hŒnew”…”�”}”(hjÔ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hãhjÌ ubhŒ type for type-checking.”…”�”}”(hjÌ h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M›hjÈ ubah}”(h]”h ]”h"]”h$]”h&]”uh1j]hjZubj^)�”}”(hXXNew types which are identical to standard C99 types, in certain exceptional circumstances. Although it would only take a short amount of time for the eyes and brain to become accustomed to the standard types like ``uint32_t``, some people object to their use anyway. Therefore, the Linux-specific ``u8/u16/u32/u64`` types and their signed equivalents which are identical to standard types are permitted -- although they are not mandatory in new code of your own. When editing existing code which already uses one or the other set of types, you should conform to the existing choices in that code. ”h]”(hÚ)�”}”(hŒZNew types which are identical to standard C99 types, in certain exceptional circumstances.”h]”hŒZNew types which are identical to standard C99 types, in certain exceptional circumstances.”…”�”}”(hjö h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´Mžhjò ubhÚ)�”}”(hŒ¯Although it would only take a short amount of time for the eyes and brain to become accustomed to the standard types like ``uint32_t``, some people object to their use anyway.”h]”(hŒzAlthough it would only take a short amount of time for the eyes and brain to become accustomed to the standard types like ”…”�”}”(hj h²hh³Nh´Nubjk)�”}”(hŒ ``uint32_t``”h]”hŒuint32_t”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhj ubhŒ), some people object to their use anyway.”…”�”}”(hj h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M¡hjò ubhÚ)�”}”(hŒÃTherefore, the Linux-specific ``u8/u16/u32/u64`` types and their signed equivalents which are identical to standard types are permitted -- although they are not mandatory in new code of your own.”h]”(hŒTherefore, the Linux-specific ”…”�”}”(hj$ h²hh³Nh´Nubjk)�”}”(hŒ``u8/u16/u32/u64``”h]”hŒu8/u16/u32/u64”…”�”}”(hj, h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhj$ ubhŒ“ types and their signed equivalents which are identical to standard types are permitted -- although they are not mandatory in new code of your own.”…”�”}”(hj$ h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M¥hjò ubhÚ)�”}”(hŒ…When editing existing code which already uses one or the other set of types, you should conform to the existing choices in that code.”h]”hŒ…When editing existing code which already uses one or the other set of types, you should conform to the existing choices in that code.”…”�”}”(hjD h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´Mªhjò ubeh}”(h]”h ]”h"]”h$]”h&]”uh1j]hjZubj^)�”}”(hŒóTypes safe for use in userspace. In certain structures which are visible to userspace, we cannot require C99 types and cannot use the ``u32`` form above. Thus, we use __u32 and similar types in all structures which are shared with userspace. ”h]”(hÚ)�”}”(hŒ Types safe for use in userspace.”h]”hŒ Types safe for use in userspace.”…”�”}”(hj\ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M­hjX ubhÚ)�”}”(hŒÐIn certain structures which are visible to userspace, we cannot require C99 types and cannot use the ``u32`` form above. Thus, we use __u32 and similar types in all structures which are shared with userspace.”h]”(hŒeIn certain structures which are visible to userspace, we cannot require C99 types and cannot use the ”…”�”}”(hjj h²hh³Nh´Nubjk)�”}”(hŒ``u32``”h]”hŒu32”…”�”}”(hjr h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhjj ubhŒd form above. Thus, we use __u32 and similar types in all structures which are shared with userspace.”…”�”}”(hjj h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M¯hjX ubeh}”(h]”h ]”h"]”h$]”h&]”uh1j]hjZubeh}”(h]”h ]”h"]”h$]”h&]”Œenumtype”Œ loweralpha”Œprefix”Œ(”Œsuffix”Œ)”uh1jXhjTubah}”(h]”h ]”h"]”h$]”h&]”uh1jRh³hÃh´M~hj£h²hubhÚ)�”}”(hŒŽMaybe there are other cases too, but the rule should basically be to NEVER EVER use a typedef unless you can clearly match one of those rules.”h]”hŒŽMaybe there are other cases too, but the rule should basically be to NEVER EVER use a typedef unless you can clearly match one of those rules.”…”�”}”(hj¢ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M´hj£h²hubhÚ)�”}”(hŒ|In general, a pointer, or a struct that has elements that can reasonably be directly accessed should **never** be a typedef.”h]”(hŒeIn general, a pointer, or a struct that has elements that can reasonably be directly accessed should ”…”�”}”(hj° h²hh³Nh´Nubhä)�”}”(hŒ **never**”h]”hŒnever”…”�”}”(hj¸ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hãhj° ubhŒ be a typedef.”…”�”}”(hj° h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M·hj£h²hubeh}”(h]”Œtypedefs”ah ]”h"]”Œ 5) typedefs”ah$]”h&]”uh1hÄhhÆh²hh³hÃh´MhubhÅ)�”}”(hhh]”(hÊ)�”}”(hŒ 6) Functions”h]”hŒ 6) Functions”…”�”}”(hjÛ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhjØ h²hh³hÃh´M¼ubhÚ)�”}”(hŒÅFunctions should be short and sweet, and do just one thing. They should fit on one or two screenfuls of text (the ISO/ANSI screen size is 80x24, as we all know), and do one thing and do that well.”h]”hŒÅFunctions should be short and sweet, and do just one thing. They should fit on one or two screenfuls of text (the ISO/ANSI screen size is 80x24, as we all know), and do one thing and do that well.”…”�”}”(hjé h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M¾hjØ h²hubhÚ)�”}”(hXBThe maximum length of a function is inversely proportional to the complexity and indentation level of that function. So, if you have a conceptually simple function that is just one long (but simple) case-statement, where you have to do lots of small things for a lot of different cases, it's OK to have a longer function.”h]”hXDThe maximum length of a function is inversely proportional to the complexity and indentation level of that function. So, if you have a conceptually simple function that is just one long (but simple) case-statement, where you have to do lots of small things for a lot of different cases, it’s OK to have a longer function.”…”�”}”(hj÷ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´MÂhjØ h²hubhÚ)�”}”(hX¬However, if you have a complex function, and you suspect that a less-than-gifted first-year high-school student might not even understand what the function is all about, you should adhere to the maximum limits all the more closely. Use helper functions with descriptive names (you can ask the compiler to in-line them if you think it's performance-critical, and it will probably do a better job of it than you would have done).”h]”hX®However, if you have a complex function, and you suspect that a less-than-gifted first-year high-school student might not even understand what the function is all about, you should adhere to the maximum limits all the more closely. Use helper functions with descriptive names (you can ask the compiler to in-line them if you think it’s performance-critical, and it will probably do a better job of it than you would have done).”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´MÈhjØ h²hubhÚ)�”}”(hX‡Another measure of the function is the number of local variables. They shouldn't exceed 5-10, or you're doing something wrong. Re-think the function, and split it into smaller pieces. A human brain can generally easily keep track of about 7 different things, anything more and it gets confused. You know you're brilliant, but maybe you'd like to understand what you did 2 weeks from now.”h]”hX�Another measure of the function is the number of local variables. They shouldn’t exceed 5-10, or you’re doing something wrong. Re-think the function, and split it into smaller pieces. A human brain can generally easily keep track of about 7 different things, anything more and it gets confused. You know you’re brilliant, but maybe you’d like to understand what you did 2 weeks from now.”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´MÐhjØ h²hubhÚ)�”}”(hŒºIn source files, separate functions with one blank line. If the function is exported, the **EXPORT** macro for it should follow immediately after the closing function brace line. E.g.:”h]”(hŒ[In source files, separate functions with one blank line. If the function is exported, the ”…”�”}”(hj! h²hh³Nh´Nubhä)�”}”(hŒ **EXPORT**”h]”hŒEXPORT”…”�”}”(hj) h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hãhj! ubhŒU macro for it should follow immediately after the closing function brace line. E.g.:”…”�”}”(hj! h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M×hjØ h²hubj»)�”}”(hŒfint system_is_up(void) { return system_state == SYSTEM_RUNNING; } EXPORT_SYMBOL(system_is_up);”h]”hŒfint system_is_up(void) { return system_state == SYSTEM_RUNNING; } EXPORT_SYMBOL(system_is_up);”…”�”}”hjA sbah}”(h]”h ]”h"]”h$]”h&]”jÊjËj̉jÍjÎjÏ}”uh1jºh³hÃh´MÛhjØ h²hubhÅ)�”}”(hhh]”(hÊ)�”}”(hŒ6.1) Function prototypes”h]”hŒ6.1) Function prototypes”…”�”}”(hjS h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhjP h²hh³hÃh´MäubhÚ)�”}”(hŒ×In function prototypes, include parameter names with their data types. Although this is not required by the C language, it is preferred in Linux because it is a simple way to add valuable information for the reader.”h]”hŒ×In function prototypes, include parameter names with their data types. Although this is not required by the C language, it is preferred in Linux because it is a simple way to add valuable information for the reader.”…”�”}”(hja h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´MæhjP h²hubhÚ)�”}”(hŒuDo not use the ``extern`` keyword with function declarations as this makes lines longer and isn't strictly necessary.”h]”(hŒDo not use the ”…”�”}”(hjo h²hh³Nh´Nubjk)�”}”(hŒ ``extern``”h]”hŒextern”…”�”}”(hjw h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhjo ubhŒ^ keyword with function declarations as this makes lines longer and isn’t strictly necessary.”…”�”}”(hjo h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´MêhjP h²hubhÚ)�”}”(hŒïWhen writing function prototypes, please keep the `order of elements regular `_. For example, using this function declaration example::”h]”(hŒ2When writing function prototypes, please keep the ”…”�”}”(hj� h²hh³Nh´NubhŒ reference”“”)�”}”(hŒ…`order of elements regular `_”h]”hŒorder of elements regular”…”�”}”(hj™ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”Œname”Œorder of elements regular”Œrefuri”Œfhttps://lore.kernel.org/mm-commits/CAHk-=wiOCLRny5aifWNhr621kYrJwhfURsa0vFPeUEm8mF0ufg@mail.gmail.com/”uh1j— hj� ubh¶)�”}”(hŒi ”h]”h}”(h]”Œorder-of-elements-regular”ah ]”h"]”Œorder of elements regular”ah$]”h&]”Œrefuri”jª uh1hµŒ referenced”Khj� ubhŒ7. For example, using this function declaration example:”…”�”}”(hj� h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´MíhjP h²hubj»)�”}”(hŒ•__init void * __must_check action(enum magic value, size_t size, u8 count, char *fmt, ...) __printf(4, 5) __malloc;”h]”hŒ•__init void * __must_check action(enum magic value, size_t size, u8 count, char *fmt, ...) __printf(4, 5) __malloc;”…”�”}”hjà sbah}”(h]”h ]”h"]”h$]”h&]”jÊjËuh1jºh³hÃh´MñhjP h²hubhÚ)�”}”(hŒ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhj6 ubhŒ4 -- i.e. section declarations, but also things like ”…”�”}”(hj6 h²hh³Nh´Nubjk)�”}”(hŒ ``__cold``”h]”hŒ__cold”…”�”}”(hjP h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhj6 ubhŒ)”…”�”}”(hj6 h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´Møhj2 ubah}”(h]”h ]”h"]”h$]”h&]”uh1j]hjá h²hh³hÃh´Nubj^)�”}”(hŒreturn type (here, ``void *``)”h]”hÚ)�”}”(hjp h]”(hŒreturn type (here, ”…”�”}”(hjr h²hh³Nh´Nubjk)�”}”(hŒ ``void *``”h]”hŒvoid *”…”�”}”(hjy h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhjr ubhŒ)”…”�”}”(hjr h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´Múhjn ubah}”(h]”h ]”h"]”h$]”h&]”uh1j]hjá h²hh³hÃh´Nubj^)�”}”(hŒ/return type attributes (here, ``__must_check``)”h]”hÚ)�”}”(hj™ h]”(hŒreturn type attributes (here, ”…”�”}”(hj› h²hh³Nh´Nubjk)�”}”(hŒ``__must_check``”h]”hŒ __must_check”…”�”}”(hj¢ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhj› ubhŒ)”…”�”}”(hj› h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´Mûhj— ubah}”(h]”h ]”h"]”h$]”h&]”uh1j]hjá h²hh³hÃh´Nubj^)�”}”(hŒ function name (here, ``action``)”h]”hÚ)�”}”(hj h]”(hŒfunction name (here, ”…”�”}”(hjÄ h²hh³Nh´Nubjk)�”}”(hŒ ``action``”h]”hŒaction”…”�”}”(hjË h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhjÄ ubhŒ)”…”�”}”(hjÄ h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´MühjÀ ubah}”(h]”h ]”h"]”h$]”h&]”uh1j]hjá h²hh³hÃh´Nubj^)�”}”(hŒ�function parameters (here, ``(enum magic value, size_t size, u8 count, char *fmt, ...)``, noting that parameter names should always be included)”h]”hÚ)�”}”(hŒ�function parameters (here, ``(enum magic value, size_t size, u8 count, char *fmt, ...)``, noting that parameter names should always be included)”h]”(hŒfunction parameters (here, ”…”�”}”(hjí h²hh³Nh´Nubjk)�”}”(hŒ=``(enum magic value, size_t size, u8 count, char *fmt, ...)``”h]”hŒ9(enum magic value, size_t size, u8 count, char *fmt, ...)”…”�”}”(hjõ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhjí ubhŒ8, noting that parameter names should always be included)”…”�”}”(hjí h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´Mýhjé ubah}”(h]”h ]”h"]”h$]”h&]”uh1j]hjá h²hh³hÃh´Nubj^)�”}”(hŒ8function parameter attributes (here, ``__printf(4, 5)``)”h]”hÚ)�”}”(hj h]”(hŒ%function parameter attributes (here, ”…”�”}”(hj h²hh³Nh´Nubjk)�”}”(hŒ``__printf(4, 5)``”h]”hŒ__printf(4, 5)”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhj ubhŒ)”…”�”}”(hj h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´Mÿhj ubah}”(h]”h ]”h"]”h$]”h&]”uh1j]hjá h²hh³hÃh´Nubj^)�”}”(hŒ2function behavior attributes (here, ``__malloc``) ”h]”hÚ)�”}”(hŒ1function behavior attributes (here, ``__malloc``)”h]”(hŒ$function behavior attributes (here, ”…”�”}”(hj@ h²hh³Nh´Nubjk)�”}”(hŒ ``__malloc``”h]”hŒ__malloc”…”�”}”(hjH h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhj@ ubhŒ)”…”�”}”(hj@ h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´Mhj< ubah}”(h]”h ]”h"]”h$]”h&]”uh1j]hjá h²hh³hÃh´Nubeh}”(h]”h ]”h"]”h$]”h&]”Œbullet”Œ-”uh1jß h³hÃh´MöhjP h²hubhÚ)�”}”(hXQNote that for a function **definition** (i.e. the actual function body), the compiler does not allow function parameter attributes after the function parameters. In these cases, they should go after the storage class attributes (e.g. note the changed position of ``__printf(4, 5)`` below, compared to the **declaration** example above)::”h]”(hŒNote that for a function ”…”�”}”(hjn h²hh³Nh´Nubhä)�”}”(hŒ**definition**”h]”hŒ definition”…”�”}”(hjv h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hãhjn ubhŒà (i.e. the actual function body), the compiler does not allow function parameter attributes after the function parameters. In these cases, they should go after the storage class attributes (e.g. note the changed position of ”…”�”}”(hjn h²hh³Nh´Nubjk)�”}”(hŒ``__printf(4, 5)``”h]”hŒ__printf(4, 5)”…”�”}”(hjˆ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhjn ubhŒ below, compared to the ”…”�”}”(hjn h²hh³Nh´Nubhä)�”}”(hŒ**declaration**”h]”hŒ declaration”…”�”}”(hjš h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hãhjn ubhŒ example above):”…”�”}”(hjn h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´MhjP h²hubj»)�”}”(hŒ§static __always_inline __init __printf(4, 5) void * __must_check action(enum magic value, size_t size, u8 count, char *fmt, ...) __malloc { ... }”h]”hŒ§static __always_inline __init __printf(4, 5) void * __must_check action(enum magic value, size_t size, u8 count, char *fmt, ...) __malloc { ... }”…”�”}”hj² sbah}”(h]”h ]”h"]”h$]”h&]”jÊjËuh1jºh³hÃh´MhjP h²hubeh}”(h]”Œfunction-prototypes”ah ]”h"]”Œ6.1) function prototypes”ah$]”h&]”uh1hÄhjØ h²hh³hÃh´Mäubeh}”(h]”Œ functions”ah ]”h"]”Œ 6) functions”ah$]”h&]”uh1hÄhhÆh²hh³hÃh´M¼ubhÅ)�”}”(hhh]”(hÊ)�”}”(hŒ#7) Centralized exiting of functions”h]”hŒ#7) Centralized exiting of functions”…”�”}”(hjÓ h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhjÐ h²hh³hÃh´MubhÚ)�”}”(hŒ•Albeit deprecated by some people, the equivalent of the goto statement is used frequently by compilers in form of the unconditional jump instruction.”h]”hŒ•Albeit deprecated by some people, the equivalent of the goto statement is used frequently by compilers in form of the unconditional jump instruction.”…”�”}”(hjá h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´MhjÐ h²hubhÚ)�”}”(hŒ¾The goto statement comes in handy when a function exits from multiple locations and some common work such as cleanup has to be done. If there is no cleanup needed then just return directly.”h]”hŒ¾The goto statement comes in handy when a function exits from multiple locations and some common work such as cleanup has to be done. If there is no cleanup needed then just return directly.”…”�”}”(hjï h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´MhjÐ h²hubhÚ)�”}”(hXVChoose label names which say what the goto does or why the goto exists. An example of a good name could be ``out_free_buffer:`` if the goto frees ``buffer``. Avoid using GW-BASIC names like ``err1:`` and ``err2:``, as you would have to renumber them if you ever add or remove exit paths, and they make correctness difficult to verify anyway.”h]”(hŒlChoose label names which say what the goto does or why the goto exists. An example of a good name could be ”…”�”}”(hjý h²hh³Nh´Nubjk)�”}”(hŒ``out_free_buffer:``”•h]”hŒout_free_buffer:”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhjý ubhŒ if the goto frees ”…”�”}”(hjý h²hh³Nh´Nubjk)�”}”(hŒ ``buffer``”h]”hŒbuffer”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhjý ubhŒ". Avoid using GW-BASIC names like ”…”�”}”(hjý h²hh³Nh´Nubjk)�”}”(hŒ ``err1:``”h]”hŒerr1:”…”�”}”(hj)h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhjý ubhŒ and ”…”�”}”(hjý h²hh³Nh´Nubjk)�”}”(hŒ ``err2:``”h]”hŒerr2:”…”�”}”(hj;h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhjý ubhŒ€, as you would have to renumber them if you ever add or remove exit paths, and they make correctness difficult to verify anyway.”…”�”}”(hjý h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´MhjÐ h²hubhÚ)�”}”(hŒ!The rationale for using gotos is:”h]”hŒ!The rationale for using gotos is:”…”�”}”(hjSh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´MhjÐ h²hubjà )�”}”(hhh]”(j^)�”}”(hŒhjÐ h²hubj»)�”}”(hŒEerr: kfree(foo->bar); kfree(foo); return ret;”h]”hŒEerr: kfree(foo->bar); kfree(foo); return ret;”…”�”}”hj÷sbah}”(h]”h ]”h"]”h$]”h&]”jÊjËj̉jÍjÎjÏ}”uh1jºh³hÃh´M@hjÐ h²hubhÚ)�”}”(hŒ¬The bug in this code is that on some exit paths ``foo`` is NULL. Normally the fix for this is to split it up into two error labels ``err_free_bar:`` and ``err_free_foo:``:”h]”(hŒ0The bug in this code is that on some exit paths ”…”�”}”(hjh²hh³Nh´Nubjk)�”}”(hŒ``foo``”h]”hŒfoo”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhjubhŒM is NULL. Normally the fix for this is to split it up into two error labels ”…”�”}”(hjh²hh³Nh´Nubjk)�”}”(hŒ``err_free_bar:``”h]”hŒ err_free_bar:”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhjubhŒ and ”…”�”}”(hjh²hh³Nh´Nubjk)�”}”(hŒ``err_free_foo:``”h]”hŒ err_free_foo:”…”�”}”(hj2h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhjubhŒ:”…”�”}”(hjh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´MGhjÐ h²hubj»)�”}”(hŒ\err_free_bar: kfree(foo->bar); err_free_foo: kfree(foo); return ret;”h]”hŒ\err_free_bar: kfree(foo->bar); err_free_foo: kfree(foo); return ret;”…”�”}”hjJsbah}”(h]”h ]”h"]”h$]”h&]”jÊjËj̉jÍjÎjÏ}”uh1jºh³hÃh´MKhjÐ h²hubhÚ)�”}”(hŒ:Ideally you should simulate errors to test all exit paths.”h]”hŒ:Ideally you should simulate errors to test all exit paths.”…”�”}”(hjYh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´MShjÐ h²hubeh}”(h]”Œ centralized-exiting-of-functions”ah ]”h"]”Œ#7) centralized exiting of functions”ah$]”h&]”uh1hÄhhÆh²hh³hÃh´MubhÅ)�”}”(hhh]”(hÊ)�”}”(hŒ 8) Commenting”h]”hŒ 8) Commenting”…”�”}”(hjrh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhjoh²hh³hÃh´MWubhÚ)�”}”(hŒøComments are good, but there is also a danger of over-commenting. NEVER try to explain HOW your code works in a comment: it's much better to write the code so that the **working** is obvious, and it's a waste of time to explain badly written code.”h]”(hŒ«Comments are good, but there is also a danger of over-commenting. NEVER try to explain HOW your code works in a comment: it’s much better to write the code so that the ”…”�”}”(hj€h²hh³Nh´Nubhä)�”}”(hŒ **working**”h]”hŒworking”…”�”}”(hjˆh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hãhj€ubhŒF is obvious, and it’s a waste of time to explain badly written code.”…”�”}”(hj€h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´MYhjoh²hubhÚ)�”}”(hXïGenerally, you want your comments to tell WHAT your code does, not HOW. Also, try to avoid putting comments inside a function body: if the function is so complex that you need to separately comment parts of it, you should probably go back to chapter 6 for a while. You can make small comments to note or warn about something particularly clever (or ugly), but try to avoid excess. Instead, put the comments at the head of the function, telling people what it does, and possibly WHY it does it.”h]”hXïGenerally, you want your comments to tell WHAT your code does, not HOW. Also, try to avoid putting comments inside a function body: if the function is so complex that you need to separately comment parts of it, you should probably go back to chapter 6 for a while. You can make small comments to note or warn about something particularly clever (or ugly), but try to avoid excess. Instead, put the comments at the head of the function, telling people what it does, and possibly WHY it does it.”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M^hjoh²hubhÚ)�”}”(hXuWhen commenting the kernel API functions, please use the kernel-doc format. See the files at :ref:`Documentation/doc-guide/ ` and ``tools/docs/kernel-doc`` for details. Note that the danger of over-commenting applies to kernel-doc comments all the same. Do not add boilerplate kernel-doc which simply reiterates what's obvious from the signature of the function.”h]”(hŒ]When commenting the kernel API functions, please use the kernel-doc format. See the files at ”…”�”}”(hj®h²hh³Nh´Nubh)�”}”(hŒ+:ref:`Documentation/doc-guide/ `”h]”hŒinline”“”)�”}”(hj¸h]”hŒDocumentation/doc-guide/”…”�”}”(hj¼h²hh³Nh´Nubah}”(h]”h ]”(Œxref”Œstd”Œstd-ref”eh"]”h$]”h&]”uh1jºhj¶ubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”Œprocess/coding-style”Œ refdomain”jÇŒreftype”Œref”Œ refexplicit”ˆŒrefwarn”ˆŒ reftarget”Œ doc_guide”uh1hh³hÃh´Mghj®ubhŒ and ”…”�”}”(hj®h²hh³Nh´Nubjk)�”}”(hŒ``tools/docs/kernel-doc``”h]”hŒtools/docs/kernel-doc”…”�”}”(hjßh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhj®ubhŒÑ for details. Note that the danger of over-commenting applies to kernel-doc comments all the same. Do not add boilerplate kernel-doc which simply reiterates what’s obvious from the signature of the function.”…”�”}”(hj®h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´Mghjoh²hubhÚ)�”}”(hŒ6The preferred style for long (multi-line) comments is:”h]”hŒ6The preferred style for long (multi-line) comments is:”…”�”}”(hj÷h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´Mnhjoh²hubj»)�”}”(hŒí/* * This is the preferred style for multi-line * comments in the Linux kernel source code. * Please use it consistently. * * Description: A column of asterisks on the left side, * with beginning and ending almost-blank lines. */”h]”hŒí/* * This is the preferred style for multi-line * comments in the Linux kernel source code. * Please use it consistently. * * Description: A column of asterisks on the left side, * with beginning and ending almost-blank lines. */”…”�”}”hjsbah}”(h]”h ]”h"]”h$]”h&]”jÊjËj̉jÍjÎjÏ}”uh1jºh³hÃh´Mphjoh²hubhÚ)�”}”(hXIt's also important to comment data, whether they are basic types or derived types. To this end, use just one data declaration per line (no commas for multiple data declarations). This leaves you room for a small comment on each item, explaining its use.”h]”hXIt’s also important to comment data, whether they are basic types or derived types. To this end, use just one data declaration per line (no commas for multiple data declarations). This leaves you room for a small comment on each item, explaining its use.”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M{hjoh²hubeh}”(h]”Œ commenting”ah ]”h"]”Œ 8) commenting”ah$]”h&]”uh1hÄhhÆh²hh³hÃh´MWubhÅ)�”}”(hhh]”(hÊ)�”}”(hŒ9) You've made a mess of it”h]”hŒ9) You’ve made a mess of it”…”�”}”(hj-h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhj*h²hh³hÃh´M‚ubhÚ)�”}”(hXvThat's OK, we all do. You've probably been told by your long-time Unix user helper that ``GNU emacs`` automatically formats the C sources for you, and you've noticed that yes, it does do that, but the defaults it uses are less than desirable (in fact, they are worse than random typing - an infinite number of monkeys typing into GNU emacs would never make a good program).”h]”(hŒ]That’s OK, we all do. You’ve probably been told by your long-time Unix user helper that ”…”�”}”(hj;h²hh³Nh´Nubjk)�”}”(hŒ ``GNU emacs``”h]”hŒ GNU emacs”…”�”}”(hjCh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhj;ubhX automatically formats the C sources for you, and you’ve noticed that yes, it does do that, but the defaults it uses are less than desirable (in fact, they are worse than random typing - an infinite number of monkeys typing into GNU emacs would never make a good program).”…”�”}”(hj;h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M„hj*h²hubhÚ)�”}”(hŒŽSo, you can either get rid of GNU emacs, or change it to use saner values. To do the latter, you can stick the following in your .emacs file:”h]”hŒŽSo, you can either get rid of GNU emacs, or change it to use saner values. To do the latter, you can stick the following in your .emacs file:”…”�”}”(hj[h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M‹hj*h²hubj»)�”}”(hX(defun c-lineup-arglist-tabs-only (ignored) "Line up argument lists by tabs, not spaces" (let* ((anchor (c-langelem-pos c-syntactic-element)) (column (c-langelem-2nd-pos c-syntactic-element)) (offset (- (1+ column) anchor)) (steps (floor offset c-basic-offset))) (* (max steps 1) c-basic-offset))) (dir-locals-set-class-variables 'linux-kernel '((c-mode . ( (c-basic-offset . 8) (c-label-minimum-indentation . 0) (c-offsets-alist . ( (arglist-close . c-lineup-arglist-tabs-only) (arglist-cont-nonempty . (c-lineup-gcc-asm-reg c-lineup-arglist-tabs-only)) (arglist-intro . +) (brace-list-intro . +) (c . c-lineup-C-comments) (case-label . 0) (comment-intro . c-lineup-comment) (cpp-define-intro . +) (cpp-macro . -1000) (cpp-macro-cont . +) (defun-block-intro . +) (else-clause . 0) (func-decl-cont . +) (inclass . +) (inher-cont . c-lineup-multi-inher) (knr-argdecl-intro . 0) (label . -1000) (statement . 0) (statement-block-intro . +) (statement-case-intro . +) (statement-cont . +) (substatement . +) )) (indent-tabs-mode . t) (show-trailing-whitespace . t) )))) (dir-locals-set-directory-class (expand-file-name "~/src/linux-trees") 'linux-kernel)”h]”hX(defun c-lineup-arglist-tabs-only (ignored) "Line up argument lists by tabs, not spaces" (let* ((anchor (c-langelem-pos c-syntactic-element)) (column (c-langelem-2nd-pos c-syntactic-element)) (offset (- (1+ column) anchor)) (steps (floor offset c-basic-offset))) (* (max steps 1) c-basic-offset))) (dir-locals-set-class-variables 'linux-kernel '((c-mode . ( (c-basic-offset . 8) (c-label-minimum-indentation . 0) (c-offsets-alist . ( (arglist-close . c-lineup-arglist-tabs-only) (arglist-cont-nonempty . (c-lineup-gcc-asm-reg c-lineup-arglist-tabs-only)) (arglist-intro . +) (brace-list-intro . +) (c . c-lineup-C-comments) (case-label . 0) (comment-intro . c-lineup-comment) (cpp-define-intro . +) (cpp-macro . -1000) (cpp-macro-cont . +) (defun-block-intro . +) (else-clause . 0) (func-decl-cont . +) (inclass . +) (inher-cont . c-lineup-multi-inher) (knr-argdecl-intro . 0) (label . -1000) (statement . 0) (statement-block-intro . +) (statement-case-intro . +) (statement-cont . +) (substatement . +) )) (indent-tabs-mode . t) (show-trailing-whitespace . t) )))) (dir-locals-set-directory-class (expand-file-name "~/src/linux-trees") 'linux-kernel)”…”�”}”hjisbah}”(h]”h ]”h"]”h$]”h&]”jÊjËj̉jÍŒelisp”jÏ}”uh1jºh³hÃh´MŽhj*h²hubhÚ)�”}”(hŒdThis will make emacs go better with the kernel coding style for C files below ``~/src/linux-trees``.”h]”(hŒNThis will make emacs go better with the kernel coding style for C files below ”…”�”}”(hjyh²hh³Nh´Nubjk)�”}”(hŒ``~/src/linux-trees``”h]”hŒ~/src/linux-trees”…”�”}”(hj�h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhjyubhŒ.”…”�”}”(hjyh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M¿hj*h²hubhÚ)�”}”(hŒdBut even if you fail in getting emacs to do sane formatting, not everything is lost: use ``indent``.”h]”(hŒYBut even if you fail in getting emacs to do sane formatting, not everything is lost: use ”…”�”}”(hj™h²hh³Nh´Nubjk)�”}”(hŒ ``indent``”h]”hŒindent”…”�”}”(hj¡h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhj™ubhŒ.”…”�”}”(hj™h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´MÂhj*h²hubhÚ)�”}”(hXÓNow, again, GNU indent has the same brain-dead settings that GNU emacs has, which is why you need to give it a few command line options. However, that's not too bad, because even the makers of GNU indent recognize the authority of K&R (the GNU people aren't evil, they are just severely misguided in this matter), so you just give indent the options ``-kr -i8`` (stands for ``K&R, 8 character indents``), or use ``scripts/Lindent``, which indents in the latest style.”h]”(hXbNow, again, GNU indent has the same brain-dead settings that GNU emacs has, which is why you need to give it a few command line options. However, that’s not too bad, because even the makers of GNU indent recognize the authority of K&R (the GNU people aren’t evil, they are just severely misguided in this matter), so you just give indent the options ”…”�”}”(hj¹h²hh³Nh´Nubjk)�”}”(hŒ ``-kr -i8``”h]”hŒ-kr -i8”…”�”}”(hjÁh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhj¹ubhŒ (stands for ”…”�”}”(hj¹h²hh³Nh´Nubjk)�”}”(hŒ``K&R, 8 character indents``”h]”hŒK&R, 8 character indents”…”�”}”(hjÓh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhj¹ubhŒ ), or use ”…”�”}”(hj¹h²hh³Nh´Nubjk)�”}”(hŒ``scripts/Lindent``”h]”hŒscripts/Lindent”…”�”}”(hjåh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhj¹ubhŒ$, which indents in the latest style.”…”�”}”(hj¹h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´MÅhj*h²hubhÚ)�”}”(hŒ¿``indent`` has a lot of options, and especially when it comes to comment re-formatting you may want to take a look at the man page. But remember: ``indent`` is not a fix for bad programming.”h]”(jk)�”}”(hŒ ``indent``”h]”hŒindent”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhjýubhŒ‰ has a lot of options, and especially when it comes to comment re-formatting you may want to take a look at the man page. But remember: ”…”�”}”(hjýh²hh³Nh´Nubjk)�”}”(hŒ ``indent``”h]”hŒindent”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhjýubhŒ" is not a fix for bad programming.”…”�”}”(hjýh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´MÍhj*h²hubhÚ)�”}”(hX¿Note that you can also use the ``clang-format`` tool to help you with these rules, to quickly re-format parts of your code automatically, and to review full files in order to spot coding style mistakes, typos and possible improvements. It is also handy for sorting ``#includes``, for aligning variables/macros, for reflowing text and other similar tasks. See the file :ref:`Documentation/dev-tools/clang-format.rst ` for more details.”h]”(hŒNote that you can also use the ”…”�”}”(hj+h²hh³Nh´Nubjk)�”}”(hŒ``clang-format``”h]”hŒ clang-format”…”�”}”(hj3h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhj+ubhŒÚ tool to help you with these rules, to quickly re-format parts of your code automatically, and to review full files in order to spot coding style mistakes, typos and possible improvements. It is also handy for sorting ”…”�”}”(hj+h²hh³Nh´Nubjk)�”}”(hŒ ``#includes``”h]”hŒ #includes”…”�”}”(hjEh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhj+ubhŒZ, for aligning variables/macros, for reflowing text and other similar tasks. See the file ”…”�”}”(hj+h²hh³Nh´Nubh)�”}”(hŒ=:ref:`Documentation/dev-tools/clang-format.rst `”h]”j»)�”}”(hjYh]”hŒ(Documentation/dev-tools/clang-format.rst”…”�”}”(hj[h²hh³Nh´Nubah}”(h]”h ]”(jÆŒstd”Œstd-ref”eh"]”h$]”h&]”uh1jºhjWubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”jÓŒ refdomain”jeŒreftype”Œref”Œ refexplicit”ˆŒrefwarn”ˆjÙŒ clangformat”uh1hh³hÃh´MÑhj+ubhŒ for more details.”…”�”}”(hj+h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´MÑhj*h²hubhÚ)�”}”(hŒòSome basic editor settings, such as indentation and line endings, will be set automatically if you are using an editor that is compatible with EditorConfig. See the official EditorConfig website for more information: https://editorconfig.org/”h]”(hŒÙSome basic editor settings, such as indentation and line endings, will be set automatically if you are using an editor that is compatible with EditorConfig. See the official EditorConfig website for more information: ”…”�”}”(hj�h²hh³Nh´Nubj˜ )�”}”(hŒhttps://editorconfig.org/”h]”hŒhttps://editorconfig.org/”…”�”}”(hj‰h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”Œrefuri”j‹uh1j— hj�ubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´MÙhj*h²hubeh}”(h]”Œyou-ve-made-a-mess-of-it”ah ]”h"]”Œ9) you've made a mess of it”ah$]”h&]”uh1hÄhhÆh²hh³hÃh´M‚ubhÅ)�”}”(hhh]”(hÊ)�”}”(hŒ10) Kconfig configuration files”h]”hŒ10) Kconfig configuration files”…”�”}”(hj©h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhj¦h²hh³hÃh´MßubhÚ)�”}”(hŒïFor all of the Kconfig* configuration files throughout the source tree, the indentation is somewhat different. Lines under a ``config`` definition are indented with one tab, while help text is indented an additional two spaces. Example::”h]”(hŒ~For all of the Kconfig* configuration files throughout the source tree, the indentation is somewhat different. Lines under a ”…”�”}”(hj·h²hh³Nh´Nubjk)�”}”(hŒ ``config``”h]”hŒconfig”…”�”}”(hj¿h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhj·ubhŒf definition are indented with one tab, while help text is indented an additional two spaces. Example:”…”�”}”(hj·h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´Máhj¦h²hubj»)�”}”(hXBconfig AUDIT bool "Auditing support" depends on NET help Enable auditing infrastructure that can be used with another kernel subsystem, such as SELinux (which requires this for logging of avc messages output). Does not do system-call auditing without CONFIG_AUDITSYSCALL.”h]”hXBconfig AUDIT bool "Auditing support" depends on NET help Enable auditing infrastructure that can be used with another kernel subsystem, such as SELinux (which requires this for logging of avc messages output). Does not do system-call auditing without CONFIG_AUDITSYSCALL.”…”�”}”hj×sbah}”(h]”h ]”h"]”h$]”h&]”jÊjËuh1jºh³hÃh´Mæhj¦h²hubhÚ)�”}”(hŒ‡Seriously dangerous features (such as write support for certain filesystems) should advertise this prominently in their prompt string::”h]”hŒ†Seriously dangerous features (such as write support for certain filesystems) should advertise this prominently in their prompt string:”…”�”}”(hjåh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´Mïhj¦h²hubj»)�”}”(hŒ`config ADFS_FS_RW bool "ADFS write support (DANGEROUS)" depends on ADFS_FS ...”h]”hŒ`config ADFS_FS_RW bool "ADFS write support (DANGEROUS)" depends on ADFS_FS ...”…”�”}”hjósbah}”(h]”h ]”h"]”h$]”h&]”jÊjËuh1jºh³hÃh´Mòhj¦h²hubhÚ)�”}”(hŒjFor full documentation on the configuration files, see the file Documentation/kbuild/kconfig-language.rst.”h]”hŒjFor full documentation on the configuration files, see the file Documentation/kbuild/kconfig-language.rst.”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M÷hj¦h²hubeh}”(h]”Œkconfig-configuration-files”ah ]”h"]”Œ10) kconfig configuration files”ah$]”h&]”uh1hÄhhÆh²hh³hÃh´MßubhÅ)�”}”(hhh]”(hÊ)�”}”(hŒ11) Data structures”h]”hŒ11) Data structures”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhjh²hh³hÃh´MüubhÚ)�”}”(hXTData structures that have visibility outside the single-threaded environment they are created and destroyed in should always have reference counts. In the kernel, garbage collection doesn't exist (and outside the kernel garbage collection is slow and inefficient), which means that you absolutely **have** to reference count all your uses.”h]”(hX,Data structures that have visibility outside the single-threaded environment they are created and destroyed in should always have reference counts. In the kernel, garbage collection doesn’t exist (and outside the kernel garbage collection is slow and inefficient), which means that you absolutely ”…”�”}”(hj(h²hh³Nh´Nubhä)�”}”(hŒ**have**”h]”hŒhave”…”�”}”(hj0h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hãhj(ubhŒ" to reference count all your uses.”…”�”}”(hj(h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´Mþhjh²hubhÚ)�”}”(hX Reference counting means that you can avoid locking, and allows multiple users to have access to the data structure in parallel - and not having to worry about the structure suddenly going away from under them just because they slept or did something else for a while.”h]”hX Reference counting means that you can avoid locking, and allows multiple users to have access to the data structure in parallel - and not having to worry about the structure suddenly going away from under them just because they slept or did something else for a while.”…”�”}”(hjHh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´Mhjh²hubhÚ)�”}”(hŒúNote that locking is **not** a replacement for reference counting. Locking is used to keep data structures coherent, while reference counting is a memory management technique. Usually both are needed, and they are not to be confused with each other.”h]”(hŒNote that locking is ”…”�”}”(hjVh²hh³Nh´Nubhä)�”}”(hŒ**not**”h]”hŒnot”…”�”}”(hj^h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hãhjVubhŒÞ a replacement for reference counting. Locking is used to keep data structures coherent, while reference counting is a memory management technique. Usually both are needed, and they are not to be confused with each other.”…”�”}”(hjVh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M hjh²hubhÚ)�”}”(hŒþMany data structures can indeed have two levels of reference counting, when there are users of different ``classes``. The subclass count counts the number of subclass users, and decrements the global count just once when the subclass count goes to zero.”h]”(hŒiMany data structures can indeed have two levels of reference counting, when there are users of different ”…”�”}”(hjvh²hh³Nh´Nubjk)�”}”(hŒ ``classes``”h]”hŒclasses”…”�”}”(hj~h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhjvubhŒŠ. The subclass count counts the number of subclass users, and decrements the global count just once when the subclass count goes to zero.”…”�”}”(hjvh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´Mhjh²hubhÚ)�”}”(hŒÓExamples of this kind of ``multi-level-reference-counting`` can be found in memory management (``struct mm_struct``: mm_users and mm_count), and in filesystem code (``struct super_block``: s_count and s_active).”h]”(hŒExamples of this kind of ”…”�”}”(hj–h²hh³Nh´Nubjk)�”}”(hŒ"``multi-level-reference-counting``”h]”hŒmulti-level-reference-counting”…”�”}”(hjžh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhj–ubhŒ$ can be found in memory management (”…”�”}”(hj–h²hh³Nh´Nubjk)�”}”(hŒ``struct mm_struct``”h]”hŒstruct mm_struct”…”�”}”(hj°h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhj–ubhŒ2: mm_users and mm_count), and in filesystem code (”…”�”}”(hj–h²hh³Nh´Nubjk)�”}”(hŒ``struct super_block``”h]”hŒstruct super_block”…”�”}”(hjÂh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhj–ubhŒ: s_count and s_active).”…”�”}”(hj–h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´Mhjh²hubhÚ)�”}”(hŒ†Remember: if another thread can find your data structure, and you don't have a reference count on it, you almost certainly have a bug.”h]”hŒˆRemember: if another thread can find your data structure, and you don’t have a reference count on it, you almost certainly have a bug.”…”�”}”(hjÚh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´Mhjh²hubeh}”(h]”Œdata-structures”ah ]”h"]”Œ11) data structures”ah$]”h&]”uh1hÄhhÆh²hh³hÃh´MüubhÅ)�”}”(hhh]”(hÊ)�”}”(hŒ12) Macros, Enums and RTL”h]”hŒ12) Macros, Enums and RTL”…”�”}”(hjóh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhjðh²hh³hÃh´MubhÚ)�”}”(hŒGNames of macros defining constants and labels in enums are capitalized.”h]”hŒGNames of macros defining constants and labels in enums are capitalized.”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´Mhjðh²hubj»)�”}”(hŒ#define CONSTANT 0x12345”h]”hŒ#define CONSTANT 0x12345”…”�”}”hjsbah}”(h]”h ]”h"]”h$]”h&]”jÊjËj̉jÍjÎjÏ}”uh1jºh³hÃh´M hjðh²hubhÚ)�”}”(hŒhjðh²hubj»)�”}”(hŒ�/* * Avoid doing this whenever possible and instead opt for static * inline functions */ #define macrofun(foo) do { (void) (foo); } while (0)”h]”hŒ�/* * Avoid doing this whenever possible and instead opt for static * inline functions */ #define macrofun(foo) do { (void) (foo); } while (0)”…”�”}”hj�sbah}”(h]”h ]”h"]”h$]”h&]”jÊjËj̉jÍjÎjÏ}”uh1jºh³hÃh´MDhjðh²hubhÚ)�”}”(hŒ"Things to avoid when using macros:”h]”hŒ"Things to avoid when using macros:”…”�”}”(hjŸh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´MLhjðh²hubjY)�”}”(hhh]”j^)�”}”(hŒ!macros that affect control flow: ”h]”hÚ)�”}”(hŒ macros that affect control flow:”h]”hŒ macros that affect control flow:”…”�”}”(hj´h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´MNhj°ubah}”(h]”h ]”h"]”h$]”h&]”uh1j]hj­h²hh³hÃh´Nubah}”(h]”h ]”h"]”h$]”h&]”j– Œarabic”j˜ hjš j› uh1jXhjðh²hh³hÃh´MNubj»)�”}”(hŒÛ#define FOO(x) \ do { \ if (blah(x) < 0) \ return -EBUGGERED; \ } while (0)”h]”hŒÛ#define FOO(x) \ do { \ if (blah(x) < 0) \ return -EBUGGERED; \ } while (0)”…”�”}”hjÏsbah}”(h]”h ]”h"]”h$]”h&]”jÊjËj̉jÍjÎjÏ}”uh1jºh³hÃh´MPhjðh²hubhÚ)�”}”(hŒœis a **very** bad idea. It looks like a function call but exits the ``calling`` function; don't break the internal parsers of those who will read the code.”h]”(hŒis a ”…”�”}”(hjÞh²hh³Nh´Nubhä)�”}”(hŒ**very**”h]”hŒvery”…”�”}”(hjæh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hãhjÞubhŒ8 bad idea. It looks like a function call but exits the ”…”�”}”(hjÞh²hh³Nh´Nubjk)�”}”(hŒ ``calling``”h]”hŒcalling”…”�”}”(hjøh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhjÞubhŒN function; don’t break the internal parsers of those who will read the code.”…”�”}”(hjÞh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´MXhjðh²hubjY)�”}”(hhh]”j^)�”}”(hŒAmacros that depend on having a local variable with a magic name: ”h]”hÚ)�”}”(hŒ@macros that depend on having a local variable with a magic name:”h]”hŒ@macros that depend on having a local variable with a magic name:”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M[hjubah}”(h]”h ]”h"]”h$]”h&]”uh1j]hjh²hh³hÃh´Nubah}”(h]”h ]”h"]”h$]”h&]”j– jÎj˜ hjš j› Œstart”Kuh1jXhjðh²hh³hÃh´M[ubj»)�”}”(hŒ #define FOO(val) bar(index, val)”h]”hŒ #define FOO(val) bar(index, val)”…”�”}”hj2sbah}”(h]”h ]”h"]”h$]”h&]”jÊjËj̉jÍjÎjÏ}”uh1jºh³hÃh´M]hjðh²hubhÚ)�”}”(hŒŒmight look like a good thing, but it's confusing as hell when one reads the code and it's prone to breakage from seemingly innocent changes.”h]”hŒ�might look like a good thing, but it’s confusing as hell when one reads the code and it’s prone to breakage from seemingly innocent changes.”…”�”}”(hjAh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´Mahjðh²hubhÚ)�”}”(hŒ�3) macros with arguments that are used as l-values: FOO(x) = y; will bite you if somebody e.g. turns FOO into an inline function.”h]”hŒ�3) macros with arguments that are used as l-values: FOO(x) = y; will bite you if somebody e.g. turns FOO into an inline function.”…”�”}”(hjOh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´Mdhjðh²hubhÚ)�”}”(hŒ®4) forgetting about precedence: macros defining constants using expressions must enclose the expression in parentheses. Beware of similar issues with macros using parameters.”h]”hŒ®4) forgetting about precedence: macros defining constants using expressions must enclose the expression in parentheses. Beware of similar issues with macros using parameters.”…”�”}”(hj]h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´Mghjðh²hubj»)�”}”(hŒ7#define CONSTANT 0x4000 #define CONSTEXP (CONSTANT | 3)”h]”hŒ7#define CONSTANT 0x4000 #define CONSTEXP (CONSTANT | 3)”…”�”}”hjksbah}”(h]”h ]”h"]”h$]”h&]”jÊjËj̉jÍjÎjÏ}”uh1jºh³hÃh´Mkhjðh²hubhÚ)�”}”(hŒU5) namespace collisions when defining local variables in macros resembling functions:”h]”hŒU5) namespace collisions when defining local variables in macros resembling functions:”…”�”}”(hjzh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´Mphjðh²hubj»)�”}”(hŒÔ#define FOO(x) \ ({ \ typeof(x) ret; \ ret = calc_ret(x); \ (ret); \ })”h]”hŒÔ#define FOO(x) \ ({ \ typeof(x) ret; \ ret = calc_ret(x); \ (ret); \ })”…”�”}”hjˆsbah}”(h]”h ]”h"]”h$]”h&]”jÊjËj̉jÍjÎjÏ}”uh1jºh³hÃh´Mshjðh²hubhÚ)�”}”(hŒjret is a common name for a local variable - __foo_ret is less likely to collide with an existing variable.”h]”hŒjret is a common name for a local variable - __foo_ret is less likely to collide with an existing variable.”…”�”}”(hj—h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M|hjðh²hubhÚ)�”}”(hŒ–The cpp manual deals with macros exhaustively. The gcc internals manual also covers RTL which is used frequently with assembly language in the kernel.”h]”hŒ–The cpp manual deals with macros exhaustively. The gcc internals manual also covers RTL which is used frequently with assembly language in the kernel.”…”�”}”(hj¥h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´Mhjðh²hubeh}”(h]”Œmacros-enums-and-rtl”ah ]”h"]”Œ12) macros, enums and rtl”ah$]”h&]”uh1hÄhhÆh²hh³hÃh´MubhÅ)�”}”(hhh]”(hÊ)�”}”(hŒ13) Printing kernel messages”h]”hŒ13) Printing kernel messages”…”�”}”(hj¾h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhj»h²hh³hÃh´M„ubhÚ)�”}”(hŒúKernel developers like to be seen as literate. Do mind the spelling of kernel messages to make a good impression. Do not use incorrect contractions like ``dont``; use ``do not`` or ``don't`` instead. Make the messages concise, clear, and unambiguous.”h]”(hŒ™Kernel developers like to be seen as literate. Do mind the spelling of kernel messages to make a good impression. Do not use incorrect contractions like ”…”�”}”(hjÌh²hh³Nh´Nubjk)�”}”(hŒ``dont``”h]”hŒdont”…”�”}”(hjÔh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhjÌubhŒ; use ”…”�”}”(hjÌh²hh³Nh´Nubjk)�”}”(hŒ ``do not``”h]”hŒdo not”…”�”}”(hjæh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhjÌubhŒ or ”…”�”}”(hjÌh²hh³Nh´Nubjk)�”}”(hŒ ``don't``”h]”hŒdon't”…”�”}”(hjøh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhjÌubhŒ< instead. Make the messages concise, clear, and unambiguous.”…”�”}”(hjÌh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M†hj»h²hubhÚ)�”}”(hŒ;Kernel messages do not have to be terminated with a period.”h]”hŒ;Kernel messages do not have to be terminated with a period.”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M‹hj»h²hubhÚ)�”}”(hŒIPrinting numbers in parentheses (%d) adds no value and should be avoided.”h]”hŒIPrinting numbers in parentheses (%d) adds no value and should be avoided.”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M�hj»h²hubhÚ)�”}”(hXóThere are a number of driver model diagnostic macros in which you should use to make sure messages are matched to the right device and driver, and are tagged with the right level: dev_err(), dev_warn(), dev_info(), and so forth. For messages that aren't associated with a particular device, defines pr_notice(), pr_info(), pr_warn(), pr_err(), etc. When drivers are working properly they are quiet, so prefer to use dev_dbg/pr_debug unless something is wrong.”h]”hXõThere are a number of driver model diagnostic macros in which you should use to make sure messages are matched to the right device and driver, and are tagged with the right level: dev_err(), dev_warn(), dev_info(), and so forth. For messages that aren’t associated with a particular device, defines pr_notice(), pr_info(), pr_warn(), pr_err(), etc. When drivers are working properly they are quiet, so prefer to use dev_dbg/pr_debug unless something is wrong.”…”�”}”(hj,h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M�hj»h²hubhÚ)�”}”(hX(Coming up with good debugging messages can be quite a challenge; and once you have them, they can be a huge help for remote troubleshooting. However debug message printing is handled differently than printing other non-debug messages. While the other pr_XXX() functions print unconditionally, pr_debug() does not; it is compiled out by default, unless either DEBUG is defined or CONFIG_DYNAMIC_DEBUG is set. That is true for dev_dbg() also, and a related convention uses VERBOSE_DEBUG to add dev_vdbg() messages to the ones already enabled by DEBUG.”h]”hX(Coming up with good debugging messages can be quite a challenge; and once you have them, they can be a huge help for remote troubleshooting. However debug message printing is handled differently than printing other non-debug messages. While the other pr_XXX() functions print unconditionally, pr_debug() does not; it is compiled out by default, unless either DEBUG is defined or CONFIG_DYNAMIC_DEBUG is set. That is true for dev_dbg() also, and a related convention uses VERBOSE_DEBUG to add dev_vdbg() messages to the ones already enabled by DEBUG.”…”�”}”(hj:h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M—hj»h²hubhÚ)�”}”(hX*Many subsystems have Kconfig debug options to turn on -DDEBUG in the corresponding Makefile; in other cases specific files #define DEBUG. And when a debug message should be unconditionally printed, such as if it is already inside a debug-related #ifdef section, printk(KERN_DEBUG ...) can be used.”h]”hX*Many subsystems have Kconfig debug options to turn on -DDEBUG in the corresponding Makefile; in other cases specific files #define DEBUG. And when a debug message should be unconditionally printed, such as if it is already inside a debug-related #ifdef section, printk(KERN_DEBUG ...) can be used.”…”�”}”(hjHh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M hj»h²hubeh}”(h]”Œprinting-kernel-messages”ah ]”h"]”Œ13) printing kernel messages”ah$]”h&]”uh1hÄhhÆh²hh³hÃh´M„ubhÅ)�”}”(hhh]”(hÊ)�”}”(hŒ14) Allocating memory”h]”hŒ14) Allocating memory”…”�”}”(hjah²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhj^h²hh³hÃh´M¨ubhÚ)�”}”(hX(The kernel provides the following general purpose memory allocators: kmalloc(), kzalloc(), kmalloc_objs(), kzalloc_objs(), vmalloc(), and vzalloc(). Please refer to the API documentation for further information about them. :ref:`Documentation/core-api/memory-allocation.rst `”h]”(hŒáThe kernel provides the following general purpose memory allocators: kmalloc(), kzalloc(), kmalloc_objs(), kzalloc_objs(), vmalloc(), and vzalloc(). Please refer to the API documentation for further information about them. ”…”�”}”(hjoh²hh³Nh´Nubh)�”}”(hŒG:ref:`Documentation/core-api/memory-allocation.rst `”h]”j»)�”}”(hjyh]”hŒ,Documentation/core-api/memory-allocation.rst”…”�”}”(hj{h²hh³Nh´Nubah}”(h]”h ]”(jÆŒstd”Œstd-ref”eh"]”h$]”h&]”uh1jºhjwubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”jÓŒ refdomain”j…Œreftype”Œref”Œ refexplicit”ˆŒrefwarn”ˆjÙŒmemory_allocation”uh1hh³hÃh´Mªhjoubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´Mªhj^h²hubhÚ)�”}”(hŒCThe preferred form for passing a size of a struct is the following:”h]”hŒCThe preferred form for passing a size of a struct is the following:”…”�”}”(hj�h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M°hj^h²hubj»)�”}”(hŒp = kmalloc_obj(*p, ...);”h]”hŒp = kmalloc_obj(*p, ...);”…”�”}”hj«sbah}”(h]”h ]”h"]”h$]”h&]”jÊjËj̉jÍjÎjÏ}”uh1jºh³hÃh´M²hj^h²hubhÚ)�”}”(hŒãThe alternative form where struct name is spelled out hurts readability and introduces an opportunity for a bug when the pointer variable type is changed but the corresponding sizeof that is passed to a memory allocator is not.”h]”hŒãThe alternative form where struct name is spelled out hurts readability and introduces an opportunity for a bug when the pointer variable type is changed but the corresponding sizeof that is passed to a memory allocator is not.”…”�”}”(hjºh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M¶hj^h²hubhÚ)�”}”(hŒ¦Casting the return value which is a void pointer is redundant. The conversion from void pointer to any other pointer type is guaranteed by the C programming language.”h]”hŒ¦Casting the return value which is a void pointer is redundant. The conversion from void pointer to any other pointer type is guaranteed by the C programming language.”…”�”}”(hjÈh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´Mºhj^h²hubhÚ)�”}”(hŒf))”h]”hŒ/#define sizeof_field(t, f) (sizeof(((t*)0)->f))”…”�”}”hjsbah}”(h]”h ]”h"]”h$]”h&]”jÊjËj̉jÍjÎjÏ}”uh1jºh³hÃh´M>hj»h²hubhÚ)�”}”(hŒwhich is defined in stddef.h.”h]”hŒwhich is defined in stddef.h.”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´MBhj»h²hubhÚ)�”}”(hŒÜThere are also min() and max() macros defined in minmax.h that do strict type checking if you need them. Feel free to peruse the header files to see what else is already defined that you shouldn't reproduce in your code.”h]”hŒÞThere are also min() and max() macros defined in minmax.h that do strict type checking if you need them. Feel free to peruse the header files to see what else is already defined that you shouldn’t reproduce in your code.”…”�”}”(hj"h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´MDhj»h²hubeh}”(h]”Œ!don-t-re-invent-the-kernel-macros”ah ]”h"]”Œ%18) don't re-invent the kernel macros”ah$]”h&]”uh1hÄhhÆh²hh³hÃh´M/ubhÅ)�”}”(hhh]”(hÊ)�”}”(hŒ$19) Editor modelines and other cruft”h]”hŒ$19) Editor modelines and other cruft”…”�”}”(hj;h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhj8h²hh³hÃh´MJubhÚ)�”}”(hŒ¥Some editors can interpret configuration information embedded in source files, indicated with special markers. For example, emacs interprets lines marked like this:”h]”hŒ¥Some editors can interpret configuration information embedded in source files, indicated with special markers. For example, emacs interprets lines marked like this:”…”�”}”(hjIh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´MLhj8h²hubj»)�”}”(hŒ-*- mode: c -*-”h]”hŒ-*- mode: c -*-”…”�”}”hjWsbah}”(h]”h ]”h"]”h$]”h&]”jÊjËj̉jÍjÎjÏ}”uh1jºh³hÃh´MPhj8h²hubhÚ)�”}”(hŒ Or like this:”h]”hŒ Or like this:”…”�”}”(hjfh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´MThj8h²hubj»)�”}”(hŒK/* Local Variables: compile-command: "gcc -DMAGIC_DEBUG_FLAG foo.c" End: */”h]”hŒK/* Local Variables: compile-command: "gcc -DMAGIC_DEBUG_FLAG foo.c" End: */”…”�”}”hjtsbah}”(h]”h ]”h"]”h$]”h&]”jÊjËj̉jÍjÎjÏ}”uh1jºh³hÃh´MVhj8h²hubhÚ)�”}”(hŒ+Vim interprets markers that look like this:”h]”hŒ+Vim interprets markers that look like this:”…”�”}”(hjƒh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M^hj8h²hubj»)�”}”(hŒ/* vim:set sw=8 noet */”h]”hŒ/* vim:set sw=8 noet */”…”�”}”hj‘sbah}”(h]”h ]”h"]”h$]”h&]”jÊjËj̉jÍjÎjÏ}”uh1jºh³hÃh´M`hj8h²hubhÚ)�”}”(hXDDo not include any of these in source files. People have their own personal editor configurations, and your source files should not override them. This includes markers for indentation and mode configuration. People may use their own custom mode, or may have some other magic method for making indentation work correctly.”h]”hXDDo not include any of these in source files. People have their own personal editor configurations, and your source files should not override them. This includes markers for indentation and mode configuration. People may use their own custom mode, or may have some other magic method for making indentation work correctly.”…”�”}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´Mdhj8h²hubeh}”(h]”Œ editor-modelines-and-other-cruft”ah ]”h"]”Œ$19) editor modelines and other cruft”ah$]”h&]”uh1hÄhhÆh²hh³hÃh´MJubhÅ)�”}”(hhh]”(hÊ)�”}”(hŒ20) Inline assembly”h]”hŒ20) Inline assembly”…”�”}”(hj¹h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhj¶h²hh³hÃh´MlubhÚ)�”}”(hXIn architecture-specific code, you may need to use inline assembly to interface with CPU or platform functionality. Don't hesitate to do so when necessary. However, don't use inline assembly gratuitously when C can do the job. You can and should poke hardware from C when possible.”h]”hXIn architecture-specific code, you may need to use inline assembly to interface with CPU or platform functionality. Don’t hesitate to do so when necessary. However, don’t use inline assembly gratuitously when C can do the job. You can and should poke hardware from C when possible.”…”�”}”(hjÇh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´Mnhj¶h²hubhÚ)�”}”(hŒÃConsider writing simple helper functions that wrap common bits of inline assembly, rather than repeatedly writing them with slight variations. Remember that inline assembly can use C parameters.”h]”hŒÃConsider writing simple helper functions that wrap common bits of inline assembly, rather than repeatedly writing them with slight variations. Remember that inline assembly can use C parameters.”…”�”}”(hjÕh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´Mshj¶h²hubhÚ)�”}”(hŒ»Large, non-trivial assembly functions should go in .S files, with corresponding C prototypes defined in C header files. The C prototypes for assembly functions should use ``asmlinkage``.”h]”(hŒ¬Large, non-trivial assembly functions should go in .S files, with corresponding C prototypes defined in C header files. The C prototypes for assembly functions should use ”…”�”}”(hjãh²hh³Nh´Nubjk)�”}”(hŒ``asmlinkage``”h]”hŒ asmlinkage”…”�”}”(hjëh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhjãubhŒ.”…”�”}”(hjãh²hh³Nh´Nubeh•÷P}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´Mwhj¶h²hubhÚ)�”}”(hŒØYou may need to mark your asm statement as volatile, to prevent GCC from removing it if GCC doesn't notice any side effects. You don't always need to do so, though, and doing so unnecessarily can limit optimization.”h]”hŒÜYou may need to mark your asm statement as volatile, to prevent GCC from removing it if GCC doesn’t notice any side effects. You don’t always need to do so, though, and doing so unnecessarily can limit optimization.”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M{hj¶h²hubhÚ)�”}”(hXWhen writing a single inline assembly statement containing multiple instructions, put each instruction on a separate line in a separate quoted string, and end each string except the last with ``\n\t`` to properly indent the next instruction in the assembly output:”h]”(hŒÀWhen writing a single inline assembly statement containing multiple instructions, put each instruction on a separate line in a separate quoted string, and end each string except the last with ”…”�”}”(hjh²hh³Nh´Nubjk)�”}”(hŒ``\n\t``”h]”hŒ\n\t”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhjubhŒ@ to properly indent the next instruction in the assembly output:”…”�”}”(hjh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´Mhj¶h²hubj»)�”}”(hŒqasm ("magic %reg1, #42\n\t" "more_magic %reg2, %reg3" : /* outputs */ : /* inputs */ : /* clobbers */);”h]”hŒqasm ("magic %reg1, #42\n\t" "more_magic %reg2, %reg3" : /* outputs */ : /* inputs */ : /* clobbers */);”…”�”}”hj1sbah}”(h]”h ]”h"]”h$]”h&]”jÊjËj̉jÍjÎjÏ}”uh1jºh³hÃh´M„hj¶h²hubeh}”(h]”Œinline-assembly”ah ]”h"]”Œ20) inline assembly”ah$]”h&]”uh1hÄhhÆh²hh³hÃh´MlubhÅ)�”}”(hhh]”(hÊ)�”}”(hŒ21) Conditional Compilation”h]”hŒ21) Conditional Compilation”…”�”}”(hjKh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhjHh²hh³hÃh´MŒubhÚ)�”}”(hXåWherever possible, don't use preprocessor conditionals (#if, #ifdef) in .c files; doing so makes code harder to read and logic harder to follow. Instead, use such conditionals in a header file defining functions for use in those .c files, providing no-op stub versions in the #else case, and then call those functions unconditionally from .c files. The compiler will avoid generating any code for the stub calls, producing identical results, but the logic will remain easy to follow.”h]”hXçWherever possible, don’t use preprocessor conditionals (#if, #ifdef) in .c files; doing so makes code harder to read and logic harder to follow. Instead, use such conditionals in a header file defining functions for use in those .c files, providing no-op stub versions in the #else case, and then call those functions unconditionally from .c files. The compiler will avoid generating any code for the stub calls, producing identical results, but the logic will remain easy to follow.”…”�”}”(hjYh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´MŽhjHh²hubhÚ)�”}”(hX Prefer to compile out entire functions, rather than portions of functions or portions of expressions. Rather than putting an ifdef in an expression, factor out part or all of the expression into a separate helper function and apply the conditional to that function.”h]”hX Prefer to compile out entire functions, rather than portions of functions or portions of expressions. Rather than putting an ifdef in an expression, factor out part or all of the expression into a separate helper function and apply the conditional to that function.”…”�”}”(hjgh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M–hjHh²hubhÚ)�”}”(hXDIf you have a function or variable which may potentially go unused in a particular configuration, and the compiler would warn about its definition going unused, mark the definition as __maybe_unused rather than wrapping it in a preprocessor conditional. (However, if a function or variable *always* goes unused, delete it.)”h]”(hX#If you have a function or variable which may potentially go unused in a particular configuration, and the compiler would warn about its definition going unused, mark the definition as __maybe_unused rather than wrapping it in a preprocessor conditional. (However, if a function or variable ”…”�”}”(hjuh²hh³Nh´Nubjn)�”}”(hŒ*always*”h]”hŒalways”…”�”}”(hj}h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jmhjuubhŒ goes unused, delete it.)”…”�”}”(hjuh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M›hjHh²hubhÚ)�”}”(hŒ”Within code, where possible, use the IS_ENABLED macro to convert a Kconfig symbol into a C boolean expression, and use it in a normal C conditional:”h]”hŒ”Within code, where possible, use the IS_ENABLED macro to convert a Kconfig symbol into a C boolean expression, and use it in a normal C conditional:”…”�”}”(hj•h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M¡hjHh²hubj»)�”}”(hŒ1if (IS_ENABLED(CONFIG_SOMETHING)) { ... }”h]”hŒ1if (IS_ENABLED(CONFIG_SOMETHING)) { ... }”…”�”}”hj£sbah}”(h]”h ]”h"]”h$]”h&]”jÊjËj̉jÍjÎjÏ}”uh1jºh³hÃh´M¤hjHh²hubhÚ)�”}”(hXÅThe compiler will constant-fold the conditional away, and include or exclude the block of code just as with an #ifdef, so this will not add any runtime overhead. However, this approach still allows the C compiler to see the code inside the block, and check it for correctness (syntax, types, symbol references, etc). Thus, you still have to use an #ifdef if the code inside the block references symbols that will not exist if the condition is not met.”h]”hXÅThe compiler will constant-fold the conditional away, and include or exclude the block of code just as with an #ifdef, so this will not add any runtime overhead. However, this approach still allows the C compiler to see the code inside the block, and check it for correctness (syntax, types, symbol references, etc). Thus, you still have to use an #ifdef if the code inside the block references symbols that will not exist if the condition is not met.”…”�”}”(hj²h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´MªhjHh²hubhÚ)�”}”(hŒ´At the end of any non-trivial #if or #ifdef block (more than a few lines), place a comment after the #endif on the same line, noting the conditional expression used. For instance:”h]”hŒ´At the end of any non-trivial #if or #ifdef block (more than a few lines), place a comment after the #endif on the same line, noting the conditional expression used. For instance:”…”�”}”(hjÀh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M±hjHh²hubj»)�”}”(hŒ9#ifdef CONFIG_SOMETHING ... #endif /* CONFIG_SOMETHING */”h]”hŒ9#ifdef CONFIG_SOMETHING ... #endif /* CONFIG_SOMETHING */”…”�”}”hjÎsbah}”(h]”h ]”h"]”h$]”h&]”jÊjËj̉jÍjÎjÏ}”uh1jºh³hÃh´MµhjHh²hubeh}”(h]”Œconditional-compilation”ah ]”h"]”Œ21) conditional compilation”ah$]”h&]”uh1hÄhhÆh²hh³hÃh´MŒubhÅ)�”}”(hhh]”(hÊ)�”}”(hŒ22) Do not crash the kernel”h]”hŒ22) Do not crash the kernel”…”�”}”(hjèh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhjåh²hh³hÃh´M½ubhÚ)�”}”(hŒfIn general, the decision to crash the kernel belongs to the user, rather than to the kernel developer.”h]”hŒfIn general, the decision to crash the kernel belongs to the user, rather than to the kernel developer.”…”�”}”(hjöh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M¿hjåh²hubhÅ)�”}”(hhh]”(hÊ)�”}”(hŒ Avoid panic()”h]”hŒ Avoid panic()”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhjh²hh³hÃh´MÃubhÚ)�”}”(hŒ²panic() should be used with care and primarily only during system boot. panic() is, for example, acceptable when running out of memory during boot and not being able to continue.”h]”hŒ²panic() should be used with care and primarily only during system boot. panic() is, for example, acceptable when running out of memory during boot and not being able to continue.”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´MÅhjh²hubeh}”(h]”Œ avoid-panic”ah ]”h"]”Œ avoid panic()”ah$]”h&]”uh1hÄhjåh²hh³hÃh´MÃubhÅ)�”}”(hhh]”(hÊ)�”}”(hŒUse WARN() rather than BUG()”h]”hŒUse WARN() rather than BUG()”…”�”}”(hj.h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhj+h²hh³hÃh´MÊubhÚ)�”}”(hXDo not add new code that uses any of the BUG() variants, such as BUG(), BUG_ON(), or VM_BUG_ON(). Instead, use a WARN*() variant, preferably WARN_ON_ONCE(), and possibly with recovery code. Recovery code is not required if there is no reasonable way to at least partially recover.”h]”hXDo not add new code that uses any of the BUG() variants, such as BUG(), BUG_ON(), or VM_BUG_ON(). Instead, use a WARN*() variant, preferably WARN_ON_ONCE(), and possibly with recovery code. Recovery code is not required if there is no reasonable way to at least partially recover.”…”�”}”(hj<h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´MÌhj+h²hubhÚ)�”}”(hŒ¬"I'm too lazy to do error handling" is not an excuse for using BUG(). Major internal corruptions with no way of continuing may still use BUG(), but need good justification.”h]”hŒ²â€œI’m too lazy to do error handlingâ€� is not an excuse for using BUG(). Major internal corruptions with no way of continuing may still use BUG(), but need good justification.”…”�”}”(hjJh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´MÑhj+h²hubeh}”(h]”Œuse-warn-rather-than-bug”ah ]”h"]”Œuse warn() rather than bug()”ah$]”h&]”uh1hÄhjåh²hh³hÃh´MÊubhÅ)�”}”(hhh]”(hÊ)�”}”(hŒ2Use WARN_ON_ONCE() rather than WARN() or WARN_ON()”h]”hŒ2Use WARN_ON_ONCE() rather than WARN() or WARN_ON()”…”�”}”(hjch²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhj`h²hh³hÃh´MÖubhÚ)�”}”(hX2WARN_ON_ONCE() is generally preferred over WARN() or WARN_ON(), because it is common for a given warning condition, if it occurs at all, to occur multiple times. This can fill up and wrap the kernel log, and can even slow the system enough that the excessive logging turns into its own, additional problem.”h]”hX2WARN_ON_ONCE() is generally preferred over WARN() or WARN_ON(), because it is common for a given warning condition, if it occurs at all, to occur multiple times. This can fill up and wrap the kernel log, and can even slow the system enough that the excessive logging turns into its own, additional problem.”…”�”}”(hjqh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´MØhj`h²hubeh}”(h]”Œ,use-warn-on-once-rather-than-warn-or-warn-on”ah ]”h"]”Œ2use warn_on_once() rather than warn() or warn_on()”ah$]”h&]”uh1hÄhjåh²hh³hÃh´MÖubhÅ)�”}”(hhh]”(hÊ)�”}”(hŒDo not WARN lightly”h]”hŒDo not WARN lightly”…”�”}”(hjŠh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhj‡h²hh³hÃh´MßubhÚ)�”}”(hXµWARN*() is intended for unexpected, this-should-never-happen situations. WARN*() macros are not to be used for anything that is expected to happen during normal operation. These are not pre- or post-condition asserts, for example. Again: WARN*() must not be used for a condition that is expected to trigger easily, for example, by user space actions. pr_warn_once() is a possible alternative, if you need to notify the user of a problem.”h]”hXµWARN*() is intended for unexpected, this-should-never-happen situations. WARN*() macros are not to be used for anything that is expected to happen during normal operation. These are not pre- or post-condition asserts, for example. Again: WARN*() must not be used for a condition that is expected to trigger easily, for example, by user space actions. pr_warn_once() is a possible alternative, if you need to notify the user of a problem.”…”�”}”(hj˜h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´Máhj‡h²hubeh}”(h]”Œdo-not-warn-lightly”ah ]”h"]”Œdo not warn lightly”ah$]”h&]”uh1hÄhjåh²hh³hÃh´MßubhÅ)�”}”(hhh]”(hÊ)�”}”(hŒ&Do not worry about panic_on_warn users”h]”hŒ&Do not worry about panic_on_warn users”…”�”}”(hj±h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhj®h²hh³hÃh´MéubhÚ)�”}”(hX A few more words about panic_on_warn: Remember that ``panic_on_warn`` is an available kernel option, and that many users set this option. This is why there is a "Do not WARN lightly" writeup, above. However, the existence of panic_on_warn users is not a valid reason to avoid the judicious use WARN*(). That is because, whoever enables panic_on_warn has explicitly asked the kernel to crash if a WARN*() fires, and such users must be prepared to deal with the consequences of a system that is somewhat more likely to crash.”h]”(hŒ4A few more words about panic_on_warn: Remember that ”…”�”}”(hj¿h²hh³Nh´Nubjk)�”}”(hŒ``panic_on_warn``”h]”hŒ panic_on_warn”…”�”}”(hjÇh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jjhj¿ubhXÊ is an available kernel option, and that many users set this option. This is why there is a “Do not WARN lightlyâ€� writeup, above. However, the existence of panic_on_warn users is not a valid reason to avoid the judicious use WARN*(). That is because, whoever enables panic_on_warn has explicitly asked the kernel to crash if a WARN*() fires, and such users must be prepared to deal with the consequences of a system that is somewhat more likely to crash.”…”�”}”(hj¿h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´Mëhj®h²hubeh}”(h]”Œ&do-not-worry-about-panic-on-warn-users”ah ]”h"]”Œ&do not worry about panic_on_warn users”ah$]”h&]”uh1hÄhjåh²hh³hÃh´MéubhÅ)�”}”(hhh]”(hÊ)�”}”(hŒ.Use BUILD_BUG_ON() for compile-time assertions”h]”hŒ.Use BUILD_BUG_ON() for compile-time assertions”…”�”}”(hjêh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhjçh²hh³hÃh´MõubhÚ)�”}”(hŒ}The use of BUILD_BUG_ON() is acceptable and encouraged, because it is a compile-time assertion that has no effect at runtime.”h]”hŒ}The use of BUILD_BUG_ON() is acceptable and encouraged, because it is a compile-time assertion that has no effect at runtime.”…”�”}”(hjøh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M÷hjçh²hubeh}”(h]”Œ,use-build-bug-on-for-compile-time-assertions”ah ]”h"]”Œ.use build_bug_on() for compile-time assertions”ah$]”h&]”uh1hÄhjåh²hh³hÃh´Mõubeh}”(h]”Œdo-not-crash-the-kernel”ah ]”h"]”Œ22) do not crash the kernel”ah$]”h&]”uh1hÄhhÆh²hh³hÃh´M½ubhÅ)�”}”(hhh]”(hÊ)�”}”(hŒAppendix I) References”h]”hŒAppendix I) References”…”�”}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÉhjh²hh³hÃh´MûubhÚ)�”}”(hŒ¬The C Programming Language, Second Edition by Brian W. Kernighan and Dennis M. Ritchie. Prentice Hall, Inc., 1988. ISBN 0-13-110362-8 (paperback), 0-13-110370-9 (hardback).”h]”hŒ¬The C Programming Language, Second Edition by Brian W. Kernighan and Dennis M. Ritchie. Prentice Hall, Inc., 1988. ISBN 0-13-110362-8 (paperback), 0-13-110370-9 (hardback).”…”�”}”(hj'h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´Mýhjh²hubhÚ)�”}”(hŒoThe Practice of Programming by Brian W. Kernighan and Rob Pike. Addison-Wesley, Inc., 1999. ISBN 0-201-61586-X.”h]”hŒoThe Practice of Programming by Brian W. Kernighan and Rob Pike. Addison-Wesley, Inc., 1999. ISBN 0-201-61586-X.”…”�”}”(hj5h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´Mhjh²hubhÚ)�”}”(hŒ‘GNU manuals - where in compliance with K&R and this text - for cpp, gcc, gcc internals and indent, all available from https://www.gnu.org/manual/”h]”(hŒvGNU manuals - where in compliance with K&R and this text - for cpp, gcc, gcc internals and indent, all available from ”…”�”}”(hjCh²hh³Nh´Nubj˜ )�”}”(hŒhttps://www.gnu.org/manual/”h]”hŒhttps://www.gnu.org/manual/”…”�”}”(hjKh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”Œrefuri”jMuh1j— hjCubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´Mhjh²hubhÚ)�”}”(hŒ„WG14 is the international standardization working group for the programming language C, URL: http://www.open-std.org/JTC1/SC22/WG14/”h]”(hŒ]WG14 is the international standardization working group for the programming language C, URL: ”…”�”}”(hj`h²hh³Nh´Nubj˜ )�”}”(hŒ'http://www.open-std.org/JTC1/SC22/WG14/”h]”hŒ'http://www.open-std.org/JTC1/SC22/WG14/”…”�”}”(hjhh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”Œrefuri”jjuh1j— hj`ubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M hjh²hubhÚ)�”}”(hŒzKernel CodingStyle, by greg@kroah.com at OLS 2002: http://www.kroah.com/linux/talks/ols_2002_kernel_codingstyle_talk/html/”h]”(hŒKernel CodingStyle, by ”…”�”}”(hj}h²hh³Nh´Nubj˜ )�”}”(hŒgreg@kroah.com”h]”hŒgreg@kroah.com”…”�”}”(hj…h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”Œrefuri”Œmailto:greg@kroah.com”uh1j— hj}ubhŒ at OLS 2002: ”…”�”}”(hj}h²hh³Nh´Nubj˜ )�”}”(hŒGhttp://www.kroah.com/linux/talks/ols_2002_kernel_codingstyle_talk/html/”h]”hŒGhttp://www.kroah.com/linux/talks/ols_2002_kernel_codingstyle_talk/html/”…”�”}”(hj™h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”Œrefuri”j›uh1j— hj}ubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÙh³hÃh´M hjh²hubeh}”(h]”Œappendix-i-references”ah ]”h"]”Œappendix i) references”ah$]”h&]”uh1hÄhhÆh²hh³hÃh´Mûubeh}”(h]”(Œlinux-kernel-coding-style”hÂeh ]”h"]”(Œlinux kernel coding style”Œ codingstyle”eh$]”h&]”uh1hÄhhh²hh³hÃh´KŒexpect_referenced_by_name”}”j¼h·sŒexpect_referenced_by_id”}”hÂh·subeh}”(h]”h ]”h"]”h$]”h&]”Œsource”hÃuh1hŒcurrent_source”NŒ current_line”NŒsettings”Œdocutils.frontend”ŒValues”“”)�”}”(hÉNŒ generator”NŒ datestamp”NŒ source_link”NŒ source_url”NŒ toc_backlinks”Œentry”Œfootnote_backlinks”KŒ sectnum_xform”KŒstrip_comments”NŒstrip_elements_with_classes”NŒ strip_classes”NŒ report_level”KŒ halt_level”KŒexit_status_level”KŒdebug”NŒwarning_stream”NŒ traceback”ˆŒinput_encoding”Œ utf-8-sig”Œinput_encoding_error_handler”Œstrict”Œoutput_encoding”Œutf-8”Œoutput_encoding_error_handler”jæŒerror_encoding”Œutf-8”Œerror_encoding_error_handler”Œbackslashreplace”Œ language_code”Œen”Œrecord_dependencies”NŒconfig”NŒ id_prefix”hŒauto_id_prefix”Œid”Œ dump_settings”NŒdump_internals”NŒdump_transforms”NŒdump_pseudo_xml”NŒexpose_internals”NŒstrict_visitor”NŒ_disable_config”NŒ_source”hÃŒ _destination”NŒ _config_files”]”Œ7/var/lib/git/docbuild/linux/Documentation/docutils.conf”aŒfile_insertion_enabled”ˆŒ raw_enabled”KŒline_length_limit”M'Œpep_references”NŒ pep_base_url”Œhttps://peps.python.org/”Œpep_file_url_template”Œpep-%04d”Œrfc_references”NŒ rfc_base_url”Œ&https://datatracker.ietf.org/doc/html/”Œ tab_width”KŒtrim_footnote_reference_space”‰Œsyntax_highlight”Œlong”Œ smart_quotes”ˆŒsmartquotes_locales”]”Œcharacter_level_inline_markup”‰Œdoctitle_xform”‰Œ docinfo_xform”KŒsectsubtitle_xform”‰Œ image_loading”Œlink”Œembed_stylesheet”‰Œcloak_email_addresses”ˆŒsection_self_link”‰Œenv”NubŒreporter”NŒindirect_targets”]”Œsubstitution_defs”}”Œsubstitution_names”}”Œrefnames”}”Œrefids”}”hÂ]”h·asŒnameids”}”(j¼hÂj»j¸jWjTjÄjÁjjjþjûj j�jÕ jÒ jÍ jÊ jÅ j j´ j± jljij'j$j£j jjjíjêj¸jµj[jXj1j.jšj—j=j:j¸jµj5j2j³j°jEjBjâjßjjj(j%j]jZj„j�j«j¨jäjáj jj³j°uŒ nametypes”}”(j¼ˆj»‰jW‰jĉj‰jþ‰j ‰jÕ ‰jÍ ‰jÅ ‰j´ ˆjl‰j'‰j£‰j‰jí‰j¸‰j[‰j1‰jš‰j=‰j¸‰j5‰j³‰jE‰jâ‰j‰j(‰j]‰j„‰j«‰jä‰j ‰j³‰uh}”(hÂhÆj¸hÆjTjjÁjZjjÇjûjOj�j jÒ j£jÊ jØ j jP j± j« jijÐ j$joj j*jj¦jêjjµjðjXj»j.j^j—j4j:j�jµj@j2j»j°j8jBj¶jßjHjjåj%jjZj+j�j`j¨j‡jáj®jjçj°juŒ footnote_refs”}”Œ citation_refs”}”Œ autofootnotes”]”Œautofootnote_refs”]”Œsymbol_footnotes”]”Œsymbol_footnote_refs”]”Œ footnotes”]”Œ citations”]”Œautofootnote_start”KŒsymbol_footnote_start”KŒ id_counter”Œ collections”ŒCounter”“”}”…”R”Œparse_messages”]”hŒsystem_message”“”)�”}”(hhh]”hÚ)�”}”(hŒ:Enumerated list start value not ordinal-1: "2" (ordinal 2)”h]”hŒ>Enumerated list start value not ordinal-1: “2â€� (ordinal 2)”…”�”}”(hjNh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÙhjKubah}”(h]”h ]”h"]”h$]”h&]”Œlevel”KŒtype”ŒINFO”Œsource”hÃŒline”Kuh1jIhjðh²hh³hÃh´M[ubaŒtransform_messages”]”jJ)�”}”(hhh]”hÚ)�”}”(hhh]”hŒ1Hyperlink target "codingstyle" is not referenced.”…”�”}”hjlsbah}”(h]”h ]”h"]”h$]”h&]”uh1hÙhjiubah}”(h]”h ]”h"]”h$]”h&]”Œlevel”KŒtype”jdŒsource”hÃŒline”Kuh1jIubaŒ transformer”NŒ include_log”]”Œ decoration”Nh²hub.