diff options
| author | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-01-17 16:15:55 -0500 |
|---|---|---|
| committer | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-01-17 16:15:55 -0500 |
| commit | 8dea78da5cee153b8af9c07a2745f6c55057fe12 (patch) | |
| tree | a8f4d49d63b1ecc92f2fddceba0655b2472c5bd9 /Documentation/CodingStyle | |
| parent | 406089d01562f1e2bf9f089fd7637009ebaad589 (diff) | |
Patched in Tegra support.
Diffstat (limited to 'Documentation/CodingStyle')
| -rw-r--r-- | Documentation/CodingStyle | 59 |
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) | |||
| 166 | else | 166 | else |
| 167 | do_that(); | 167 | do_that(); |
| 168 | 168 | ||
| 169 | This does not apply if only one branch of a conditional statement is a single | 169 | This does not apply if one branch of a conditional statement is a single |
| 170 | statement; in the latter case use braces in both branches: | 170 | statement. Use braces in both branches. |
| 171 | 171 | ||
| 172 | if (condition) { | 172 | if (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 | ||
| 457 | For files in net/ and drivers/net/ the preferred style for long (multi-line) | ||
| 458 | comments 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 | |||
| 467 | It's also important to comment data, whether they are basic types or derived | 457 | It's also important to comment data, whether they are basic types or derived |
| 468 | types. To this end, use just one data declaration per line (no commas for | 458 | types. To this end, use just one data declaration per line (no commas for |
| 469 | multiple data declarations). This leaves you room for a small comment on each | 459 | multiple 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 | ||
| 683 | The kernel provides the following general purpose memory allocators: | 673 | The kernel provides the following general purpose memory allocators: |
| 684 | kmalloc(), kzalloc(), kmalloc_array(), kcalloc(), vmalloc(), and | 674 | kmalloc(), kzalloc(), kcalloc(), vmalloc(), and vzalloc(). Please refer to |
| 685 | vzalloc(). Please refer to the API documentation for further information | 675 | the API documentation for further information about them. |
| 686 | about them. | ||
| 687 | 676 | ||
| 688 | The preferred form for passing a size of a struct is the following: | 677 | The 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 | |||
| 697 | from void pointer to any other pointer type is guaranteed by the C programming | 686 | from void pointer to any other pointer type is guaranteed by the C programming |
| 698 | language. | 687 | language. |
| 699 | 688 | ||
| 700 | The preferred form for allocating an array is the following: | ||
| 701 | |||
| 702 | p = kmalloc_array(n, sizeof(...), ...); | ||
| 703 | |||
| 704 | The preferred form for allocating a zeroed array is the following: | ||
| 705 | |||
| 706 | p = kcalloc(n, sizeof(...), ...); | ||
| 707 | |||
| 708 | Both forms check for overflow on the allocation size n * sizeof(...), | ||
| 709 | and 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 | |||
| 815 | work correctly. | 793 | work correctly. |
| 816 | 794 | ||
| 817 | 795 | ||
| 818 | Chapter 19: Inline assembly | ||
| 819 | |||
| 820 | In architecture-specific code, you may need to use inline assembly to interface | ||
| 821 | with CPU or platform functionality. Don't hesitate to do so when necessary. | ||
| 822 | However, don't use inline assembly gratuitously when C can do the job. You can | ||
| 823 | and should poke hardware from C when possible. | ||
| 824 | |||
| 825 | Consider writing simple helper functions that wrap common bits of inline | ||
| 826 | assembly, rather than repeatedly writing them with slight variations. Remember | ||
| 827 | that inline assembly can use C parameters. | ||
| 828 | |||
| 829 | Large, non-trivial assembly functions should go in .S files, with corresponding | ||
| 830 | C prototypes defined in C header files. The C prototypes for assembly | ||
| 831 | functions should use "asmlinkage". | ||
| 832 | |||
| 833 | You may need to mark your asm statement as volatile, to prevent GCC from | ||
| 834 | removing it if GCC doesn't notice any side effects. You don't always need to | ||
| 835 | do so, though, and doing so unnecessarily can limit optimization. | ||
| 836 | |||
| 837 | When writing a single inline assembly statement containing multiple | ||
| 838 | instructions, put each instruction on a separate line in a separate quoted | ||
| 839 | string, and end each string except the last with \n\t to properly indent the | ||
| 840 | next 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 | ||
