contributing.rst 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. .. SPDX-License-Identifier: GPL-2.0
  2. How to help improve kernel documentation
  3. ========================================
  4. Documentation is an important part of any software-development project.
  5. Good documentation helps to bring new developers in and helps established
  6. developers work more effectively. Without top-quality documentation, a lot
  7. of time is wasted in reverse-engineering the code and making avoidable
  8. mistakes.
  9. Unfortunately, the kernel's documentation currently falls far short of what
  10. it needs to be to support a project of this size and importance.
  11. This guide is for contributors who would like to improve that situation.
  12. Kernel documentation improvements can be made by developers at a variety of
  13. skill levels; they are a relatively easy way to learn the kernel process in
  14. general and find a place in the community. The bulk of what follows is the
  15. documentation maintainer's list of tasks that most urgently need to be
  16. done.
  17. The documentation TODO list
  18. ---------------------------
  19. There is an endless list of tasks that need to be carried out to get our
  20. documentation to where it should be. This list contains a number of
  21. important items, but is far from exhaustive; if you see a different way to
  22. improve the documentation, please do not hold back!
  23. Addressing warnings
  24. ~~~~~~~~~~~~~~~~~~~
  25. The documentation build currently spews out an unbelievable number of
  26. warnings. When you have that many, you might as well have none at all;
  27. people ignore them, and they will never notice when their work adds new
  28. ones. For this reason, eliminating warnings is one of the highest-priority
  29. tasks on the documentation TODO list. The task itself is reasonably
  30. straightforward, but it must be approached in the right way to be
  31. successful.
  32. Warnings issued by a compiler for C code can often be dismissed as false
  33. positives, leading to patches aimed at simply shutting the compiler up.
  34. Warnings from the documentation build almost always point at a real
  35. problem; making those warnings go away requires understanding the problem
  36. and fixing it at its source. For this reason, patches fixing documentation
  37. warnings should probably not say "fix a warning" in the changelog title;
  38. they should indicate the real problem that has been fixed.
  39. Another important point is that documentation warnings are often created by
  40. problems in kerneldoc comments in C code. While the documentation
  41. maintainer appreciates being copied on fixes for these warnings, the
  42. documentation tree is often not the right one to actually carry those
  43. fixes; they should go to the maintainer of the subsystem in question.
  44. For example, in a documentation build I grabbed a pair of warnings nearly
  45. at random::
  46. ./drivers/devfreq/devfreq.c:1818: warning: bad line:
  47. - Resource-managed devfreq_register_notifier()
  48. ./drivers/devfreq/devfreq.c:1854: warning: bad line:
  49. - Resource-managed devfreq_unregister_notifier()
  50. (The lines were split for readability).
  51. A quick look at the source file named above turned up a couple of kerneldoc
  52. comments that look like this::
  53. /**
  54. * devm_devfreq_register_notifier()
  55. - Resource-managed devfreq_register_notifier()
  56. * @dev: The devfreq user device. (parent of devfreq)
  57. * @devfreq: The devfreq object.
  58. * @nb: The notifier block to be unregistered.
  59. * @list: DEVFREQ_TRANSITION_NOTIFIER.
  60. */
  61. The problem is the missing "*", which confuses the build system's
  62. simplistic idea of what C comment blocks look like. This problem had been
  63. present since that comment was added in 2016 — a full four years. Fixing
  64. it was a matter of adding the missing asterisks. A quick look at the
  65. history for that file showed what the normal format for subject lines is,
  66. and ``scripts/get_maintainer.pl`` told me who should receive it. The
  67. resulting patch looked like this::
  68. [PATCH] PM / devfreq: Fix two malformed kerneldoc comments
  69. Two kerneldoc comments in devfreq.c fail to adhere to the required format,
  70. resulting in these doc-build warnings:
  71. ./drivers/devfreq/devfreq.c:1818: warning: bad line:
  72. - Resource-managed devfreq_register_notifier()
  73. ./drivers/devfreq/devfreq.c:1854: warning: bad line:
  74. - Resource-managed devfreq_unregister_notifier()
  75. Add a couple of missing asterisks and make kerneldoc a little happier.
  76. Signed-off-by: Jonathan Corbet <corbet@lwn.net>
  77. ---
  78. drivers/devfreq/devfreq.c | 4 ++--
  79. 1 file changed, 2 insertions(+), 2 deletions(-)
  80. diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
  81. index 57f6944d65a6..00c9b80b3d33 100644
  82. --- a/drivers/devfreq/devfreq.c
  83. +++ b/drivers/devfreq/devfreq.c
  84. @@ -1814,7 +1814,7 @@ static void devm_devfreq_notifier_release(struct device *dev, void *res)
  85. /**
  86. * devm_devfreq_register_notifier()
  87. - - Resource-managed devfreq_register_notifier()
  88. + * - Resource-managed devfreq_register_notifier()
  89. * @dev: The devfreq user device. (parent of devfreq)
  90. * @devfreq: The devfreq object.
  91. * @nb: The notifier block to be unregistered.
  92. @@ -1850,7 +1850,7 @@ EXPORT_SYMBOL(devm_devfreq_register_notifier);
  93. /**
  94. * devm_devfreq_unregister_notifier()
  95. - - Resource-managed devfreq_unregister_notifier()
  96. + * - Resource-managed devfreq_unregister_notifier()
  97. * @dev: The devfreq user device. (parent of devfreq)
  98. * @devfreq: The devfreq object.
  99. * @nb: The notifier block to be unregistered.
  100. --
  101. 2.24.1
  102. The entire process only took a few minutes. Of course, I then found that
  103. somebody else had fixed it in a separate tree, highlighting another lesson:
  104. always check linux-next to see if a problem has been fixed before you dig
  105. into it.
  106. Other fixes will take longer, especially those relating to structure
  107. members or function parameters that lack documentation. In such cases, it
  108. is necessary to work out what the role of those members or parameters is
  109. and describe them correctly. Overall, this task gets a little tedious at
  110. times, but it's highly important. If we can actually eliminate warnings
  111. from the documentation build, then we can start expecting developers to
  112. avoid adding new ones.
  113. Languishing kerneldoc comments
  114. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  115. Developers are encouraged to write kerneldoc comments for their code, but
  116. many of those comments are never pulled into the docs build. That makes
  117. this information harder to find and, for example, makes Sphinx unable to
  118. generate links to that documentation. Adding ``kernel-doc`` directives to
  119. the documentation to bring those comments in can help the community derive
  120. the full value of the work that has gone into creating them.
  121. The ``scripts/find-unused-docs.sh`` tool can be used to find these
  122. overlooked comments.
  123. Note that the most value comes from pulling in the documentation for
  124. exported functions and data structures. Many subsystems also have
  125. kerneldoc comments for internal use; those should not be pulled into the
  126. documentation build unless they are placed in a document that is
  127. specifically aimed at developers working within the relevant subsystem.
  128. Typo fixes
  129. ~~~~~~~~~~
  130. Fixing typographical or formatting errors in the documentation is a quick
  131. way to figure out how to create and send patches, and it is a useful
  132. service. I am always willing to accept such patches. That said, once you
  133. have fixed a few, please consider moving on to more advanced tasks, leaving
  134. some typos for the next beginner to address.
  135. Please note that some things are *not* typos and should not be "fixed":
  136. - Both American and British English spellings are allowed within the
  137. kernel documentation. There is no need to fix one by replacing it with
  138. the other.
  139. - The question of whether a period should be followed by one or two spaces
  140. is not to be debated in the context of kernel documentation. Other
  141. areas of rational disagreement, such as the "Oxford comma", are also
  142. off-topic here.
  143. As with any patch to any project, please consider whether your change is
  144. really making things better.
  145. Ancient documentation
  146. ~~~~~~~~~~~~~~~~~~~~~
  147. Some kernel documentation is current, maintained, and useful. Some
  148. documentation is ... not. Dusty, old, and inaccurate documentation can
  149. mislead readers and casts doubt on our documentation as a whole. Anything
  150. that can be done to address such problems is more than welcome.
  151. Whenever you are working with a document, please consider whether it is
  152. current, whether it needs updating, or whether it should perhaps be removed
  153. altogether. There are a number of warning signs that you can pay attention
  154. to here:
  155. - References to 2.x kernels
  156. - Pointers to SourceForge repositories
  157. - Nothing but typo fixes in the history for several years
  158. - Discussion of pre-Git workflows
  159. The best thing to do, of course, would be to bring the documentation
  160. current, adding whatever information is needed. Such work often requires
  161. the cooperation of developers familiar with the subsystem in question, of
  162. course. Developers are often more than willing to cooperate with people
  163. working to improve the documentation when asked nicely, and when their
  164. answers are listened to and acted upon.
  165. Some documentation is beyond hope; we occasionally find documents that
  166. refer to code that was removed from the kernel long ago, for example.
  167. There is surprising resistance to removing obsolete documentation, but we
  168. should do that anyway. Extra cruft in our documentation helps nobody.
  169. In cases where there is perhaps some useful information in a badly outdated
  170. document, and you are unable to update it, the best thing to do may be to
  171. add a warning at the beginning. The following text is recommended::
  172. .. warning ::
  173. This document is outdated and in need of attention. Please use
  174. this information with caution, and please consider sending patches
  175. to update it.
  176. That way, at least our long-suffering readers have been warned that the
  177. document may lead them astray.
  178. Documentation coherency
  179. ~~~~~~~~~~~~~~~~~~~~~~~
  180. The old-timers around here will remember the Linux books that showed up on
  181. the shelves in the 1990s. They were simply collections of documentation
  182. files scrounged from various locations on the net. The books have (mostly)
  183. improved since then, but the kernel's documentation is still mostly built
  184. on that model. It is thousands of files, almost each of which was written
  185. in isolation from all of the others. We don't have a coherent body of
  186. kernel documentation; we have thousands of individual documents.
  187. We have been trying to improve the situation through the creation of
  188. a set of "books" that group documentation for specific readers. These
  189. include:
  190. - :doc:`../admin-guide/index`
  191. - :doc:`../core-api/index`
  192. - :doc:`../driver-api/index`
  193. - :doc:`../userspace-api/index`
  194. As well as this book on documentation itself.
  195. Moving documents into the appropriate books is an important task and needs
  196. to continue. There are a couple of challenges associated with this work,
  197. though. Moving documentation files creates short-term pain for the people
  198. who work with those files; they are understandably unenthusiastic about
  199. such changes. Usually the case can be made to move a document once; we
  200. really don't want to keep shifting them around, though.
  201. Even when all documents are in the right place, though, we have only
  202. managed to turn a big pile into a group of smaller piles. The work of
  203. trying to knit all of those documents together into a single whole has not
  204. yet begun. If you have bright ideas on how we could proceed on that front,
  205. we would be more than happy to hear them.
  206. Stylesheet improvements
  207. ~~~~~~~~~~~~~~~~~~~~~~~
  208. With the adoption of Sphinx we have much nicer-looking HTML output than we
  209. once did. But it could still use a lot of improvement; Donald Knuth and
  210. Edward Tufte would be unimpressed. That requires tweaking our stylesheets
  211. to create more typographically sound, accessible, and readable output.
  212. Be warned: if you take on this task you are heading into classic bikeshed
  213. territory. Expect a lot of opinions and discussion for even relatively
  214. obvious changes. That is, alas, the nature of the world we live in.
  215. Non-LaTeX PDF build
  216. ~~~~~~~~~~~~~~~~~~~
  217. This is a decidedly nontrivial task for somebody with a lot of time and
  218. Python skills. The Sphinx toolchain is relatively small and well
  219. contained; it is easy to add to a development system. But building PDF or
  220. EPUB output requires installing LaTeX, which is anything but small or well
  221. contained. That would be a nice thing to eliminate.
  222. The original hope had been to use the rst2pdf tool (https://rst2pdf.org/)
  223. for PDF generation, but it turned out to not be up to the task.
  224. Development work on rst2pdf seems to have picked up again in recent times,
  225. though, which is a hopeful sign. If a suitably motivated developer were to
  226. work with that project to make rst2pdf work with the kernel documentation
  227. build, the world would be eternally grateful.
  228. Write more documentation
  229. ~~~~~~~~~~~~~~~~~~~~~~~~
  230. Naturally, there are massive parts of the kernel that are severely
  231. underdocumented. If you have the knowledge to document a specific kernel
  232. subsystem and the desire to do so, please do not hesitate to do some
  233. writing and contribute the result to the kernel. Untold numbers of kernel
  234. developers and users will thank you.