18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci
38c2ecf20Sopenharmony_ciHow to help improve kernel documentation
48c2ecf20Sopenharmony_ci========================================
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ciDocumentation is an important part of any software-development project.
78c2ecf20Sopenharmony_ciGood documentation helps to bring new developers in and helps established
88c2ecf20Sopenharmony_cidevelopers work more effectively.  Without top-quality documentation, a lot
98c2ecf20Sopenharmony_ciof time is wasted in reverse-engineering the code and making avoidable
108c2ecf20Sopenharmony_cimistakes.
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ciUnfortunately, the kernel's documentation currently falls far short of what
138c2ecf20Sopenharmony_ciit needs to be to support a project of this size and importance.
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ciThis guide is for contributors who would like to improve that situation.
168c2ecf20Sopenharmony_ciKernel documentation improvements can be made by developers at a variety of
178c2ecf20Sopenharmony_ciskill levels; they are a relatively easy way to learn the kernel process in
188c2ecf20Sopenharmony_cigeneral and find a place in the community.  The bulk of what follows is the
198c2ecf20Sopenharmony_cidocumentation maintainer's list of tasks that most urgently need to be
208c2ecf20Sopenharmony_cidone.
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ciThe documentation TODO list
238c2ecf20Sopenharmony_ci---------------------------
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ciThere is an endless list of tasks that need to be carried out to get our
268c2ecf20Sopenharmony_cidocumentation to where it should be.  This list contains a number of
278c2ecf20Sopenharmony_ciimportant items, but is far from exhaustive; if you see a different way to
288c2ecf20Sopenharmony_ciimprove the documentation, please do not hold back!
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ciAddressing warnings
318c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~~~~
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ciThe documentation build currently spews out an unbelievable number of
348c2ecf20Sopenharmony_ciwarnings.  When you have that many, you might as well have none at all;
358c2ecf20Sopenharmony_cipeople ignore them, and they will never notice when their work adds new
368c2ecf20Sopenharmony_ciones.  For this reason, eliminating warnings is one of the highest-priority
378c2ecf20Sopenharmony_citasks on the documentation TODO list.  The task itself is reasonably
388c2ecf20Sopenharmony_cistraightforward, but it must be approached in the right way to be
398c2ecf20Sopenharmony_cisuccessful.
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ciWarnings issued by a compiler for C code can often be dismissed as false
428c2ecf20Sopenharmony_cipositives, leading to patches aimed at simply shutting the compiler up.
438c2ecf20Sopenharmony_ciWarnings from the documentation build almost always point at a real
448c2ecf20Sopenharmony_ciproblem; making those warnings go away requires understanding the problem
458c2ecf20Sopenharmony_ciand fixing it at its source.  For this reason, patches fixing documentation
468c2ecf20Sopenharmony_ciwarnings should probably not say "fix a warning" in the changelog title;
478c2ecf20Sopenharmony_cithey should indicate the real problem that has been fixed.
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ciAnother important point is that documentation warnings are often created by
508c2ecf20Sopenharmony_ciproblems in kerneldoc comments in C code.  While the documentation
518c2ecf20Sopenharmony_cimaintainer appreciates being copied on fixes for these warnings, the
528c2ecf20Sopenharmony_cidocumentation tree is often not the right one to actually carry those
538c2ecf20Sopenharmony_cifixes; they should go to the maintainer of the subsystem in question.
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ciFor example, in a documentation build I grabbed a pair of warnings nearly
568c2ecf20Sopenharmony_ciat random::
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci  ./drivers/devfreq/devfreq.c:1818: warning: bad line:
598c2ecf20Sopenharmony_ci  	- Resource-managed devfreq_register_notifier()
608c2ecf20Sopenharmony_ci  ./drivers/devfreq/devfreq.c:1854: warning: bad line:
618c2ecf20Sopenharmony_ci	- Resource-managed devfreq_unregister_notifier()
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci(The lines were split for readability).
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ciA quick look at the source file named above turned up a couple of kerneldoc
668c2ecf20Sopenharmony_cicomments that look like this::
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci  /**
698c2ecf20Sopenharmony_ci   * devm_devfreq_register_notifier()
708c2ecf20Sopenharmony_ci	  - Resource-managed devfreq_register_notifier()
718c2ecf20Sopenharmony_ci   * @dev:	The devfreq user device. (parent of devfreq)
728c2ecf20Sopenharmony_ci   * @devfreq:	The devfreq object.
738c2ecf20Sopenharmony_ci   * @nb:		The notifier block to be unregistered.
748c2ecf20Sopenharmony_ci   * @list:	DEVFREQ_TRANSITION_NOTIFIER.
758c2ecf20Sopenharmony_ci   */
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ciThe problem is the missing "*", which confuses the build system's
788c2ecf20Sopenharmony_cisimplistic idea of what C comment blocks look like.  This problem had been
798c2ecf20Sopenharmony_cipresent since that comment was added in 2016 — a full four years.  Fixing
808c2ecf20Sopenharmony_ciit was a matter of adding the missing asterisks.  A quick look at the
818c2ecf20Sopenharmony_cihistory for that file showed what the normal format for subject lines is,
828c2ecf20Sopenharmony_ciand ``scripts/get_maintainer.pl`` told me who should receive it.  The
838c2ecf20Sopenharmony_ciresulting patch looked like this::
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci  [PATCH] PM / devfreq: Fix two malformed kerneldoc comments
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci  Two kerneldoc comments in devfreq.c fail to adhere to the required format,
888c2ecf20Sopenharmony_ci  resulting in these doc-build warnings:
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci    ./drivers/devfreq/devfreq.c:1818: warning: bad line:
918c2ecf20Sopenharmony_ci  	  - Resource-managed devfreq_register_notifier()
928c2ecf20Sopenharmony_ci    ./drivers/devfreq/devfreq.c:1854: warning: bad line:
938c2ecf20Sopenharmony_ci	  - Resource-managed devfreq_unregister_notifier()
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci  Add a couple of missing asterisks and make kerneldoc a little happier.
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci  Signed-off-by: Jonathan Corbet <corbet@lwn.net>
988c2ecf20Sopenharmony_ci  ---
998c2ecf20Sopenharmony_ci   drivers/devfreq/devfreq.c | 4 ++--
1008c2ecf20Sopenharmony_ci   1 file changed, 2 insertions(+), 2 deletions(-)
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ci  diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
1038c2ecf20Sopenharmony_ci  index 57f6944d65a6..00c9b80b3d33 100644
1048c2ecf20Sopenharmony_ci  --- a/drivers/devfreq/devfreq.c
1058c2ecf20Sopenharmony_ci  +++ b/drivers/devfreq/devfreq.c
1068c2ecf20Sopenharmony_ci  @@ -1814,7 +1814,7 @@ static void devm_devfreq_notifier_release(struct device *dev, void *res)
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci   /**
1098c2ecf20Sopenharmony_ci    * devm_devfreq_register_notifier()
1108c2ecf20Sopenharmony_ci  -	- Resource-managed devfreq_register_notifier()
1118c2ecf20Sopenharmony_ci  + *	- Resource-managed devfreq_register_notifier()
1128c2ecf20Sopenharmony_ci    * @dev:	The devfreq user device. (parent of devfreq)
1138c2ecf20Sopenharmony_ci    * @devfreq:	The devfreq object.
1148c2ecf20Sopenharmony_ci    * @nb:		The notifier block to be unregistered.
1158c2ecf20Sopenharmony_ci  @@ -1850,7 +1850,7 @@ EXPORT_SYMBOL(devm_devfreq_register_notifier);
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci   /**
1188c2ecf20Sopenharmony_ci    * devm_devfreq_unregister_notifier()
1198c2ecf20Sopenharmony_ci  -	- Resource-managed devfreq_unregister_notifier()
1208c2ecf20Sopenharmony_ci  + *	- Resource-managed devfreq_unregister_notifier()
1218c2ecf20Sopenharmony_ci    * @dev:	The devfreq user device. (parent of devfreq)
1228c2ecf20Sopenharmony_ci    * @devfreq:	The devfreq object.
1238c2ecf20Sopenharmony_ci    * @nb:		The notifier block to be unregistered.
1248c2ecf20Sopenharmony_ci  --
1258c2ecf20Sopenharmony_ci  2.24.1
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ciThe entire process only took a few minutes.  Of course, I then found that
1288c2ecf20Sopenharmony_cisomebody else had fixed it in a separate tree, highlighting another lesson:
1298c2ecf20Sopenharmony_cialways check linux-next to see if a problem has been fixed before you dig
1308c2ecf20Sopenharmony_ciinto it.
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ciOther fixes will take longer, especially those relating to structure
1338c2ecf20Sopenharmony_cimembers or function parameters that lack documentation.  In such cases, it
1348c2ecf20Sopenharmony_ciis necessary to work out what the role of those members or parameters is
1358c2ecf20Sopenharmony_ciand describe them correctly.  Overall, this task gets a little tedious at
1368c2ecf20Sopenharmony_citimes, but it's highly important.  If we can actually eliminate warnings
1378c2ecf20Sopenharmony_cifrom the documentation build, then we can start expecting developers to
1388c2ecf20Sopenharmony_ciavoid adding new ones.
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_ciLanguishing kerneldoc comments
1418c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_ciDevelopers are encouraged to write kerneldoc comments for their code, but
1448c2ecf20Sopenharmony_cimany of those comments are never pulled into the docs build.  That makes
1458c2ecf20Sopenharmony_cithis information harder to find and, for example, makes Sphinx unable to
1468c2ecf20Sopenharmony_cigenerate links to that documentation.  Adding ``kernel-doc`` directives to
1478c2ecf20Sopenharmony_cithe documentation to bring those comments in can help the community derive
1488c2ecf20Sopenharmony_cithe full value of the work that has gone into creating them.
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ciThe ``scripts/find-unused-docs.sh`` tool can be used to find these
1518c2ecf20Sopenharmony_cioverlooked comments.
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_ciNote that the most value comes from pulling in the documentation for
1548c2ecf20Sopenharmony_ciexported functions and data structures.  Many subsystems also have
1558c2ecf20Sopenharmony_cikerneldoc comments for internal use; those should not be pulled into the
1568c2ecf20Sopenharmony_cidocumentation build unless they are placed in a document that is
1578c2ecf20Sopenharmony_cispecifically aimed at developers working within the relevant subsystem.
1588c2ecf20Sopenharmony_ci
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ciTypo fixes
1618c2ecf20Sopenharmony_ci~~~~~~~~~~
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_ciFixing typographical or formatting errors in the documentation is a quick
1648c2ecf20Sopenharmony_ciway to figure out how to create and send patches, and it is a useful
1658c2ecf20Sopenharmony_ciservice.  I am always willing to accept such patches.  That said, once you
1668c2ecf20Sopenharmony_cihave fixed a few, please consider moving on to more advanced tasks, leaving
1678c2ecf20Sopenharmony_cisome typos for the next beginner to address.
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_ciPlease note that some things are *not* typos and should not be "fixed":
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_ci - Both American and British English spellings are allowed within the
1728c2ecf20Sopenharmony_ci   kernel documentation.  There is no need to fix one by replacing it with
1738c2ecf20Sopenharmony_ci   the other.
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_ci - The question of whether a period should be followed by one or two spaces
1768c2ecf20Sopenharmony_ci   is not to be debated in the context of kernel documentation.  Other
1778c2ecf20Sopenharmony_ci   areas of rational disagreement, such as the "Oxford comma", are also
1788c2ecf20Sopenharmony_ci   off-topic here.
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_ciAs with any patch to any project, please consider whether your change is
1818c2ecf20Sopenharmony_cireally making things better.
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_ciAncient documentation
1848c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~
1858c2ecf20Sopenharmony_ci
1868c2ecf20Sopenharmony_ciSome kernel documentation is current, maintained, and useful.  Some
1878c2ecf20Sopenharmony_cidocumentation is ... not.  Dusty, old, and inaccurate documentation can
1888c2ecf20Sopenharmony_cimislead readers and casts doubt on our documentation as a whole.  Anything
1898c2ecf20Sopenharmony_cithat can be done to address such problems is more than welcome.
1908c2ecf20Sopenharmony_ci
1918c2ecf20Sopenharmony_ciWhenever you are working with a document, please consider whether it is
1928c2ecf20Sopenharmony_cicurrent, whether it needs updating, or whether it should perhaps be removed
1938c2ecf20Sopenharmony_cialtogether.  There are a number of warning signs that you can pay attention
1948c2ecf20Sopenharmony_cito here:
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_ci - References to 2.x kernels
1978c2ecf20Sopenharmony_ci - Pointers to SourceForge repositories
1988c2ecf20Sopenharmony_ci - Nothing but typo fixes in the history for several years
1998c2ecf20Sopenharmony_ci - Discussion of pre-Git workflows
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_ciThe best thing to do, of course, would be to bring the documentation
2028c2ecf20Sopenharmony_cicurrent, adding whatever information is needed.  Such work often requires
2038c2ecf20Sopenharmony_cithe cooperation of developers familiar with the subsystem in question, of
2048c2ecf20Sopenharmony_cicourse.  Developers are often more than willing to cooperate with people
2058c2ecf20Sopenharmony_ciworking to improve the documentation when asked nicely, and when their
2068c2ecf20Sopenharmony_cianswers are listened to and acted upon.
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_ciSome documentation is beyond hope; we occasionally find documents that
2098c2ecf20Sopenharmony_cirefer to code that was removed from the kernel long ago, for example.
2108c2ecf20Sopenharmony_ciThere is surprising resistance to removing obsolete documentation, but we
2118c2ecf20Sopenharmony_cishould do that anyway.  Extra cruft in our documentation helps nobody.
2128c2ecf20Sopenharmony_ci
2138c2ecf20Sopenharmony_ciIn cases where there is perhaps some useful information in a badly outdated
2148c2ecf20Sopenharmony_cidocument, and you are unable to update it, the best thing to do may be to
2158c2ecf20Sopenharmony_ciadd a warning at the beginning.  The following text is recommended::
2168c2ecf20Sopenharmony_ci
2178c2ecf20Sopenharmony_ci  .. warning ::
2188c2ecf20Sopenharmony_ci  	This document is outdated and in need of attention.  Please use
2198c2ecf20Sopenharmony_ci	this information with caution, and please consider sending patches
2208c2ecf20Sopenharmony_ci	to update it.
2218c2ecf20Sopenharmony_ci
2228c2ecf20Sopenharmony_ciThat way, at least our long-suffering readers have been warned that the
2238c2ecf20Sopenharmony_cidocument may lead them astray.
2248c2ecf20Sopenharmony_ci
2258c2ecf20Sopenharmony_ciDocumentation coherency
2268c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~~
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_ciThe old-timers around here will remember the Linux books that showed up on
2298c2ecf20Sopenharmony_cithe shelves in the 1990s.  They were simply collections of documentation
2308c2ecf20Sopenharmony_cifiles scrounged from various locations on the net.  The books have (mostly)
2318c2ecf20Sopenharmony_ciimproved since then, but the kernel's documentation is still mostly built
2328c2ecf20Sopenharmony_cion that model.  It is thousands of files, almost each of which was written
2338c2ecf20Sopenharmony_ciin isolation from all of the others.  We don't have a coherent body of
2348c2ecf20Sopenharmony_cikernel documentation; we have thousands of individual documents.
2358c2ecf20Sopenharmony_ci
2368c2ecf20Sopenharmony_ciWe have been trying to improve the situation through the creation of
2378c2ecf20Sopenharmony_cia set of "books" that group documentation for specific readers.  These
2388c2ecf20Sopenharmony_ciinclude:
2398c2ecf20Sopenharmony_ci
2408c2ecf20Sopenharmony_ci - :doc:`../admin-guide/index`
2418c2ecf20Sopenharmony_ci - :doc:`../core-api/index`
2428c2ecf20Sopenharmony_ci - :doc:`../driver-api/index`
2438c2ecf20Sopenharmony_ci - :doc:`../userspace-api/index`
2448c2ecf20Sopenharmony_ci
2458c2ecf20Sopenharmony_ciAs well as this book on documentation itself.
2468c2ecf20Sopenharmony_ci
2478c2ecf20Sopenharmony_ciMoving documents into the appropriate books is an important task and needs
2488c2ecf20Sopenharmony_cito continue.  There are a couple of challenges associated with this work,
2498c2ecf20Sopenharmony_cithough.  Moving documentation files creates short-term pain for the people
2508c2ecf20Sopenharmony_ciwho work with those files; they are understandably unenthusiastic about
2518c2ecf20Sopenharmony_cisuch changes.  Usually the case can be made to move a document once; we
2528c2ecf20Sopenharmony_cireally don't want to keep shifting them around, though.
2538c2ecf20Sopenharmony_ci
2548c2ecf20Sopenharmony_ciEven when all documents are in the right place, though, we have only
2558c2ecf20Sopenharmony_cimanaged to turn a big pile into a group of smaller piles.  The work of
2568c2ecf20Sopenharmony_citrying to knit all of those documents together into a single whole has not
2578c2ecf20Sopenharmony_ciyet begun.  If you have bright ideas on how we could proceed on that front,
2588c2ecf20Sopenharmony_ciwe would be more than happy to hear them.
2598c2ecf20Sopenharmony_ci
2608c2ecf20Sopenharmony_ciStylesheet improvements
2618c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~~
2628c2ecf20Sopenharmony_ci
2638c2ecf20Sopenharmony_ciWith the adoption of Sphinx we have much nicer-looking HTML output than we
2648c2ecf20Sopenharmony_cionce did.  But it could still use a lot of improvement; Donald Knuth and
2658c2ecf20Sopenharmony_ciEdward Tufte would be unimpressed.  That requires tweaking our stylesheets
2668c2ecf20Sopenharmony_cito create more typographically sound, accessible, and readable output.
2678c2ecf20Sopenharmony_ci
2688c2ecf20Sopenharmony_ciBe warned: if you take on this task you are heading into classic bikeshed
2698c2ecf20Sopenharmony_citerritory.  Expect a lot of opinions and discussion for even relatively
2708c2ecf20Sopenharmony_ciobvious changes.  That is, alas, the nature of the world we live in.
2718c2ecf20Sopenharmony_ci
2728c2ecf20Sopenharmony_ciNon-LaTeX PDF build
2738c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~~~~
2748c2ecf20Sopenharmony_ci
2758c2ecf20Sopenharmony_ciThis is a decidedly nontrivial task for somebody with a lot of time and
2768c2ecf20Sopenharmony_ciPython skills.  The Sphinx toolchain is relatively small and well
2778c2ecf20Sopenharmony_cicontained; it is easy to add to a development system.  But building PDF or
2788c2ecf20Sopenharmony_ciEPUB output requires installing LaTeX, which is anything but small or well
2798c2ecf20Sopenharmony_cicontained.  That would be a nice thing to eliminate.
2808c2ecf20Sopenharmony_ci
2818c2ecf20Sopenharmony_ciThe original hope had been to use the rst2pdf tool (https://rst2pdf.org/)
2828c2ecf20Sopenharmony_cifor PDF generation, but it turned out to not be up to the task.
2838c2ecf20Sopenharmony_ciDevelopment work on rst2pdf seems to have picked up again in recent times,
2848c2ecf20Sopenharmony_cithough, which is a hopeful sign.  If a suitably motivated developer were to
2858c2ecf20Sopenharmony_ciwork with that project to make rst2pdf work with the kernel documentation
2868c2ecf20Sopenharmony_cibuild, the world would be eternally grateful.
2878c2ecf20Sopenharmony_ci
2888c2ecf20Sopenharmony_ciWrite more documentation
2898c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~~~
2908c2ecf20Sopenharmony_ci
2918c2ecf20Sopenharmony_ciNaturally, there are massive parts of the kernel that are severely
2928c2ecf20Sopenharmony_ciunderdocumented.  If you have the knowledge to document a specific kernel
2938c2ecf20Sopenharmony_cisubsystem and the desire to do so, please do not hesitate to do some
2948c2ecf20Sopenharmony_ciwriting and contribute the result to the kernel.  Untold numbers of kernel
2958c2ecf20Sopenharmony_cidevelopers and users will thank you.
296