aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/SubmittingPatches
diff options
context:
space:
mode:
authorJonathan Corbet <corbet@lwn.net>2014-12-23 10:38:24 -0500
committerJonathan Corbet <corbet@lwn.net>2014-12-23 10:38:24 -0500
commit6de16eba62b3b4d01b2b232ea7724d5450a19e30 (patch)
tree33782c7902de447cbd1b4f3a1abf47b322bfb2cc /Documentation/SubmittingPatches
parent97bf6af1f928216fd6c5a66e8a57bfa95a659672 (diff)
Docs: Remove "tips and tricks" from SubmittingPatches
This section was just a weird collection of stuff that is better found elsewhere. The "coding style" section somewhat duplicated the previous coding style section; the useful information there has been collected into a single place. Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Diffstat (limited to 'Documentation/SubmittingPatches')
-rw-r--r--Documentation/SubmittingPatches117
1 files changed, 21 insertions, 96 deletions
diff --git a/Documentation/SubmittingPatches b/Documentation/SubmittingPatches
index 1fa1caa198eb..8f416a2b409f 100644
--- a/Documentation/SubmittingPatches
+++ b/Documentation/SubmittingPatches
@@ -193,17 +193,33 @@ then only post say 15 or so at a time and wait for review and integration.
193 193
194 194
195 195
1964) Style check your changes. 1964) Style-check your changes.
197----------------------------
197 198
198Check your patch for basic style violations, details of which can be 199Check your patch for basic style violations, details of which can be
199found in Documentation/CodingStyle. Failure to do so simply wastes 200found in Documentation/CodingStyle. Failure to do so simply wastes
200the reviewers time and will get your patch rejected, probably 201the reviewers time and will get your patch rejected, probably
201without even being read. 202without even being read.
202 203
203At a minimum you should check your patches with the patch style 204One significant exception is when moving code from one file to
204checker prior to submission (scripts/checkpatch.pl). You should 205another -- in this case you should not modify the moved code at all in
205be able to justify all violations that remain in your patch. 206the same patch which moves it. This clearly delineates the act of
207moving the code and your changes. This greatly aids review of the
208actual differences and allows tools to better track the history of
209the code itself.
210
211Check your patches with the patch style checker prior to submission
212(scripts/checkpatch.pl). Note, though, that the style checker should be
213viewed as a guide, not as a replacement for human judgment. If your code
214looks better with a violation then its probably best left alone.
206 215
216The checker reports at three levels:
217 - ERROR: things that are very likely to be wrong
218 - WARNING: things requiring careful review
219 - CHECK: things requiring thought
220
221You should be able to justify all violations that remain in your
222patch.
207 223
208 224
2095) Select e-mail destination. 2255) Select e-mail destination.
@@ -684,100 +700,9 @@ new/deleted or renamed files.
684With rename detection, the statistics are rather different [...] 700With rename detection, the statistics are rather different [...]
685because git will notice that a fair number of the changes are renames. 701because git will notice that a fair number of the changes are renames.
686 702
687-----------------------------------
688SECTION 2 - HINTS, TIPS, AND TRICKS
689-----------------------------------
690
691This section lists many of the common "rules" associated with code
692submitted to the kernel. There are always exceptions... but you must
693have a really good reason for doing so. You could probably call this
694section Linus Computer Science 101.
695
696
697
6981) Read Documentation/CodingStyle
699
700Nuff said. If your code deviates too much from this, it is likely
701to be rejected without further review, and without comment.
702
703One significant exception is when moving code from one file to
704another -- in this case you should not modify the moved code at all in
705the same patch which moves it. This clearly delineates the act of
706moving the code and your changes. This greatly aids review of the
707actual differences and allows tools to better track the history of
708the code itself.
709
710Check your patches with the patch style checker prior to submission
711(scripts/checkpatch.pl). The style checker should be viewed as
712a guide not as the final word. If your code looks better with
713a violation then its probably best left alone.
714
715The checker reports at three levels:
716 - ERROR: things that are very likely to be wrong
717 - WARNING: things requiring careful review
718 - CHECK: things requiring thought
719
720You should be able to justify all violations that remain in your
721patch.
722
723
724
7252) #ifdefs are ugly
726
727Code cluttered with ifdefs is difficult to read and maintain. Don't do
728it. Instead, put your ifdefs in a header, and conditionally define
729'static inline' functions, or macros, which are used in the code.
730Let the compiler optimize away the "no-op" case.
731
732Simple example, of poor code:
733
734 dev = alloc_etherdev (sizeof(struct funky_private));
735 if (!dev)
736 return -ENODEV;
737 #ifdef CONFIG_NET_FUNKINESS
738 init_funky_net(dev);
739 #endif
740
741Cleaned-up example:
742
743(in header)
744 #ifndef CONFIG_NET_FUNKINESS
745 static inline void init_funky_net (struct net_device *d) {}
746 #endif
747
748(in the code itself)
749 dev = alloc_etherdev (sizeof(struct funky_private));
750 if (!dev)
751 return -ENODEV;
752 init_funky_net(dev);
753
754
755
7563) 'static inline' is better than a macro
757
758Static inline functions are greatly preferred over macros.
759They provide type safety, have no length limitations, no formatting
760limitations, and under gcc they are as cheap as macros.
761
762Macros should only be used for cases where a static inline is clearly
763suboptimal [there are a few, isolated cases of this in fast paths],
764or where it is impossible to use a static inline function [such as
765string-izing].
766
767'static inline' is preferred over 'static __inline__', 'extern inline',
768and 'extern __inline__'.
769
770
771
7724) Don't over-design.
773
774Don't try to anticipate nebulous future cases which may or may not
775be useful: "Make it as simple as you can, and no simpler."
776
777
778 703
779---------------------- 704----------------------
780SECTION 3 - REFERENCES 705SECTION 2 - REFERENCES
781---------------------- 706----------------------
782 707
783Andrew Morton, "The perfect patch" (tpp). 708Andrew Morton, "The perfect patch" (tpp).