aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/CodingStyle
diff options
context:
space:
mode:
authorJonathan Herman <hermanjl@cs.unc.edu>2013-01-17 16:15:55 -0500
committerJonathan Herman <hermanjl@cs.unc.edu>2013-01-17 16:15:55 -0500
commit8dea78da5cee153b8af9c07a2745f6c55057fe12 (patch)
treea8f4d49d63b1ecc92f2fddceba0655b2472c5bd9 /Documentation/CodingStyle
parent406089d01562f1e2bf9f089fd7637009ebaad589 (diff)
Patched in Tegra support.
Diffstat (limited to 'Documentation/CodingStyle')
-rw-r--r--Documentation/CodingStyle59
1 files changed, 4 insertions, 55 deletions
diff --git a/Documentation/CodingStyle b/Documentation/CodingStyle
index 495e5ba1634..c940239d967 100644
--- a/Documentation/CodingStyle
+++ b/Documentation/CodingStyle
@@ -166,8 +166,8 @@ if (condition)
166else 166else
167 do_that(); 167 do_that();
168 168
169This does not apply if only one branch of a conditional statement is a single 169This does not apply if one branch of a conditional statement is a single
170statement; in the latter case use braces in both branches: 170statement. Use braces in both branches.
171 171
172if (condition) { 172if (condition) {
173 do_this(); 173 do_this();
@@ -454,16 +454,6 @@ The preferred style for long (multi-line) comments is:
454 * with beginning and ending almost-blank lines. 454 * with beginning and ending almost-blank lines.
455 */ 455 */
456 456
457For files in net/ and drivers/net/ the preferred style for long (multi-line)
458comments is a little different.
459
460 /* The preferred comment style for files in net/ and drivers/net
461 * looks like this.
462 *
463 * It is nearly the same as the generally preferred comment style,
464 * but there is no initial almost-blank line.
465 */
466
467It's also important to comment data, whether they are basic types or derived 457It's also important to comment data, whether they are basic types or derived
468types. To this end, use just one data declaration per line (no commas for 458types. To this end, use just one data declaration per line (no commas for
469multiple data declarations). This leaves you room for a small comment on each 459multiple data declarations). This leaves you room for a small comment on each
@@ -681,9 +671,8 @@ ones already enabled by DEBUG.
681 Chapter 14: Allocating memory 671 Chapter 14: Allocating memory
682 672
683The kernel provides the following general purpose memory allocators: 673The kernel provides the following general purpose memory allocators:
684kmalloc(), kzalloc(), kmalloc_array(), kcalloc(), vmalloc(), and 674kmalloc(), kzalloc(), kcalloc(), vmalloc(), and vzalloc(). Please refer to
685vzalloc(). Please refer to the API documentation for further information 675the API documentation for further information about them.
686about them.
687 676
688The preferred form for passing a size of a struct is the following: 677The preferred form for passing a size of a struct is the following:
689 678
@@ -697,17 +686,6 @@ Casting the return value which is a void pointer is redundant. The conversion
697from void pointer to any other pointer type is guaranteed by the C programming 686from void pointer to any other pointer type is guaranteed by the C programming
698language. 687language.
699 688
700The preferred form for allocating an array is the following:
701
702 p = kmalloc_array(n, sizeof(...), ...);
703
704The preferred form for allocating a zeroed array is the following:
705
706 p = kcalloc(n, sizeof(...), ...);
707
708Both forms check for overflow on the allocation size n * sizeof(...),
709and return NULL if that occurred.
710
711 689
712 Chapter 15: The inline disease 690 Chapter 15: The inline disease
713 691
@@ -815,35 +793,6 @@ own custom mode, or may have some other magic method for making indentation
815work correctly. 793work correctly.
816 794
817 795
818 Chapter 19: Inline assembly
819
820In architecture-specific code, you may need to use inline assembly to interface
821with CPU or platform functionality. Don't hesitate to do so when necessary.
822However, don't use inline assembly gratuitously when C can do the job. You can
823and should poke hardware from C when possible.
824
825Consider writing simple helper functions that wrap common bits of inline
826assembly, rather than repeatedly writing them with slight variations. Remember
827that inline assembly can use C parameters.
828
829Large, non-trivial assembly functions should go in .S files, with corresponding
830C prototypes defined in C header files. The C prototypes for assembly
831functions should use "asmlinkage".
832
833You may need to mark your asm statement as volatile, to prevent GCC from
834removing it if GCC doesn't notice any side effects. You don't always need to
835do so, though, and doing so unnecessarily can limit optimization.
836
837When writing a single inline assembly statement containing multiple
838instructions, put each instruction on a separate line in a separate quoted
839string, and end each string except the last with \n\t to properly indent the
840next instruction in the assembly output:
841
842 asm ("magic %reg1, #42\n\t"
843 "more_magic %reg2, %reg3"
844 : /* outputs */ : /* inputs */ : /* clobbers */);
845
846
847 796
848 Appendix I: References 797 Appendix I: References
849 798