xref: /OK3568_Linux_fs/kernel/Documentation/doc-guide/contributing.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun.. SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun
3*4882a593SmuzhiyunHow to help improve kernel documentation
4*4882a593Smuzhiyun========================================
5*4882a593Smuzhiyun
6*4882a593SmuzhiyunDocumentation is an important part of any software-development project.
7*4882a593SmuzhiyunGood documentation helps to bring new developers in and helps established
8*4882a593Smuzhiyundevelopers work more effectively.  Without top-quality documentation, a lot
9*4882a593Smuzhiyunof time is wasted in reverse-engineering the code and making avoidable
10*4882a593Smuzhiyunmistakes.
11*4882a593Smuzhiyun
12*4882a593SmuzhiyunUnfortunately, the kernel's documentation currently falls far short of what
13*4882a593Smuzhiyunit needs to be to support a project of this size and importance.
14*4882a593Smuzhiyun
15*4882a593SmuzhiyunThis guide is for contributors who would like to improve that situation.
16*4882a593SmuzhiyunKernel documentation improvements can be made by developers at a variety of
17*4882a593Smuzhiyunskill levels; they are a relatively easy way to learn the kernel process in
18*4882a593Smuzhiyungeneral and find a place in the community.  The bulk of what follows is the
19*4882a593Smuzhiyundocumentation maintainer's list of tasks that most urgently need to be
20*4882a593Smuzhiyundone.
21*4882a593Smuzhiyun
22*4882a593SmuzhiyunThe documentation TODO list
23*4882a593Smuzhiyun---------------------------
24*4882a593Smuzhiyun
25*4882a593SmuzhiyunThere is an endless list of tasks that need to be carried out to get our
26*4882a593Smuzhiyundocumentation to where it should be.  This list contains a number of
27*4882a593Smuzhiyunimportant items, but is far from exhaustive; if you see a different way to
28*4882a593Smuzhiyunimprove the documentation, please do not hold back!
29*4882a593Smuzhiyun
30*4882a593SmuzhiyunAddressing warnings
31*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~
32*4882a593Smuzhiyun
33*4882a593SmuzhiyunThe documentation build currently spews out an unbelievable number of
34*4882a593Smuzhiyunwarnings.  When you have that many, you might as well have none at all;
35*4882a593Smuzhiyunpeople ignore them, and they will never notice when their work adds new
36*4882a593Smuzhiyunones.  For this reason, eliminating warnings is one of the highest-priority
37*4882a593Smuzhiyuntasks on the documentation TODO list.  The task itself is reasonably
38*4882a593Smuzhiyunstraightforward, but it must be approached in the right way to be
39*4882a593Smuzhiyunsuccessful.
40*4882a593Smuzhiyun
41*4882a593SmuzhiyunWarnings issued by a compiler for C code can often be dismissed as false
42*4882a593Smuzhiyunpositives, leading to patches aimed at simply shutting the compiler up.
43*4882a593SmuzhiyunWarnings from the documentation build almost always point at a real
44*4882a593Smuzhiyunproblem; making those warnings go away requires understanding the problem
45*4882a593Smuzhiyunand fixing it at its source.  For this reason, patches fixing documentation
46*4882a593Smuzhiyunwarnings should probably not say "fix a warning" in the changelog title;
47*4882a593Smuzhiyunthey should indicate the real problem that has been fixed.
48*4882a593Smuzhiyun
49*4882a593SmuzhiyunAnother important point is that documentation warnings are often created by
50*4882a593Smuzhiyunproblems in kerneldoc comments in C code.  While the documentation
51*4882a593Smuzhiyunmaintainer appreciates being copied on fixes for these warnings, the
52*4882a593Smuzhiyundocumentation tree is often not the right one to actually carry those
53*4882a593Smuzhiyunfixes; they should go to the maintainer of the subsystem in question.
54*4882a593Smuzhiyun
55*4882a593SmuzhiyunFor example, in a documentation build I grabbed a pair of warnings nearly
56*4882a593Smuzhiyunat random::
57*4882a593Smuzhiyun
58*4882a593Smuzhiyun  ./drivers/devfreq/devfreq.c:1818: warning: bad line:
59*4882a593Smuzhiyun  	- Resource-managed devfreq_register_notifier()
60*4882a593Smuzhiyun  ./drivers/devfreq/devfreq.c:1854: warning: bad line:
61*4882a593Smuzhiyun	- Resource-managed devfreq_unregister_notifier()
62*4882a593Smuzhiyun
63*4882a593Smuzhiyun(The lines were split for readability).
64*4882a593Smuzhiyun
65*4882a593SmuzhiyunA quick look at the source file named above turned up a couple of kerneldoc
66*4882a593Smuzhiyuncomments that look like this::
67*4882a593Smuzhiyun
68*4882a593Smuzhiyun  /**
69*4882a593Smuzhiyun   * devm_devfreq_register_notifier()
70*4882a593Smuzhiyun	  - Resource-managed devfreq_register_notifier()
71*4882a593Smuzhiyun   * @dev:	The devfreq user device. (parent of devfreq)
72*4882a593Smuzhiyun   * @devfreq:	The devfreq object.
73*4882a593Smuzhiyun   * @nb:		The notifier block to be unregistered.
74*4882a593Smuzhiyun   * @list:	DEVFREQ_TRANSITION_NOTIFIER.
75*4882a593Smuzhiyun   */
76*4882a593Smuzhiyun
77*4882a593SmuzhiyunThe problem is the missing "*", which confuses the build system's
78*4882a593Smuzhiyunsimplistic idea of what C comment blocks look like.  This problem had been
79*4882a593Smuzhiyunpresent since that comment was added in 2016 — a full four years.  Fixing
80*4882a593Smuzhiyunit was a matter of adding the missing asterisks.  A quick look at the
81*4882a593Smuzhiyunhistory for that file showed what the normal format for subject lines is,
82*4882a593Smuzhiyunand ``scripts/get_maintainer.pl`` told me who should receive it.  The
83*4882a593Smuzhiyunresulting patch looked like this::
84*4882a593Smuzhiyun
85*4882a593Smuzhiyun  [PATCH] PM / devfreq: Fix two malformed kerneldoc comments
86*4882a593Smuzhiyun
87*4882a593Smuzhiyun  Two kerneldoc comments in devfreq.c fail to adhere to the required format,
88*4882a593Smuzhiyun  resulting in these doc-build warnings:
89*4882a593Smuzhiyun
90*4882a593Smuzhiyun    ./drivers/devfreq/devfreq.c:1818: warning: bad line:
91*4882a593Smuzhiyun  	  - Resource-managed devfreq_register_notifier()
92*4882a593Smuzhiyun    ./drivers/devfreq/devfreq.c:1854: warning: bad line:
93*4882a593Smuzhiyun	  - Resource-managed devfreq_unregister_notifier()
94*4882a593Smuzhiyun
95*4882a593Smuzhiyun  Add a couple of missing asterisks and make kerneldoc a little happier.
96*4882a593Smuzhiyun
97*4882a593Smuzhiyun  Signed-off-by: Jonathan Corbet <corbet@lwn.net>
98*4882a593Smuzhiyun  ---
99*4882a593Smuzhiyun   drivers/devfreq/devfreq.c | 4 ++--
100*4882a593Smuzhiyun   1 file changed, 2 insertions(+), 2 deletions(-)
101*4882a593Smuzhiyun
102*4882a593Smuzhiyun  diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
103*4882a593Smuzhiyun  index 57f6944d65a6..00c9b80b3d33 100644
104*4882a593Smuzhiyun  --- a/drivers/devfreq/devfreq.c
105*4882a593Smuzhiyun  +++ b/drivers/devfreq/devfreq.c
106*4882a593Smuzhiyun  @@ -1814,7 +1814,7 @@ static void devm_devfreq_notifier_release(struct device *dev, void *res)
107*4882a593Smuzhiyun
108*4882a593Smuzhiyun   /**
109*4882a593Smuzhiyun    * devm_devfreq_register_notifier()
110*4882a593Smuzhiyun  -	- Resource-managed devfreq_register_notifier()
111*4882a593Smuzhiyun  + *	- Resource-managed devfreq_register_notifier()
112*4882a593Smuzhiyun    * @dev:	The devfreq user device. (parent of devfreq)
113*4882a593Smuzhiyun    * @devfreq:	The devfreq object.
114*4882a593Smuzhiyun    * @nb:		The notifier block to be unregistered.
115*4882a593Smuzhiyun  @@ -1850,7 +1850,7 @@ EXPORT_SYMBOL(devm_devfreq_register_notifier);
116*4882a593Smuzhiyun
117*4882a593Smuzhiyun   /**
118*4882a593Smuzhiyun    * devm_devfreq_unregister_notifier()
119*4882a593Smuzhiyun  -	- Resource-managed devfreq_unregister_notifier()
120*4882a593Smuzhiyun  + *	- Resource-managed devfreq_unregister_notifier()
121*4882a593Smuzhiyun    * @dev:	The devfreq user device. (parent of devfreq)
122*4882a593Smuzhiyun    * @devfreq:	The devfreq object.
123*4882a593Smuzhiyun    * @nb:		The notifier block to be unregistered.
124*4882a593Smuzhiyun  --
125*4882a593Smuzhiyun  2.24.1
126*4882a593Smuzhiyun
127*4882a593SmuzhiyunThe entire process only took a few minutes.  Of course, I then found that
128*4882a593Smuzhiyunsomebody else had fixed it in a separate tree, highlighting another lesson:
129*4882a593Smuzhiyunalways check linux-next to see if a problem has been fixed before you dig
130*4882a593Smuzhiyuninto it.
131*4882a593Smuzhiyun
132*4882a593SmuzhiyunOther fixes will take longer, especially those relating to structure
133*4882a593Smuzhiyunmembers or function parameters that lack documentation.  In such cases, it
134*4882a593Smuzhiyunis necessary to work out what the role of those members or parameters is
135*4882a593Smuzhiyunand describe them correctly.  Overall, this task gets a little tedious at
136*4882a593Smuzhiyuntimes, but it's highly important.  If we can actually eliminate warnings
137*4882a593Smuzhiyunfrom the documentation build, then we can start expecting developers to
138*4882a593Smuzhiyunavoid adding new ones.
139*4882a593Smuzhiyun
140*4882a593SmuzhiyunLanguishing kerneldoc comments
141*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
142*4882a593Smuzhiyun
143*4882a593SmuzhiyunDevelopers are encouraged to write kerneldoc comments for their code, but
144*4882a593Smuzhiyunmany of those comments are never pulled into the docs build.  That makes
145*4882a593Smuzhiyunthis information harder to find and, for example, makes Sphinx unable to
146*4882a593Smuzhiyungenerate links to that documentation.  Adding ``kernel-doc`` directives to
147*4882a593Smuzhiyunthe documentation to bring those comments in can help the community derive
148*4882a593Smuzhiyunthe full value of the work that has gone into creating them.
149*4882a593Smuzhiyun
150*4882a593SmuzhiyunThe ``scripts/find-unused-docs.sh`` tool can be used to find these
151*4882a593Smuzhiyunoverlooked comments.
152*4882a593Smuzhiyun
153*4882a593SmuzhiyunNote that the most value comes from pulling in the documentation for
154*4882a593Smuzhiyunexported functions and data structures.  Many subsystems also have
155*4882a593Smuzhiyunkerneldoc comments for internal use; those should not be pulled into the
156*4882a593Smuzhiyundocumentation build unless they are placed in a document that is
157*4882a593Smuzhiyunspecifically aimed at developers working within the relevant subsystem.
158*4882a593Smuzhiyun
159*4882a593Smuzhiyun
160*4882a593SmuzhiyunTypo fixes
161*4882a593Smuzhiyun~~~~~~~~~~
162*4882a593Smuzhiyun
163*4882a593SmuzhiyunFixing typographical or formatting errors in the documentation is a quick
164*4882a593Smuzhiyunway to figure out how to create and send patches, and it is a useful
165*4882a593Smuzhiyunservice.  I am always willing to accept such patches.  That said, once you
166*4882a593Smuzhiyunhave fixed a few, please consider moving on to more advanced tasks, leaving
167*4882a593Smuzhiyunsome typos for the next beginner to address.
168*4882a593Smuzhiyun
169*4882a593SmuzhiyunPlease note that some things are *not* typos and should not be "fixed":
170*4882a593Smuzhiyun
171*4882a593Smuzhiyun - Both American and British English spellings are allowed within the
172*4882a593Smuzhiyun   kernel documentation.  There is no need to fix one by replacing it with
173*4882a593Smuzhiyun   the other.
174*4882a593Smuzhiyun
175*4882a593Smuzhiyun - The question of whether a period should be followed by one or two spaces
176*4882a593Smuzhiyun   is not to be debated in the context of kernel documentation.  Other
177*4882a593Smuzhiyun   areas of rational disagreement, such as the "Oxford comma", are also
178*4882a593Smuzhiyun   off-topic here.
179*4882a593Smuzhiyun
180*4882a593SmuzhiyunAs with any patch to any project, please consider whether your change is
181*4882a593Smuzhiyunreally making things better.
182*4882a593Smuzhiyun
183*4882a593SmuzhiyunAncient documentation
184*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~
185*4882a593Smuzhiyun
186*4882a593SmuzhiyunSome kernel documentation is current, maintained, and useful.  Some
187*4882a593Smuzhiyundocumentation is ... not.  Dusty, old, and inaccurate documentation can
188*4882a593Smuzhiyunmislead readers and casts doubt on our documentation as a whole.  Anything
189*4882a593Smuzhiyunthat can be done to address such problems is more than welcome.
190*4882a593Smuzhiyun
191*4882a593SmuzhiyunWhenever you are working with a document, please consider whether it is
192*4882a593Smuzhiyuncurrent, whether it needs updating, or whether it should perhaps be removed
193*4882a593Smuzhiyunaltogether.  There are a number of warning signs that you can pay attention
194*4882a593Smuzhiyunto here:
195*4882a593Smuzhiyun
196*4882a593Smuzhiyun - References to 2.x kernels
197*4882a593Smuzhiyun - Pointers to SourceForge repositories
198*4882a593Smuzhiyun - Nothing but typo fixes in the history for several years
199*4882a593Smuzhiyun - Discussion of pre-Git workflows
200*4882a593Smuzhiyun
201*4882a593SmuzhiyunThe best thing to do, of course, would be to bring the documentation
202*4882a593Smuzhiyuncurrent, adding whatever information is needed.  Such work often requires
203*4882a593Smuzhiyunthe cooperation of developers familiar with the subsystem in question, of
204*4882a593Smuzhiyuncourse.  Developers are often more than willing to cooperate with people
205*4882a593Smuzhiyunworking to improve the documentation when asked nicely, and when their
206*4882a593Smuzhiyunanswers are listened to and acted upon.
207*4882a593Smuzhiyun
208*4882a593SmuzhiyunSome documentation is beyond hope; we occasionally find documents that
209*4882a593Smuzhiyunrefer to code that was removed from the kernel long ago, for example.
210*4882a593SmuzhiyunThere is surprising resistance to removing obsolete documentation, but we
211*4882a593Smuzhiyunshould do that anyway.  Extra cruft in our documentation helps nobody.
212*4882a593Smuzhiyun
213*4882a593SmuzhiyunIn cases where there is perhaps some useful information in a badly outdated
214*4882a593Smuzhiyundocument, and you are unable to update it, the best thing to do may be to
215*4882a593Smuzhiyunadd a warning at the beginning.  The following text is recommended::
216*4882a593Smuzhiyun
217*4882a593Smuzhiyun  .. warning ::
218*4882a593Smuzhiyun  	This document is outdated and in need of attention.  Please use
219*4882a593Smuzhiyun	this information with caution, and please consider sending patches
220*4882a593Smuzhiyun	to update it.
221*4882a593Smuzhiyun
222*4882a593SmuzhiyunThat way, at least our long-suffering readers have been warned that the
223*4882a593Smuzhiyundocument may lead them astray.
224*4882a593Smuzhiyun
225*4882a593SmuzhiyunDocumentation coherency
226*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~
227*4882a593Smuzhiyun
228*4882a593SmuzhiyunThe old-timers around here will remember the Linux books that showed up on
229*4882a593Smuzhiyunthe shelves in the 1990s.  They were simply collections of documentation
230*4882a593Smuzhiyunfiles scrounged from various locations on the net.  The books have (mostly)
231*4882a593Smuzhiyunimproved since then, but the kernel's documentation is still mostly built
232*4882a593Smuzhiyunon that model.  It is thousands of files, almost each of which was written
233*4882a593Smuzhiyunin isolation from all of the others.  We don't have a coherent body of
234*4882a593Smuzhiyunkernel documentation; we have thousands of individual documents.
235*4882a593Smuzhiyun
236*4882a593SmuzhiyunWe have been trying to improve the situation through the creation of
237*4882a593Smuzhiyuna set of "books" that group documentation for specific readers.  These
238*4882a593Smuzhiyuninclude:
239*4882a593Smuzhiyun
240*4882a593Smuzhiyun - :doc:`../admin-guide/index`
241*4882a593Smuzhiyun - :doc:`../core-api/index`
242*4882a593Smuzhiyun - :doc:`../driver-api/index`
243*4882a593Smuzhiyun - :doc:`../userspace-api/index`
244*4882a593Smuzhiyun
245*4882a593SmuzhiyunAs well as this book on documentation itself.
246*4882a593Smuzhiyun
247*4882a593SmuzhiyunMoving documents into the appropriate books is an important task and needs
248*4882a593Smuzhiyunto continue.  There are a couple of challenges associated with this work,
249*4882a593Smuzhiyunthough.  Moving documentation files creates short-term pain for the people
250*4882a593Smuzhiyunwho work with those files; they are understandably unenthusiastic about
251*4882a593Smuzhiyunsuch changes.  Usually the case can be made to move a document once; we
252*4882a593Smuzhiyunreally don't want to keep shifting them around, though.
253*4882a593Smuzhiyun
254*4882a593SmuzhiyunEven when all documents are in the right place, though, we have only
255*4882a593Smuzhiyunmanaged to turn a big pile into a group of smaller piles.  The work of
256*4882a593Smuzhiyuntrying to knit all of those documents together into a single whole has not
257*4882a593Smuzhiyunyet begun.  If you have bright ideas on how we could proceed on that front,
258*4882a593Smuzhiyunwe would be more than happy to hear them.
259*4882a593Smuzhiyun
260*4882a593SmuzhiyunStylesheet improvements
261*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~
262*4882a593Smuzhiyun
263*4882a593SmuzhiyunWith the adoption of Sphinx we have much nicer-looking HTML output than we
264*4882a593Smuzhiyunonce did.  But it could still use a lot of improvement; Donald Knuth and
265*4882a593SmuzhiyunEdward Tufte would be unimpressed.  That requires tweaking our stylesheets
266*4882a593Smuzhiyunto create more typographically sound, accessible, and readable output.
267*4882a593Smuzhiyun
268*4882a593SmuzhiyunBe warned: if you take on this task you are heading into classic bikeshed
269*4882a593Smuzhiyunterritory.  Expect a lot of opinions and discussion for even relatively
270*4882a593Smuzhiyunobvious changes.  That is, alas, the nature of the world we live in.
271*4882a593Smuzhiyun
272*4882a593SmuzhiyunNon-LaTeX PDF build
273*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~
274*4882a593Smuzhiyun
275*4882a593SmuzhiyunThis is a decidedly nontrivial task for somebody with a lot of time and
276*4882a593SmuzhiyunPython skills.  The Sphinx toolchain is relatively small and well
277*4882a593Smuzhiyuncontained; it is easy to add to a development system.  But building PDF or
278*4882a593SmuzhiyunEPUB output requires installing LaTeX, which is anything but small or well
279*4882a593Smuzhiyuncontained.  That would be a nice thing to eliminate.
280*4882a593Smuzhiyun
281*4882a593SmuzhiyunThe original hope had been to use the rst2pdf tool (https://rst2pdf.org/)
282*4882a593Smuzhiyunfor PDF generation, but it turned out to not be up to the task.
283*4882a593SmuzhiyunDevelopment work on rst2pdf seems to have picked up again in recent times,
284*4882a593Smuzhiyunthough, which is a hopeful sign.  If a suitably motivated developer were to
285*4882a593Smuzhiyunwork with that project to make rst2pdf work with the kernel documentation
286*4882a593Smuzhiyunbuild, the world would be eternally grateful.
287*4882a593Smuzhiyun
288*4882a593SmuzhiyunWrite more documentation
289*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~
290*4882a593Smuzhiyun
291*4882a593SmuzhiyunNaturally, there are massive parts of the kernel that are severely
292*4882a593Smuzhiyununderdocumented.  If you have the knowledge to document a specific kernel
293*4882a593Smuzhiyunsubsystem and the desire to do so, please do not hesitate to do some
294*4882a593Smuzhiyunwriting and contribute the result to the kernel.  Untold numbers of kernel
295*4882a593Smuzhiyundevelopers and users will thank you.
296