xref: /OK3568_Linux_fs/kernel/Documentation/process/5.Posting.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun.. _development_posting:
2*4882a593Smuzhiyun
3*4882a593SmuzhiyunPosting patches
4*4882a593Smuzhiyun===============
5*4882a593Smuzhiyun
6*4882a593SmuzhiyunSooner or later, the time comes when your work is ready to be presented to
7*4882a593Smuzhiyunthe community for review and, eventually, inclusion into the mainline
8*4882a593Smuzhiyunkernel.  Unsurprisingly, the kernel development community has evolved a set
9*4882a593Smuzhiyunof conventions and procedures which are used in the posting of patches;
10*4882a593Smuzhiyunfollowing them will make life much easier for everybody involved.  This
11*4882a593Smuzhiyundocument will attempt to cover these expectations in reasonable detail;
12*4882a593Smuzhiyunmore information can also be found in the files
13*4882a593Smuzhiyun:ref:`Documentation/process/submitting-patches.rst <submittingpatches>`,
14*4882a593Smuzhiyun:ref:`Documentation/process/submitting-drivers.rst  <submittingdrivers>`
15*4882a593Smuzhiyunand :ref:`Documentation/process/submit-checklist.rst <submitchecklist>`.
16*4882a593Smuzhiyun
17*4882a593Smuzhiyun
18*4882a593SmuzhiyunWhen to post
19*4882a593Smuzhiyun------------
20*4882a593Smuzhiyun
21*4882a593SmuzhiyunThere is a constant temptation to avoid posting patches before they are
22*4882a593Smuzhiyuncompletely "ready."  For simple patches, that is not a problem.  If the
23*4882a593Smuzhiyunwork being done is complex, though, there is a lot to be gained by getting
24*4882a593Smuzhiyunfeedback from the community before the work is complete.  So you should
25*4882a593Smuzhiyunconsider posting in-progress work, or even making a git tree available so
26*4882a593Smuzhiyunthat interested developers can catch up with your work at any time.
27*4882a593Smuzhiyun
28*4882a593SmuzhiyunWhen posting code which is not yet considered ready for inclusion, it is a
29*4882a593Smuzhiyungood idea to say so in the posting itself.  Also mention any major work
30*4882a593Smuzhiyunwhich remains to be done and any known problems.  Fewer people will look at
31*4882a593Smuzhiyunpatches which are known to be half-baked, but those who do will come in
32*4882a593Smuzhiyunwith the idea that they can help you drive the work in the right direction.
33*4882a593Smuzhiyun
34*4882a593Smuzhiyun
35*4882a593SmuzhiyunBefore creating patches
36*4882a593Smuzhiyun-----------------------
37*4882a593Smuzhiyun
38*4882a593SmuzhiyunThere are a number of things which should be done before you consider
39*4882a593Smuzhiyunsending patches to the development community.  These include:
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun - Test the code to the extent that you can.  Make use of the kernel's
42*4882a593Smuzhiyun   debugging tools, ensure that the kernel will build with all reasonable
43*4882a593Smuzhiyun   combinations of configuration options, use cross-compilers to build for
44*4882a593Smuzhiyun   different architectures, etc.
45*4882a593Smuzhiyun
46*4882a593Smuzhiyun - Make sure your code is compliant with the kernel coding style
47*4882a593Smuzhiyun   guidelines.
48*4882a593Smuzhiyun
49*4882a593Smuzhiyun - Does your change have performance implications?  If so, you should run
50*4882a593Smuzhiyun   benchmarks showing what the impact (or benefit) of your change is; a
51*4882a593Smuzhiyun   summary of the results should be included with the patch.
52*4882a593Smuzhiyun
53*4882a593Smuzhiyun - Be sure that you have the right to post the code.  If this work was done
54*4882a593Smuzhiyun   for an employer, the employer likely has a right to the work and must be
55*4882a593Smuzhiyun   agreeable with its release under the GPL.
56*4882a593Smuzhiyun
57*4882a593SmuzhiyunAs a general rule, putting in some extra thought before posting code almost
58*4882a593Smuzhiyunalways pays back the effort in short order.
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun
61*4882a593SmuzhiyunPatch preparation
62*4882a593Smuzhiyun-----------------
63*4882a593Smuzhiyun
64*4882a593SmuzhiyunThe preparation of patches for posting can be a surprising amount of work,
65*4882a593Smuzhiyunbut, once again, attempting to save time here is not generally advisable
66*4882a593Smuzhiyuneven in the short term.
67*4882a593Smuzhiyun
68*4882a593SmuzhiyunPatches must be prepared against a specific version of the kernel.  As a
69*4882a593Smuzhiyungeneral rule, a patch should be based on the current mainline as found in
70*4882a593SmuzhiyunLinus's git tree.  When basing on mainline, start with a well-known release
71*4882a593Smuzhiyunpoint - a stable or -rc release - rather than branching off the mainline at
72*4882a593Smuzhiyunan arbitrary spot.
73*4882a593Smuzhiyun
74*4882a593SmuzhiyunIt may become necessary to make versions against -mm, linux-next, or a
75*4882a593Smuzhiyunsubsystem tree, though, to facilitate wider testing and review.  Depending
76*4882a593Smuzhiyunon the area of your patch and what is going on elsewhere, basing a patch
77*4882a593Smuzhiyunagainst these other trees can require a significant amount of work
78*4882a593Smuzhiyunresolving conflicts and dealing with API changes.
79*4882a593Smuzhiyun
80*4882a593SmuzhiyunOnly the most simple changes should be formatted as a single patch;
81*4882a593Smuzhiyuneverything else should be made as a logical series of changes.  Splitting
82*4882a593Smuzhiyunup patches is a bit of an art; some developers spend a long time figuring
83*4882a593Smuzhiyunout how to do it in the way that the community expects.  There are a few
84*4882a593Smuzhiyunrules of thumb, however, which can help considerably:
85*4882a593Smuzhiyun
86*4882a593Smuzhiyun - The patch series you post will almost certainly not be the series of
87*4882a593Smuzhiyun   changes found in your working revision control system.  Instead, the
88*4882a593Smuzhiyun   changes you have made need to be considered in their final form, then
89*4882a593Smuzhiyun   split apart in ways which make sense.  The developers are interested in
90*4882a593Smuzhiyun   discrete, self-contained changes, not the path you took to get to those
91*4882a593Smuzhiyun   changes.
92*4882a593Smuzhiyun
93*4882a593Smuzhiyun - Each logically independent change should be formatted as a separate
94*4882a593Smuzhiyun   patch.  These changes can be small ("add a field to this structure") or
95*4882a593Smuzhiyun   large (adding a significant new driver, for example), but they should be
96*4882a593Smuzhiyun   conceptually small and amenable to a one-line description.  Each patch
97*4882a593Smuzhiyun   should make a specific change which can be reviewed on its own and
98*4882a593Smuzhiyun   verified to do what it says it does.
99*4882a593Smuzhiyun
100*4882a593Smuzhiyun - As a way of restating the guideline above: do not mix different types of
101*4882a593Smuzhiyun   changes in the same patch.  If a single patch fixes a critical security
102*4882a593Smuzhiyun   bug, rearranges a few structures, and reformats the code, there is a
103*4882a593Smuzhiyun   good chance that it will be passed over and the important fix will be
104*4882a593Smuzhiyun   lost.
105*4882a593Smuzhiyun
106*4882a593Smuzhiyun - Each patch should yield a kernel which builds and runs properly; if your
107*4882a593Smuzhiyun   patch series is interrupted in the middle, the result should still be a
108*4882a593Smuzhiyun   working kernel.  Partial application of a patch series is a common
109*4882a593Smuzhiyun   scenario when the "git bisect" tool is used to find regressions; if the
110*4882a593Smuzhiyun   result is a broken kernel, you will make life harder for developers and
111*4882a593Smuzhiyun   users who are engaging in the noble work of tracking down problems.
112*4882a593Smuzhiyun
113*4882a593Smuzhiyun - Do not overdo it, though.  One developer once posted a set of edits
114*4882a593Smuzhiyun   to a single file as 500 separate patches - an act which did not make him
115*4882a593Smuzhiyun   the most popular person on the kernel mailing list.  A single patch can
116*4882a593Smuzhiyun   be reasonably large as long as it still contains a single *logical*
117*4882a593Smuzhiyun   change.
118*4882a593Smuzhiyun
119*4882a593Smuzhiyun - It can be tempting to add a whole new infrastructure with a series of
120*4882a593Smuzhiyun   patches, but to leave that infrastructure unused until the final patch
121*4882a593Smuzhiyun   in the series enables the whole thing.  This temptation should be
122*4882a593Smuzhiyun   avoided if possible; if that series adds regressions, bisection will
123*4882a593Smuzhiyun   finger the last patch as the one which caused the problem, even though
124*4882a593Smuzhiyun   the real bug is elsewhere.  Whenever possible, a patch which adds new
125*4882a593Smuzhiyun   code should make that code active immediately.
126*4882a593Smuzhiyun
127*4882a593SmuzhiyunWorking to create the perfect patch series can be a frustrating process
128*4882a593Smuzhiyunwhich takes quite a bit of time and thought after the "real work" has been
129*4882a593Smuzhiyundone.  When done properly, though, it is time well spent.
130*4882a593Smuzhiyun
131*4882a593Smuzhiyun
132*4882a593SmuzhiyunPatch formatting and changelogs
133*4882a593Smuzhiyun-------------------------------
134*4882a593Smuzhiyun
135*4882a593SmuzhiyunSo now you have a perfect series of patches for posting, but the work is
136*4882a593Smuzhiyunnot done quite yet.  Each patch needs to be formatted into a message which
137*4882a593Smuzhiyunquickly and clearly communicates its purpose to the rest of the world.  To
138*4882a593Smuzhiyunthat end, each patch will be composed of the following:
139*4882a593Smuzhiyun
140*4882a593Smuzhiyun - An optional "From" line naming the author of the patch.  This line is
141*4882a593Smuzhiyun   only necessary if you are passing on somebody else's patch via email,
142*4882a593Smuzhiyun   but it never hurts to add it when in doubt.
143*4882a593Smuzhiyun
144*4882a593Smuzhiyun - A one-line description of what the patch does.  This message should be
145*4882a593Smuzhiyun   enough for a reader who sees it with no other context to figure out the
146*4882a593Smuzhiyun   scope of the patch; it is the line that will show up in the "short form"
147*4882a593Smuzhiyun   changelogs.  This message is usually formatted with the relevant
148*4882a593Smuzhiyun   subsystem name first, followed by the purpose of the patch.  For
149*4882a593Smuzhiyun   example:
150*4882a593Smuzhiyun
151*4882a593Smuzhiyun   ::
152*4882a593Smuzhiyun
153*4882a593Smuzhiyun	gpio: fix build on CONFIG_GPIO_SYSFS=n
154*4882a593Smuzhiyun
155*4882a593Smuzhiyun - A blank line followed by a detailed description of the contents of the
156*4882a593Smuzhiyun   patch.  This description can be as long as is required; it should say
157*4882a593Smuzhiyun   what the patch does and why it should be applied to the kernel.
158*4882a593Smuzhiyun
159*4882a593Smuzhiyun - One or more tag lines, with, at a minimum, one Signed-off-by: line from
160*4882a593Smuzhiyun   the author of the patch.  Tags will be described in more detail below.
161*4882a593Smuzhiyun
162*4882a593SmuzhiyunThe items above, together, form the changelog for the patch.  Writing good
163*4882a593Smuzhiyunchangelogs is a crucial but often-neglected art; it's worth spending
164*4882a593Smuzhiyunanother moment discussing this issue.  When writing a changelog, you should
165*4882a593Smuzhiyunbear in mind that a number of different people will be reading your words.
166*4882a593SmuzhiyunThese include subsystem maintainers and reviewers who need to decide
167*4882a593Smuzhiyunwhether the patch should be included, distributors and other maintainers
168*4882a593Smuzhiyuntrying to decide whether a patch should be backported to other kernels, bug
169*4882a593Smuzhiyunhunters wondering whether the patch is responsible for a problem they are
170*4882a593Smuzhiyunchasing, users who want to know how the kernel has changed, and more.  A
171*4882a593Smuzhiyungood changelog conveys the needed information to all of these people in the
172*4882a593Smuzhiyunmost direct and concise way possible.
173*4882a593Smuzhiyun
174*4882a593SmuzhiyunTo that end, the summary line should describe the effects of and motivation
175*4882a593Smuzhiyunfor the change as well as possible given the one-line constraint.  The
176*4882a593Smuzhiyundetailed description can then amplify on those topics and provide any
177*4882a593Smuzhiyunneeded additional information.  If the patch fixes a bug, cite the commit
178*4882a593Smuzhiyunwhich introduced the bug if possible (and please provide both the commit ID
179*4882a593Smuzhiyunand the title when citing commits).  If a problem is associated with
180*4882a593Smuzhiyunspecific log or compiler output, include that output to help others
181*4882a593Smuzhiyunsearching for a solution to the same problem.  If the change is meant to
182*4882a593Smuzhiyunsupport other changes coming in later patch, say so.  If internal APIs are
183*4882a593Smuzhiyunchanged, detail those changes and how other developers should respond.  In
184*4882a593Smuzhiyungeneral, the more you can put yourself into the shoes of everybody who will
185*4882a593Smuzhiyunbe reading your changelog, the better that changelog (and the kernel as a
186*4882a593Smuzhiyunwhole) will be.
187*4882a593Smuzhiyun
188*4882a593SmuzhiyunNeedless to say, the changelog should be the text used when committing the
189*4882a593Smuzhiyunchange to a revision control system.  It will be followed by:
190*4882a593Smuzhiyun
191*4882a593Smuzhiyun - The patch itself, in the unified ("-u") patch format.  Using the "-p"
192*4882a593Smuzhiyun   option to diff will associate function names with changes, making the
193*4882a593Smuzhiyun   resulting patch easier for others to read.
194*4882a593Smuzhiyun
195*4882a593SmuzhiyunYou should avoid including changes to irrelevant files (those generated by
196*4882a593Smuzhiyunthe build process, for example, or editor backup files) in the patch.  The
197*4882a593Smuzhiyunfile "dontdiff" in the Documentation directory can help in this regard;
198*4882a593Smuzhiyunpass it to diff with the "-X" option.
199*4882a593Smuzhiyun
200*4882a593SmuzhiyunThe tags mentioned above are used to describe how various developers have
201*4882a593Smuzhiyunbeen associated with the development of this patch.  They are described in
202*4882a593Smuzhiyundetail in
203*4882a593Smuzhiyunthe :ref:`Documentation/process/submitting-patches.rst <submittingpatches>`
204*4882a593Smuzhiyundocument; what follows here is a brief summary.  Each of these lines has
205*4882a593Smuzhiyunthe format:
206*4882a593Smuzhiyun
207*4882a593Smuzhiyun::
208*4882a593Smuzhiyun
209*4882a593Smuzhiyun	tag: Full Name <email address>  optional-other-stuff
210*4882a593Smuzhiyun
211*4882a593SmuzhiyunThe tags in common use are:
212*4882a593Smuzhiyun
213*4882a593Smuzhiyun - Signed-off-by: this is a developer's certification that he or she has
214*4882a593Smuzhiyun   the right to submit the patch for inclusion into the kernel.  It is an
215*4882a593Smuzhiyun   agreement to the Developer's Certificate of Origin, the full text of
216*4882a593Smuzhiyun   which can be found in :ref:`Documentation/process/submitting-patches.rst <submittingpatches>`
217*4882a593Smuzhiyun   Code without a proper signoff cannot be merged into the mainline.
218*4882a593Smuzhiyun
219*4882a593Smuzhiyun - Co-developed-by: states that the patch was co-created by several developers;
220*4882a593Smuzhiyun   it is a used to give attribution to co-authors (in addition to the author
221*4882a593Smuzhiyun   attributed by the From: tag) when multiple people work on a single patch.
222*4882a593Smuzhiyun   Every Co-developed-by: must be immediately followed by a Signed-off-by: of
223*4882a593Smuzhiyun   the associated co-author.  Details and examples can be found in
224*4882a593Smuzhiyun   :ref:`Documentation/process/submitting-patches.rst <submittingpatches>`.
225*4882a593Smuzhiyun
226*4882a593Smuzhiyun - Acked-by: indicates an agreement by another developer (often a
227*4882a593Smuzhiyun   maintainer of the relevant code) that the patch is appropriate for
228*4882a593Smuzhiyun   inclusion into the kernel.
229*4882a593Smuzhiyun
230*4882a593Smuzhiyun - Tested-by: states that the named person has tested the patch and found
231*4882a593Smuzhiyun   it to work.
232*4882a593Smuzhiyun
233*4882a593Smuzhiyun - Reviewed-by: the named developer has reviewed the patch for correctness;
234*4882a593Smuzhiyun   see the reviewer's statement in :ref:`Documentation/process/submitting-patches.rst <submittingpatches>`
235*4882a593Smuzhiyun   for more detail.
236*4882a593Smuzhiyun
237*4882a593Smuzhiyun - Reported-by: names a user who reported a problem which is fixed by this
238*4882a593Smuzhiyun   patch; this tag is used to give credit to the (often underappreciated)
239*4882a593Smuzhiyun   people who test our code and let us know when things do not work
240*4882a593Smuzhiyun   correctly.
241*4882a593Smuzhiyun
242*4882a593Smuzhiyun - Cc: the named person received a copy of the patch and had the
243*4882a593Smuzhiyun   opportunity to comment on it.
244*4882a593Smuzhiyun
245*4882a593SmuzhiyunBe careful in the addition of tags to your patches: only Cc: is appropriate
246*4882a593Smuzhiyunfor addition without the explicit permission of the person named.
247*4882a593Smuzhiyun
248*4882a593Smuzhiyun
249*4882a593SmuzhiyunSending the patch
250*4882a593Smuzhiyun-----------------
251*4882a593Smuzhiyun
252*4882a593SmuzhiyunBefore you mail your patches, there are a couple of other things you should
253*4882a593Smuzhiyuntake care of:
254*4882a593Smuzhiyun
255*4882a593Smuzhiyun - Are you sure that your mailer will not corrupt the patches?  Patches
256*4882a593Smuzhiyun   which have had gratuitous white-space changes or line wrapping performed
257*4882a593Smuzhiyun   by the mail client will not apply at the other end, and often will not
258*4882a593Smuzhiyun   be examined in any detail.  If there is any doubt at all, mail the patch
259*4882a593Smuzhiyun   to yourself and convince yourself that it shows up intact.
260*4882a593Smuzhiyun
261*4882a593Smuzhiyun   :ref:`Documentation/process/email-clients.rst <email_clients>` has some
262*4882a593Smuzhiyun   helpful hints on making specific mail clients work for sending patches.
263*4882a593Smuzhiyun
264*4882a593Smuzhiyun - Are you sure your patch is free of silly mistakes?  You should always
265*4882a593Smuzhiyun   run patches through scripts/checkpatch.pl and address the complaints it
266*4882a593Smuzhiyun   comes up with.  Please bear in mind that checkpatch.pl, while being the
267*4882a593Smuzhiyun   embodiment of a fair amount of thought about what kernel patches should
268*4882a593Smuzhiyun   look like, is not smarter than you.  If fixing a checkpatch.pl complaint
269*4882a593Smuzhiyun   would make the code worse, don't do it.
270*4882a593Smuzhiyun
271*4882a593SmuzhiyunPatches should always be sent as plain text.  Please do not send them as
272*4882a593Smuzhiyunattachments; that makes it much harder for reviewers to quote sections of
273*4882a593Smuzhiyunthe patch in their replies.  Instead, just put the patch directly into your
274*4882a593Smuzhiyunmessage.
275*4882a593Smuzhiyun
276*4882a593SmuzhiyunWhen mailing patches, it is important to send copies to anybody who might
277*4882a593Smuzhiyunbe interested in it.  Unlike some other projects, the kernel encourages
278*4882a593Smuzhiyunpeople to err on the side of sending too many copies; don't assume that the
279*4882a593Smuzhiyunrelevant people will see your posting on the mailing lists.  In particular,
280*4882a593Smuzhiyuncopies should go to:
281*4882a593Smuzhiyun
282*4882a593Smuzhiyun - The maintainer(s) of the affected subsystem(s).  As described earlier,
283*4882a593Smuzhiyun   the MAINTAINERS file is the first place to look for these people.
284*4882a593Smuzhiyun
285*4882a593Smuzhiyun - Other developers who have been working in the same area - especially
286*4882a593Smuzhiyun   those who might be working there now.  Using git to see who else has
287*4882a593Smuzhiyun   modified the files you are working on can be helpful.
288*4882a593Smuzhiyun
289*4882a593Smuzhiyun - If you are responding to a bug report or a feature request, copy the
290*4882a593Smuzhiyun   original poster as well.
291*4882a593Smuzhiyun
292*4882a593Smuzhiyun - Send a copy to the relevant mailing list, or, if nothing else applies,
293*4882a593Smuzhiyun   the linux-kernel list.
294*4882a593Smuzhiyun
295*4882a593Smuzhiyun - If you are fixing a bug, think about whether the fix should go into the
296*4882a593Smuzhiyun   next stable update.  If so, stable@vger.kernel.org should get a copy of
297*4882a593Smuzhiyun   the patch.  Also add a "Cc: stable@vger.kernel.org" to the tags within
298*4882a593Smuzhiyun   the patch itself; that will cause the stable team to get a notification
299*4882a593Smuzhiyun   when your fix goes into the mainline.
300*4882a593Smuzhiyun
301*4882a593SmuzhiyunWhen selecting recipients for a patch, it is good to have an idea of who
302*4882a593Smuzhiyunyou think will eventually accept the patch and get it merged.  While it
303*4882a593Smuzhiyunis possible to send patches directly to Linus Torvalds and have him merge
304*4882a593Smuzhiyunthem, things are not normally done that way.  Linus is busy, and there are
305*4882a593Smuzhiyunsubsystem maintainers who watch over specific parts of the kernel.  Usually
306*4882a593Smuzhiyunyou will be wanting that maintainer to merge your patches.  If there is no
307*4882a593Smuzhiyunobvious maintainer, Andrew Morton is often the patch target of last resort.
308*4882a593Smuzhiyun
309*4882a593SmuzhiyunPatches need good subject lines.  The canonical format for a patch line is
310*4882a593Smuzhiyunsomething like:
311*4882a593Smuzhiyun
312*4882a593Smuzhiyun::
313*4882a593Smuzhiyun
314*4882a593Smuzhiyun	[PATCH nn/mm] subsys: one-line description of the patch
315*4882a593Smuzhiyun
316*4882a593Smuzhiyunwhere "nn" is the ordinal number of the patch, "mm" is the total number of
317*4882a593Smuzhiyunpatches in the series, and "subsys" is the name of the affected subsystem.
318*4882a593SmuzhiyunClearly, nn/mm can be omitted for a single, standalone patch.
319*4882a593Smuzhiyun
320*4882a593SmuzhiyunIf you have a significant series of patches, it is customary to send an
321*4882a593Smuzhiyunintroductory description as part zero.  This convention is not universally
322*4882a593Smuzhiyunfollowed though; if you use it, remember that information in the
323*4882a593Smuzhiyunintroduction does not make it into the kernel changelogs.  So please ensure
324*4882a593Smuzhiyunthat the patches, themselves, have complete changelog information.
325*4882a593Smuzhiyun
326*4882a593SmuzhiyunIn general, the second and following parts of a multi-part patch should be
327*4882a593Smuzhiyunsent as a reply to the first part so that they all thread together at the
328*4882a593Smuzhiyunreceiving end.  Tools like git and quilt have commands to mail out a set of
329*4882a593Smuzhiyunpatches with the proper threading.  If you have a long series, though, and
330*4882a593Smuzhiyunare using git, please stay away from the --chain-reply-to option to avoid
331*4882a593Smuzhiyuncreating exceptionally deep nesting.
332