0001 .. SPDX-License-Identifier: GPL-2.0
0002
0003 How to help improve kernel documentation
0004 ========================================
0005
0006 Documentation is an important part of any software-development project.
0007 Good documentation helps to bring new developers in and helps established
0008 developers work more effectively. Without top-quality documentation, a lot
0009 of time is wasted in reverse-engineering the code and making avoidable
0010 mistakes.
0011
0012 Unfortunately, the kernel's documentation currently falls far short of what
0013 it needs to be to support a project of this size and importance.
0014
0015 This guide is for contributors who would like to improve that situation.
0016 Kernel documentation improvements can be made by developers at a variety of
0017 skill levels; they are a relatively easy way to learn the kernel process in
0018 general and find a place in the community. The bulk of what follows is the
0019 documentation maintainer's list of tasks that most urgently need to be
0020 done.
0021
0022 The documentation TODO list
0023 ---------------------------
0024
0025 There is an endless list of tasks that need to be carried out to get our
0026 documentation to where it should be. This list contains a number of
0027 important items, but is far from exhaustive; if you see a different way to
0028 improve the documentation, please do not hold back!
0029
0030 Addressing warnings
0031 ~~~~~~~~~~~~~~~~~~~
0032
0033 The documentation build currently spews out an unbelievable number of
0034 warnings. When you have that many, you might as well have none at all;
0035 people ignore them, and they will never notice when their work adds new
0036 ones. For this reason, eliminating warnings is one of the highest-priority
0037 tasks on the documentation TODO list. The task itself is reasonably
0038 straightforward, but it must be approached in the right way to be
0039 successful.
0040
0041 Warnings issued by a compiler for C code can often be dismissed as false
0042 positives, leading to patches aimed at simply shutting the compiler up.
0043 Warnings from the documentation build almost always point at a real
0044 problem; making those warnings go away requires understanding the problem
0045 and fixing it at its source. For this reason, patches fixing documentation
0046 warnings should probably not say "fix a warning" in the changelog title;
0047 they should indicate the real problem that has been fixed.
0048
0049 Another important point is that documentation warnings are often created by
0050 problems in kerneldoc comments in C code. While the documentation
0051 maintainer appreciates being copied on fixes for these warnings, the
0052 documentation tree is often not the right one to actually carry those
0053 fixes; they should go to the maintainer of the subsystem in question.
0054
0055 For example, in a documentation build I grabbed a pair of warnings nearly
0056 at random::
0057
0058 ./drivers/devfreq/devfreq.c:1818: warning: bad line:
0059 - Resource-managed devfreq_register_notifier()
0060 ./drivers/devfreq/devfreq.c:1854: warning: bad line:
0061 - Resource-managed devfreq_unregister_notifier()
0062
0063 (The lines were split for readability).
0064
0065 A quick look at the source file named above turned up a couple of kerneldoc
0066 comments that look like this::
0067
0068 /**
0069 * devm_devfreq_register_notifier()
0070 - Resource-managed devfreq_register_notifier()
0071 * @dev: The devfreq user device. (parent of devfreq)
0072 * @devfreq: The devfreq object.
0073 * @nb: The notifier block to be unregistered.
0074 * @list: DEVFREQ_TRANSITION_NOTIFIER.
0075 */
0076
0077 The problem is the missing "*", which confuses the build system's
0078 simplistic idea of what C comment blocks look like. This problem had been
0079 present since that comment was added in 2016 — a full four years. Fixing
0080 it was a matter of adding the missing asterisks. A quick look at the
0081 history for that file showed what the normal format for subject lines is,
0082 and ``scripts/get_maintainer.pl`` told me who should receive it (pass paths to
0083 your patches as arguments to scripts/get_maintainer.pl). The resulting patch
0084 looked like this::
0085
0086 [PATCH] PM / devfreq: Fix two malformed kerneldoc comments
0087
0088 Two kerneldoc comments in devfreq.c fail to adhere to the required format,
0089 resulting in these doc-build warnings:
0090
0091 ./drivers/devfreq/devfreq.c:1818: warning: bad line:
0092 - Resource-managed devfreq_register_notifier()
0093 ./drivers/devfreq/devfreq.c:1854: warning: bad line:
0094 - Resource-managed devfreq_unregister_notifier()
0095
0096 Add a couple of missing asterisks and make kerneldoc a little happier.
0097
0098 Signed-off-by: Jonathan Corbet <corbet@lwn.net>
0099 ---
0100 drivers/devfreq/devfreq.c | 4 ++--
0101 1 file changed, 2 insertions(+), 2 deletions(-)
0102
0103 diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
0104 index 57f6944d65a6..00c9b80b3d33 100644
0105 --- a/drivers/devfreq/devfreq.c
0106 +++ b/drivers/devfreq/devfreq.c
0107 @@ -1814,7 +1814,7 @@ static void devm_devfreq_notifier_release(struct device *dev, void *res)
0108
0109 /**
0110 * devm_devfreq_register_notifier()
0111 - - Resource-managed devfreq_register_notifier()
0112 + * - Resource-managed devfreq_register_notifier()
0113 * @dev: The devfreq user device. (parent of devfreq)
0114 * @devfreq: The devfreq object.
0115 * @nb: The notifier block to be unregistered.
0116 @@ -1850,7 +1850,7 @@ EXPORT_SYMBOL(devm_devfreq_register_notifier);
0117
0118 /**
0119 * devm_devfreq_unregister_notifier()
0120 - - Resource-managed devfreq_unregister_notifier()
0121 + * - Resource-managed devfreq_unregister_notifier()
0122 * @dev: The devfreq user device. (parent of devfreq)
0123 * @devfreq: The devfreq object.
0124 * @nb: The notifier block to be unregistered.
0125 --
0126 2.24.1
0127
0128 The entire process only took a few minutes. Of course, I then found that
0129 somebody else had fixed it in a separate tree, highlighting another lesson:
0130 always check linux-next to see if a problem has been fixed before you dig
0131 into it.
0132
0133 Other fixes will take longer, especially those relating to structure
0134 members or function parameters that lack documentation. In such cases, it
0135 is necessary to work out what the role of those members or parameters is
0136 and describe them correctly. Overall, this task gets a little tedious at
0137 times, but it's highly important. If we can actually eliminate warnings
0138 from the documentation build, then we can start expecting developers to
0139 avoid adding new ones.
0140
0141 Languishing kerneldoc comments
0142 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0143
0144 Developers are encouraged to write kerneldoc comments for their code, but
0145 many of those comments are never pulled into the docs build. That makes
0146 this information harder to find and, for example, makes Sphinx unable to
0147 generate links to that documentation. Adding ``kernel-doc`` directives to
0148 the documentation to bring those comments in can help the community derive
0149 the full value of the work that has gone into creating them.
0150
0151 The ``scripts/find-unused-docs.sh`` tool can be used to find these
0152 overlooked comments.
0153
0154 Note that the most value comes from pulling in the documentation for
0155 exported functions and data structures. Many subsystems also have
0156 kerneldoc comments for internal use; those should not be pulled into the
0157 documentation build unless they are placed in a document that is
0158 specifically aimed at developers working within the relevant subsystem.
0159
0160
0161 Typo fixes
0162 ~~~~~~~~~~
0163
0164 Fixing typographical or formatting errors in the documentation is a quick
0165 way to figure out how to create and send patches, and it is a useful
0166 service. I am always willing to accept such patches. That said, once you
0167 have fixed a few, please consider moving on to more advanced tasks, leaving
0168 some typos for the next beginner to address.
0169
0170 Please note that some things are *not* typos and should not be "fixed":
0171
0172 - Both American and British English spellings are allowed within the
0173 kernel documentation. There is no need to fix one by replacing it with
0174 the other.
0175
0176 - The question of whether a period should be followed by one or two spaces
0177 is not to be debated in the context of kernel documentation. Other
0178 areas of rational disagreement, such as the "Oxford comma", are also
0179 off-topic here.
0180
0181 As with any patch to any project, please consider whether your change is
0182 really making things better.
0183
0184 Ancient documentation
0185 ~~~~~~~~~~~~~~~~~~~~~
0186
0187 Some kernel documentation is current, maintained, and useful. Some
0188 documentation is ... not. Dusty, old, and inaccurate documentation can
0189 mislead readers and casts doubt on our documentation as a whole. Anything
0190 that can be done to address such problems is more than welcome.
0191
0192 Whenever you are working with a document, please consider whether it is
0193 current, whether it needs updating, or whether it should perhaps be removed
0194 altogether. There are a number of warning signs that you can pay attention
0195 to here:
0196
0197 - References to 2.x kernels
0198 - Pointers to SourceForge repositories
0199 - Nothing but typo fixes in the history for several years
0200 - Discussion of pre-Git workflows
0201
0202 The best thing to do, of course, would be to bring the documentation
0203 current, adding whatever information is needed. Such work often requires
0204 the cooperation of developers familiar with the subsystem in question, of
0205 course. Developers are often more than willing to cooperate with people
0206 working to improve the documentation when asked nicely, and when their
0207 answers are listened to and acted upon.
0208
0209 Some documentation is beyond hope; we occasionally find documents that
0210 refer to code that was removed from the kernel long ago, for example.
0211 There is surprising resistance to removing obsolete documentation, but we
0212 should do that anyway. Extra cruft in our documentation helps nobody.
0213
0214 In cases where there is perhaps some useful information in a badly outdated
0215 document, and you are unable to update it, the best thing to do may be to
0216 add a warning at the beginning. The following text is recommended::
0217
0218 .. warning ::
0219 This document is outdated and in need of attention. Please use
0220 this information with caution, and please consider sending patches
0221 to update it.
0222
0223 That way, at least our long-suffering readers have been warned that the
0224 document may lead them astray.
0225
0226 Documentation coherency
0227 ~~~~~~~~~~~~~~~~~~~~~~~
0228
0229 The old-timers around here will remember the Linux books that showed up on
0230 the shelves in the 1990s. They were simply collections of documentation
0231 files scrounged from various locations on the net. The books have (mostly)
0232 improved since then, but the kernel's documentation is still mostly built
0233 on that model. It is thousands of files, almost each of which was written
0234 in isolation from all of the others. We don't have a coherent body of
0235 kernel documentation; we have thousands of individual documents.
0236
0237 We have been trying to improve the situation through the creation of
0238 a set of "books" that group documentation for specific readers. These
0239 include:
0240
0241 - Documentation/admin-guide/index.rst
0242 - Documentation/core-api/index.rst
0243 - Documentation/driver-api/index.rst
0244 - Documentation/userspace-api/index.rst
0245
0246 As well as this book on documentation itself.
0247
0248 Moving documents into the appropriate books is an important task and needs
0249 to continue. There are a couple of challenges associated with this work,
0250 though. Moving documentation files creates short-term pain for the people
0251 who work with those files; they are understandably unenthusiastic about
0252 such changes. Usually the case can be made to move a document once; we
0253 really don't want to keep shifting them around, though.
0254
0255 Even when all documents are in the right place, though, we have only
0256 managed to turn a big pile into a group of smaller piles. The work of
0257 trying to knit all of those documents together into a single whole has not
0258 yet begun. If you have bright ideas on how we could proceed on that front,
0259 we would be more than happy to hear them.
0260
0261 Stylesheet improvements
0262 ~~~~~~~~~~~~~~~~~~~~~~~
0263
0264 With the adoption of Sphinx we have much nicer-looking HTML output than we
0265 once did. But it could still use a lot of improvement; Donald Knuth and
0266 Edward Tufte would be unimpressed. That requires tweaking our stylesheets
0267 to create more typographically sound, accessible, and readable output.
0268
0269 Be warned: if you take on this task you are heading into classic bikeshed
0270 territory. Expect a lot of opinions and discussion for even relatively
0271 obvious changes. That is, alas, the nature of the world we live in.
0272
0273 Non-LaTeX PDF build
0274 ~~~~~~~~~~~~~~~~~~~
0275
0276 This is a decidedly nontrivial task for somebody with a lot of time and
0277 Python skills. The Sphinx toolchain is relatively small and well
0278 contained; it is easy to add to a development system. But building PDF or
0279 EPUB output requires installing LaTeX, which is anything but small or well
0280 contained. That would be a nice thing to eliminate.
0281
0282 The original hope had been to use the rst2pdf tool (https://rst2pdf.org/)
0283 for PDF generation, but it turned out to not be up to the task.
0284 Development work on rst2pdf seems to have picked up again in recent times,
0285 though, which is a hopeful sign. If a suitably motivated developer were to
0286 work with that project to make rst2pdf work with the kernel documentation
0287 build, the world would be eternally grateful.
0288
0289 Write more documentation
0290 ~~~~~~~~~~~~~~~~~~~~~~~~
0291
0292 Naturally, there are massive parts of the kernel that are severely
0293 underdocumented. If you have the knowledge to document a specific kernel
0294 subsystem and the desire to do so, please do not hesitate to do some
0295 writing and contribute the result to the kernel. Untold numbers of kernel
0296 developers and users will thank you.