162306a36Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0-only 262306a36Sopenharmony_ci 362306a36Sopenharmony_ci========== 462306a36Sopenharmony_ciCheckpatch 562306a36Sopenharmony_ci========== 662306a36Sopenharmony_ci 762306a36Sopenharmony_ciCheckpatch (scripts/checkpatch.pl) is a perl script which checks for trivial 862306a36Sopenharmony_cistyle violations in patches and optionally corrects them. Checkpatch can 962306a36Sopenharmony_cialso be run on file contexts and without the kernel tree. 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ciCheckpatch is not always right. Your judgement takes precedence over checkpatch 1262306a36Sopenharmony_cimessages. If your code looks better with the violations, then its probably 1362306a36Sopenharmony_cibest left alone. 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ciOptions 1762306a36Sopenharmony_ci======= 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ciThis section will describe the options checkpatch can be run with. 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ciUsage:: 2262306a36Sopenharmony_ci 2362306a36Sopenharmony_ci ./scripts/checkpatch.pl [OPTION]... [FILE]... 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_ciAvailable options: 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ci - -q, --quiet 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_ci Enable quiet mode. 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ci - -v, --verbose 3262306a36Sopenharmony_ci Enable verbose mode. Additional verbose test descriptions are output 3362306a36Sopenharmony_ci so as to provide information on why that particular message is shown. 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ci - --no-tree 3662306a36Sopenharmony_ci 3762306a36Sopenharmony_ci Run checkpatch without the kernel tree. 3862306a36Sopenharmony_ci 3962306a36Sopenharmony_ci - --no-signoff 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ci Disable the 'Signed-off-by' line check. The sign-off is a simple line at 4262306a36Sopenharmony_ci the end of the explanation for the patch, which certifies that you wrote it 4362306a36Sopenharmony_ci or otherwise have the right to pass it on as an open-source patch. 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_ci Example:: 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_ci Signed-off-by: Random J Developer <random@developer.example.org> 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ci Setting this flag effectively stops a message for a missing signed-off-by 5062306a36Sopenharmony_ci line in a patch context. 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ci - --patch 5362306a36Sopenharmony_ci 5462306a36Sopenharmony_ci Treat FILE as a patch. This is the default option and need not be 5562306a36Sopenharmony_ci explicitly specified. 5662306a36Sopenharmony_ci 5762306a36Sopenharmony_ci - --emacs 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_ci Set output to emacs compile window format. This allows emacs users to jump 6062306a36Sopenharmony_ci from the error in the compile window directly to the offending line in the 6162306a36Sopenharmony_ci patch. 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ci - --terse 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_ci Output only one line per report. 6662306a36Sopenharmony_ci 6762306a36Sopenharmony_ci - --showfile 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_ci Show the diffed file position instead of the input file position. 7062306a36Sopenharmony_ci 7162306a36Sopenharmony_ci - -g, --git 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_ci Treat FILE as a single commit or a git revision range. 7462306a36Sopenharmony_ci 7562306a36Sopenharmony_ci Single commit with: 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_ci - <rev> 7862306a36Sopenharmony_ci - <rev>^ 7962306a36Sopenharmony_ci - <rev>~n 8062306a36Sopenharmony_ci 8162306a36Sopenharmony_ci Multiple commits with: 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_ci - <rev1>..<rev2> 8462306a36Sopenharmony_ci - <rev1>...<rev2> 8562306a36Sopenharmony_ci - <rev>-<count> 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_ci - -f, --file 8862306a36Sopenharmony_ci 8962306a36Sopenharmony_ci Treat FILE as a regular source file. This option must be used when running 9062306a36Sopenharmony_ci checkpatch on source files in the kernel. 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_ci - --subjective, --strict 9362306a36Sopenharmony_ci 9462306a36Sopenharmony_ci Enable stricter tests in checkpatch. By default the tests emitted as CHECK 9562306a36Sopenharmony_ci do not activate by default. Use this flag to activate the CHECK tests. 9662306a36Sopenharmony_ci 9762306a36Sopenharmony_ci - --list-types 9862306a36Sopenharmony_ci 9962306a36Sopenharmony_ci Every message emitted by checkpatch has an associated TYPE. Add this flag 10062306a36Sopenharmony_ci to display all the types in checkpatch. 10162306a36Sopenharmony_ci 10262306a36Sopenharmony_ci Note that when this flag is active, checkpatch does not read the input FILE, 10362306a36Sopenharmony_ci and no message is emitted. Only a list of types in checkpatch is output. 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_ci - --types TYPE(,TYPE2...) 10662306a36Sopenharmony_ci 10762306a36Sopenharmony_ci Only display messages with the given types. 10862306a36Sopenharmony_ci 10962306a36Sopenharmony_ci Example:: 11062306a36Sopenharmony_ci 11162306a36Sopenharmony_ci ./scripts/checkpatch.pl mypatch.patch --types EMAIL_SUBJECT,BRACES 11262306a36Sopenharmony_ci 11362306a36Sopenharmony_ci - --ignore TYPE(,TYPE2...) 11462306a36Sopenharmony_ci 11562306a36Sopenharmony_ci Checkpatch will not emit messages for the specified types. 11662306a36Sopenharmony_ci 11762306a36Sopenharmony_ci Example:: 11862306a36Sopenharmony_ci 11962306a36Sopenharmony_ci ./scripts/checkpatch.pl mypatch.patch --ignore EMAIL_SUBJECT,BRACES 12062306a36Sopenharmony_ci 12162306a36Sopenharmony_ci - --show-types 12262306a36Sopenharmony_ci 12362306a36Sopenharmony_ci By default checkpatch doesn't display the type associated with the messages. 12462306a36Sopenharmony_ci Set this flag to show the message type in the output. 12562306a36Sopenharmony_ci 12662306a36Sopenharmony_ci - --max-line-length=n 12762306a36Sopenharmony_ci 12862306a36Sopenharmony_ci Set the max line length (default 100). If a line exceeds the specified 12962306a36Sopenharmony_ci length, a LONG_LINE message is emitted. 13062306a36Sopenharmony_ci 13162306a36Sopenharmony_ci 13262306a36Sopenharmony_ci The message level is different for patch and file contexts. For patches, 13362306a36Sopenharmony_ci a WARNING is emitted. While a milder CHECK is emitted for files. So for 13462306a36Sopenharmony_ci file contexts, the --strict flag must also be enabled. 13562306a36Sopenharmony_ci 13662306a36Sopenharmony_ci - --min-conf-desc-length=n 13762306a36Sopenharmony_ci 13862306a36Sopenharmony_ci Set the Kconfig entry minimum description length, if shorter, warn. 13962306a36Sopenharmony_ci 14062306a36Sopenharmony_ci - --tab-size=n 14162306a36Sopenharmony_ci 14262306a36Sopenharmony_ci Set the number of spaces for tab (default 8). 14362306a36Sopenharmony_ci 14462306a36Sopenharmony_ci - --root=PATH 14562306a36Sopenharmony_ci 14662306a36Sopenharmony_ci PATH to the kernel tree root. 14762306a36Sopenharmony_ci 14862306a36Sopenharmony_ci This option must be specified when invoking checkpatch from outside 14962306a36Sopenharmony_ci the kernel root. 15062306a36Sopenharmony_ci 15162306a36Sopenharmony_ci - --no-summary 15262306a36Sopenharmony_ci 15362306a36Sopenharmony_ci Suppress the per file summary. 15462306a36Sopenharmony_ci 15562306a36Sopenharmony_ci - --mailback 15662306a36Sopenharmony_ci 15762306a36Sopenharmony_ci Only produce a report in case of Warnings or Errors. Milder Checks are 15862306a36Sopenharmony_ci excluded from this. 15962306a36Sopenharmony_ci 16062306a36Sopenharmony_ci - --summary-file 16162306a36Sopenharmony_ci 16262306a36Sopenharmony_ci Include the filename in summary. 16362306a36Sopenharmony_ci 16462306a36Sopenharmony_ci - --debug KEY=[0|1] 16562306a36Sopenharmony_ci 16662306a36Sopenharmony_ci Turn on/off debugging of KEY, where KEY is one of 'values', 'possible', 16762306a36Sopenharmony_ci 'type', and 'attr' (default is all off). 16862306a36Sopenharmony_ci 16962306a36Sopenharmony_ci - --fix 17062306a36Sopenharmony_ci 17162306a36Sopenharmony_ci This is an EXPERIMENTAL feature. If correctable errors exists, a file 17262306a36Sopenharmony_ci <inputfile>.EXPERIMENTAL-checkpatch-fixes is created which has the 17362306a36Sopenharmony_ci automatically fixable errors corrected. 17462306a36Sopenharmony_ci 17562306a36Sopenharmony_ci - --fix-inplace 17662306a36Sopenharmony_ci 17762306a36Sopenharmony_ci EXPERIMENTAL - Similar to --fix but input file is overwritten with fixes. 17862306a36Sopenharmony_ci 17962306a36Sopenharmony_ci DO NOT USE this flag unless you are absolutely sure and you have a backup 18062306a36Sopenharmony_ci in place. 18162306a36Sopenharmony_ci 18262306a36Sopenharmony_ci - --ignore-perl-version 18362306a36Sopenharmony_ci 18462306a36Sopenharmony_ci Override checking of perl version. Runtime errors maybe encountered after 18562306a36Sopenharmony_ci enabling this flag if the perl version does not meet the minimum specified. 18662306a36Sopenharmony_ci 18762306a36Sopenharmony_ci - --codespell 18862306a36Sopenharmony_ci 18962306a36Sopenharmony_ci Use the codespell dictionary for checking spelling errors. 19062306a36Sopenharmony_ci 19162306a36Sopenharmony_ci - --codespellfile 19262306a36Sopenharmony_ci 19362306a36Sopenharmony_ci Use the specified codespell file. 19462306a36Sopenharmony_ci Default is '/usr/share/codespell/dictionary.txt'. 19562306a36Sopenharmony_ci 19662306a36Sopenharmony_ci - --typedefsfile 19762306a36Sopenharmony_ci 19862306a36Sopenharmony_ci Read additional types from this file. 19962306a36Sopenharmony_ci 20062306a36Sopenharmony_ci - --color[=WHEN] 20162306a36Sopenharmony_ci 20262306a36Sopenharmony_ci Use colors 'always', 'never', or only when output is a terminal ('auto'). 20362306a36Sopenharmony_ci Default is 'auto'. 20462306a36Sopenharmony_ci 20562306a36Sopenharmony_ci - --kconfig-prefix=WORD 20662306a36Sopenharmony_ci 20762306a36Sopenharmony_ci Use WORD as a prefix for Kconfig symbols (default is `CONFIG_`). 20862306a36Sopenharmony_ci 20962306a36Sopenharmony_ci - -h, --help, --version 21062306a36Sopenharmony_ci 21162306a36Sopenharmony_ci Display the help text. 21262306a36Sopenharmony_ci 21362306a36Sopenharmony_ciMessage Levels 21462306a36Sopenharmony_ci============== 21562306a36Sopenharmony_ci 21662306a36Sopenharmony_ciMessages in checkpatch are divided into three levels. The levels of messages 21762306a36Sopenharmony_ciin checkpatch denote the severity of the error. They are: 21862306a36Sopenharmony_ci 21962306a36Sopenharmony_ci - ERROR 22062306a36Sopenharmony_ci 22162306a36Sopenharmony_ci This is the most strict level. Messages of type ERROR must be taken 22262306a36Sopenharmony_ci seriously as they denote things that are very likely to be wrong. 22362306a36Sopenharmony_ci 22462306a36Sopenharmony_ci - WARNING 22562306a36Sopenharmony_ci 22662306a36Sopenharmony_ci This is the next stricter level. Messages of type WARNING requires a 22762306a36Sopenharmony_ci more careful review. But it is milder than an ERROR. 22862306a36Sopenharmony_ci 22962306a36Sopenharmony_ci - CHECK 23062306a36Sopenharmony_ci 23162306a36Sopenharmony_ci This is the mildest level. These are things which may require some thought. 23262306a36Sopenharmony_ci 23362306a36Sopenharmony_ciType Descriptions 23462306a36Sopenharmony_ci================= 23562306a36Sopenharmony_ci 23662306a36Sopenharmony_ciThis section contains a description of all the message types in checkpatch. 23762306a36Sopenharmony_ci 23862306a36Sopenharmony_ci.. Types in this section are also parsed by checkpatch. 23962306a36Sopenharmony_ci.. The types are grouped into subsections based on use. 24062306a36Sopenharmony_ci 24162306a36Sopenharmony_ci 24262306a36Sopenharmony_ciAllocation style 24362306a36Sopenharmony_ci---------------- 24462306a36Sopenharmony_ci 24562306a36Sopenharmony_ci **ALLOC_ARRAY_ARGS** 24662306a36Sopenharmony_ci The first argument for kcalloc or kmalloc_array should be the 24762306a36Sopenharmony_ci number of elements. sizeof() as the first argument is generally 24862306a36Sopenharmony_ci wrong. 24962306a36Sopenharmony_ci 25062306a36Sopenharmony_ci See: https://www.kernel.org/doc/html/latest/core-api/memory-allocation.html 25162306a36Sopenharmony_ci 25262306a36Sopenharmony_ci **ALLOC_SIZEOF_STRUCT** 25362306a36Sopenharmony_ci The allocation style is bad. In general for family of 25462306a36Sopenharmony_ci allocation functions using sizeof() to get memory size, 25562306a36Sopenharmony_ci constructs like:: 25662306a36Sopenharmony_ci 25762306a36Sopenharmony_ci p = alloc(sizeof(struct foo), ...) 25862306a36Sopenharmony_ci 25962306a36Sopenharmony_ci should be:: 26062306a36Sopenharmony_ci 26162306a36Sopenharmony_ci p = alloc(sizeof(*p), ...) 26262306a36Sopenharmony_ci 26362306a36Sopenharmony_ci See: https://www.kernel.org/doc/html/latest/process/coding-style.html#allocating-memory 26462306a36Sopenharmony_ci 26562306a36Sopenharmony_ci **ALLOC_WITH_MULTIPLY** 26662306a36Sopenharmony_ci Prefer kmalloc_array/kcalloc over kmalloc/kzalloc with a 26762306a36Sopenharmony_ci sizeof multiply. 26862306a36Sopenharmony_ci 26962306a36Sopenharmony_ci See: https://www.kernel.org/doc/html/latest/core-api/memory-allocation.html 27062306a36Sopenharmony_ci 27162306a36Sopenharmony_ci 27262306a36Sopenharmony_ciAPI usage 27362306a36Sopenharmony_ci--------- 27462306a36Sopenharmony_ci 27562306a36Sopenharmony_ci **ARCH_DEFINES** 27662306a36Sopenharmony_ci Architecture specific defines should be avoided wherever 27762306a36Sopenharmony_ci possible. 27862306a36Sopenharmony_ci 27962306a36Sopenharmony_ci **ARCH_INCLUDE_LINUX** 28062306a36Sopenharmony_ci Whenever asm/file.h is included and linux/file.h exists, a 28162306a36Sopenharmony_ci conversion can be made when linux/file.h includes asm/file.h. 28262306a36Sopenharmony_ci However this is not always the case (See signal.h). 28362306a36Sopenharmony_ci This message type is emitted only for includes from arch/. 28462306a36Sopenharmony_ci 28562306a36Sopenharmony_ci **AVOID_BUG** 28662306a36Sopenharmony_ci BUG() or BUG_ON() should be avoided totally. 28762306a36Sopenharmony_ci Use WARN() and WARN_ON() instead, and handle the "impossible" 28862306a36Sopenharmony_ci error condition as gracefully as possible. 28962306a36Sopenharmony_ci 29062306a36Sopenharmony_ci See: https://www.kernel.org/doc/html/latest/process/deprecated.html#bug-and-bug-on 29162306a36Sopenharmony_ci 29262306a36Sopenharmony_ci **CONSIDER_KSTRTO** 29362306a36Sopenharmony_ci The simple_strtol(), simple_strtoll(), simple_strtoul(), and 29462306a36Sopenharmony_ci simple_strtoull() functions explicitly ignore overflows, which 29562306a36Sopenharmony_ci may lead to unexpected results in callers. The respective kstrtol(), 29662306a36Sopenharmony_ci kstrtoll(), kstrtoul(), and kstrtoull() functions tend to be the 29762306a36Sopenharmony_ci correct replacements. 29862306a36Sopenharmony_ci 29962306a36Sopenharmony_ci See: https://www.kernel.org/doc/html/latest/process/deprecated.html#simple-strtol-simple-strtoll-simple-strtoul-simple-strtoull 30062306a36Sopenharmony_ci 30162306a36Sopenharmony_ci **CONSTANT_CONVERSION** 30262306a36Sopenharmony_ci Use of __constant_<foo> form is discouraged for the following functions:: 30362306a36Sopenharmony_ci 30462306a36Sopenharmony_ci __constant_cpu_to_be[x] 30562306a36Sopenharmony_ci __constant_cpu_to_le[x] 30662306a36Sopenharmony_ci __constant_be[x]_to_cpu 30762306a36Sopenharmony_ci __constant_le[x]_to_cpu 30862306a36Sopenharmony_ci __constant_htons 30962306a36Sopenharmony_ci __constant_ntohs 31062306a36Sopenharmony_ci 31162306a36Sopenharmony_ci Using any of these outside of include/uapi/ is not preferred as using the 31262306a36Sopenharmony_ci function without __constant_ is identical when the argument is a 31362306a36Sopenharmony_ci constant. 31462306a36Sopenharmony_ci 31562306a36Sopenharmony_ci In big endian systems, the macros like __constant_cpu_to_be32(x) and 31662306a36Sopenharmony_ci cpu_to_be32(x) expand to the same expression:: 31762306a36Sopenharmony_ci 31862306a36Sopenharmony_ci #define __constant_cpu_to_be32(x) ((__force __be32)(__u32)(x)) 31962306a36Sopenharmony_ci #define __cpu_to_be32(x) ((__force __be32)(__u32)(x)) 32062306a36Sopenharmony_ci 32162306a36Sopenharmony_ci In little endian systems, the macros __constant_cpu_to_be32(x) and 32262306a36Sopenharmony_ci cpu_to_be32(x) expand to __constant_swab32 and __swab32. __swab32 32362306a36Sopenharmony_ci has a __builtin_constant_p check:: 32462306a36Sopenharmony_ci 32562306a36Sopenharmony_ci #define __swab32(x) \ 32662306a36Sopenharmony_ci (__builtin_constant_p((__u32)(x)) ? \ 32762306a36Sopenharmony_ci ___constant_swab32(x) : \ 32862306a36Sopenharmony_ci __fswab32(x)) 32962306a36Sopenharmony_ci 33062306a36Sopenharmony_ci So ultimately they have a special case for constants. 33162306a36Sopenharmony_ci Similar is the case with all of the macros in the list. Thus 33262306a36Sopenharmony_ci using the __constant_... forms are unnecessarily verbose and 33362306a36Sopenharmony_ci not preferred outside of include/uapi. 33462306a36Sopenharmony_ci 33562306a36Sopenharmony_ci See: https://lore.kernel.org/lkml/1400106425.12666.6.camel@joe-AO725/ 33662306a36Sopenharmony_ci 33762306a36Sopenharmony_ci **DEPRECATED_API** 33862306a36Sopenharmony_ci Usage of a deprecated RCU API is detected. It is recommended to replace 33962306a36Sopenharmony_ci old flavourful RCU APIs by their new vanilla-RCU counterparts. 34062306a36Sopenharmony_ci 34162306a36Sopenharmony_ci The full list of available RCU APIs can be viewed from the kernel docs. 34262306a36Sopenharmony_ci 34362306a36Sopenharmony_ci See: https://www.kernel.org/doc/html/latest/RCU/whatisRCU.html#full-list-of-rcu-apis 34462306a36Sopenharmony_ci 34562306a36Sopenharmony_ci **DEPRECATED_VARIABLE** 34662306a36Sopenharmony_ci EXTRA_{A,C,CPP,LD}FLAGS are deprecated and should be replaced by the new 34762306a36Sopenharmony_ci flags added via commit f77bf01425b1 ("kbuild: introduce ccflags-y, 34862306a36Sopenharmony_ci asflags-y and ldflags-y"). 34962306a36Sopenharmony_ci 35062306a36Sopenharmony_ci The following conversion scheme maybe used:: 35162306a36Sopenharmony_ci 35262306a36Sopenharmony_ci EXTRA_AFLAGS -> asflags-y 35362306a36Sopenharmony_ci EXTRA_CFLAGS -> ccflags-y 35462306a36Sopenharmony_ci EXTRA_CPPFLAGS -> cppflags-y 35562306a36Sopenharmony_ci EXTRA_LDFLAGS -> ldflags-y 35662306a36Sopenharmony_ci 35762306a36Sopenharmony_ci See: 35862306a36Sopenharmony_ci 35962306a36Sopenharmony_ci 1. https://lore.kernel.org/lkml/20070930191054.GA15876@uranus.ravnborg.org/ 36062306a36Sopenharmony_ci 2. https://lore.kernel.org/lkml/1313384834-24433-12-git-send-email-lacombar@gmail.com/ 36162306a36Sopenharmony_ci 3. https://www.kernel.org/doc/html/latest/kbuild/makefiles.html#compilation-flags 36262306a36Sopenharmony_ci 36362306a36Sopenharmony_ci **DEVICE_ATTR_FUNCTIONS** 36462306a36Sopenharmony_ci The function names used in DEVICE_ATTR is unusual. 36562306a36Sopenharmony_ci Typically, the store and show functions are used with <attr>_store and 36662306a36Sopenharmony_ci <attr>_show, where <attr> is a named attribute variable of the device. 36762306a36Sopenharmony_ci 36862306a36Sopenharmony_ci Consider the following examples:: 36962306a36Sopenharmony_ci 37062306a36Sopenharmony_ci static DEVICE_ATTR(type, 0444, type_show, NULL); 37162306a36Sopenharmony_ci static DEVICE_ATTR(power, 0644, power_show, power_store); 37262306a36Sopenharmony_ci 37362306a36Sopenharmony_ci The function names should preferably follow the above pattern. 37462306a36Sopenharmony_ci 37562306a36Sopenharmony_ci See: https://www.kernel.org/doc/html/latest/driver-api/driver-model/device.html#attributes 37662306a36Sopenharmony_ci 37762306a36Sopenharmony_ci **DEVICE_ATTR_RO** 37862306a36Sopenharmony_ci The DEVICE_ATTR_RO(name) helper macro can be used instead of 37962306a36Sopenharmony_ci DEVICE_ATTR(name, 0444, name_show, NULL); 38062306a36Sopenharmony_ci 38162306a36Sopenharmony_ci Note that the macro automatically appends _show to the named 38262306a36Sopenharmony_ci attribute variable of the device for the show method. 38362306a36Sopenharmony_ci 38462306a36Sopenharmony_ci See: https://www.kernel.org/doc/html/latest/driver-api/driver-model/device.html#attributes 38562306a36Sopenharmony_ci 38662306a36Sopenharmony_ci **DEVICE_ATTR_RW** 38762306a36Sopenharmony_ci The DEVICE_ATTR_RW(name) helper macro can be used instead of 38862306a36Sopenharmony_ci DEVICE_ATTR(name, 0644, name_show, name_store); 38962306a36Sopenharmony_ci 39062306a36Sopenharmony_ci Note that the macro automatically appends _show and _store to the 39162306a36Sopenharmony_ci named attribute variable of the device for the show and store methods. 39262306a36Sopenharmony_ci 39362306a36Sopenharmony_ci See: https://www.kernel.org/doc/html/latest/driver-api/driver-model/device.html#attributes 39462306a36Sopenharmony_ci 39562306a36Sopenharmony_ci **DEVICE_ATTR_WO** 39662306a36Sopenharmony_ci The DEVICE_AATR_WO(name) helper macro can be used instead of 39762306a36Sopenharmony_ci DEVICE_ATTR(name, 0200, NULL, name_store); 39862306a36Sopenharmony_ci 39962306a36Sopenharmony_ci Note that the macro automatically appends _store to the 40062306a36Sopenharmony_ci named attribute variable of the device for the store method. 40162306a36Sopenharmony_ci 40262306a36Sopenharmony_ci See: https://www.kernel.org/doc/html/latest/driver-api/driver-model/device.html#attributes 40362306a36Sopenharmony_ci 40462306a36Sopenharmony_ci **DUPLICATED_SYSCTL_CONST** 40562306a36Sopenharmony_ci Commit d91bff3011cf ("proc/sysctl: add shared variables for range 40662306a36Sopenharmony_ci check") added some shared const variables to be used instead of a local 40762306a36Sopenharmony_ci copy in each source file. 40862306a36Sopenharmony_ci 40962306a36Sopenharmony_ci Consider replacing the sysctl range checking value with the shared 41062306a36Sopenharmony_ci one in include/linux/sysctl.h. The following conversion scheme may 41162306a36Sopenharmony_ci be used:: 41262306a36Sopenharmony_ci 41362306a36Sopenharmony_ci &zero -> SYSCTL_ZERO 41462306a36Sopenharmony_ci &one -> SYSCTL_ONE 41562306a36Sopenharmony_ci &int_max -> SYSCTL_INT_MAX 41662306a36Sopenharmony_ci 41762306a36Sopenharmony_ci See: 41862306a36Sopenharmony_ci 41962306a36Sopenharmony_ci 1. https://lore.kernel.org/lkml/20190430180111.10688-1-mcroce@redhat.com/ 42062306a36Sopenharmony_ci 2. https://lore.kernel.org/lkml/20190531131422.14970-1-mcroce@redhat.com/ 42162306a36Sopenharmony_ci 42262306a36Sopenharmony_ci **ENOSYS** 42362306a36Sopenharmony_ci ENOSYS means that a nonexistent system call was called. 42462306a36Sopenharmony_ci Earlier, it was wrongly used for things like invalid operations on 42562306a36Sopenharmony_ci otherwise valid syscalls. This should be avoided in new code. 42662306a36Sopenharmony_ci 42762306a36Sopenharmony_ci See: https://lore.kernel.org/lkml/5eb299021dec23c1a48fa7d9f2c8b794e967766d.1408730669.git.luto@amacapital.net/ 42862306a36Sopenharmony_ci 42962306a36Sopenharmony_ci **ENOTSUPP** 43062306a36Sopenharmony_ci ENOTSUPP is not a standard error code and should be avoided in new patches. 43162306a36Sopenharmony_ci EOPNOTSUPP should be used instead. 43262306a36Sopenharmony_ci 43362306a36Sopenharmony_ci See: https://lore.kernel.org/netdev/20200510182252.GA411829@lunn.ch/ 43462306a36Sopenharmony_ci 43562306a36Sopenharmony_ci **EXPORT_SYMBOL** 43662306a36Sopenharmony_ci EXPORT_SYMBOL should immediately follow the symbol to be exported. 43762306a36Sopenharmony_ci 43862306a36Sopenharmony_ci **IN_ATOMIC** 43962306a36Sopenharmony_ci in_atomic() is not for driver use so any such use is reported as an ERROR. 44062306a36Sopenharmony_ci Also in_atomic() is often used to determine if sleeping is permitted, 44162306a36Sopenharmony_ci but it is not reliable in this use model. Therefore its use is 44262306a36Sopenharmony_ci strongly discouraged. 44362306a36Sopenharmony_ci 44462306a36Sopenharmony_ci However, in_atomic() is ok for core kernel use. 44562306a36Sopenharmony_ci 44662306a36Sopenharmony_ci See: https://lore.kernel.org/lkml/20080320201723.b87b3732.akpm@linux-foundation.org/ 44762306a36Sopenharmony_ci 44862306a36Sopenharmony_ci **LOCKDEP** 44962306a36Sopenharmony_ci The lockdep_no_validate class was added as a temporary measure to 45062306a36Sopenharmony_ci prevent warnings on conversion of device->sem to device->mutex. 45162306a36Sopenharmony_ci It should not be used for any other purpose. 45262306a36Sopenharmony_ci 45362306a36Sopenharmony_ci See: https://lore.kernel.org/lkml/1268959062.9440.467.camel@laptop/ 45462306a36Sopenharmony_ci 45562306a36Sopenharmony_ci **MALFORMED_INCLUDE** 45662306a36Sopenharmony_ci The #include statement has a malformed path. This has happened 45762306a36Sopenharmony_ci because the author has included a double slash "//" in the pathname 45862306a36Sopenharmony_ci accidentally. 45962306a36Sopenharmony_ci 46062306a36Sopenharmony_ci **USE_LOCKDEP** 46162306a36Sopenharmony_ci lockdep_assert_held() annotations should be preferred over 46262306a36Sopenharmony_ci assertions based on spin_is_locked() 46362306a36Sopenharmony_ci 46462306a36Sopenharmony_ci See: https://www.kernel.org/doc/html/latest/locking/lockdep-design.html#annotations 46562306a36Sopenharmony_ci 46662306a36Sopenharmony_ci **UAPI_INCLUDE** 46762306a36Sopenharmony_ci No #include statements in include/uapi should use a uapi/ path. 46862306a36Sopenharmony_ci 46962306a36Sopenharmony_ci **USLEEP_RANGE** 47062306a36Sopenharmony_ci usleep_range() should be preferred over udelay(). The proper way of 47162306a36Sopenharmony_ci using usleep_range() is mentioned in the kernel docs. 47262306a36Sopenharmony_ci 47362306a36Sopenharmony_ci See: https://www.kernel.org/doc/html/latest/timers/timers-howto.html#delays-information-on-the-various-kernel-delay-sleep-mechanisms 47462306a36Sopenharmony_ci 47562306a36Sopenharmony_ci 47662306a36Sopenharmony_ciComments 47762306a36Sopenharmony_ci-------- 47862306a36Sopenharmony_ci 47962306a36Sopenharmony_ci **BLOCK_COMMENT_STYLE** 48062306a36Sopenharmony_ci The comment style is incorrect. The preferred style for multi- 48162306a36Sopenharmony_ci line comments is:: 48262306a36Sopenharmony_ci 48362306a36Sopenharmony_ci /* 48462306a36Sopenharmony_ci * This is the preferred style 48562306a36Sopenharmony_ci * for multi line comments. 48662306a36Sopenharmony_ci */ 48762306a36Sopenharmony_ci 48862306a36Sopenharmony_ci The networking comment style is a bit different, with the first line 48962306a36Sopenharmony_ci not empty like the former:: 49062306a36Sopenharmony_ci 49162306a36Sopenharmony_ci /* This is the preferred comment style 49262306a36Sopenharmony_ci * for files in net/ and drivers/net/ 49362306a36Sopenharmony_ci */ 49462306a36Sopenharmony_ci 49562306a36Sopenharmony_ci See: https://www.kernel.org/doc/html/latest/process/coding-style.html#commenting 49662306a36Sopenharmony_ci 49762306a36Sopenharmony_ci **C99_COMMENTS** 49862306a36Sopenharmony_ci C99 style single line comments (//) should not be used. 49962306a36Sopenharmony_ci Prefer the block comment style instead. 50062306a36Sopenharmony_ci 50162306a36Sopenharmony_ci See: https://www.kernel.org/doc/html/latest/process/coding-style.html#commenting 50262306a36Sopenharmony_ci 50362306a36Sopenharmony_ci **DATA_RACE** 50462306a36Sopenharmony_ci Applications of data_race() should have a comment so as to document the 50562306a36Sopenharmony_ci reasoning behind why it was deemed safe. 50662306a36Sopenharmony_ci 50762306a36Sopenharmony_ci See: https://lore.kernel.org/lkml/20200401101714.44781-1-elver@google.com/ 50862306a36Sopenharmony_ci 50962306a36Sopenharmony_ci **FSF_MAILING_ADDRESS** 51062306a36Sopenharmony_ci Kernel maintainers reject new instances of the GPL boilerplate paragraph 51162306a36Sopenharmony_ci directing people to write to the FSF for a copy of the GPL, since the 51262306a36Sopenharmony_ci FSF has moved in the past and may do so again. 51362306a36Sopenharmony_ci So do not write paragraphs about writing to the Free Software Foundation's 51462306a36Sopenharmony_ci mailing address. 51562306a36Sopenharmony_ci 51662306a36Sopenharmony_ci See: https://lore.kernel.org/lkml/20131006222342.GT19510@leaf/ 51762306a36Sopenharmony_ci 51862306a36Sopenharmony_ci 51962306a36Sopenharmony_ciCommit message 52062306a36Sopenharmony_ci-------------- 52162306a36Sopenharmony_ci 52262306a36Sopenharmony_ci **BAD_SIGN_OFF** 52362306a36Sopenharmony_ci The signed-off-by line does not fall in line with the standards 52462306a36Sopenharmony_ci specified by the community. 52562306a36Sopenharmony_ci 52662306a36Sopenharmony_ci See: https://www.kernel.org/doc/html/latest/process/submitting-patches.html#developer-s-certificate-of-origin-1-1 52762306a36Sopenharmony_ci 52862306a36Sopenharmony_ci **BAD_STABLE_ADDRESS_STYLE** 52962306a36Sopenharmony_ci The email format for stable is incorrect. 53062306a36Sopenharmony_ci Some valid options for stable address are:: 53162306a36Sopenharmony_ci 53262306a36Sopenharmony_ci 1. stable@vger.kernel.org 53362306a36Sopenharmony_ci 2. stable@kernel.org 53462306a36Sopenharmony_ci 53562306a36Sopenharmony_ci For adding version info, the following comment style should be used:: 53662306a36Sopenharmony_ci 53762306a36Sopenharmony_ci stable@vger.kernel.org # version info 53862306a36Sopenharmony_ci 53962306a36Sopenharmony_ci **COMMIT_COMMENT_SYMBOL** 54062306a36Sopenharmony_ci Commit log lines starting with a '#' are ignored by git as 54162306a36Sopenharmony_ci comments. To solve this problem addition of a single space 54262306a36Sopenharmony_ci infront of the log line is enough. 54362306a36Sopenharmony_ci 54462306a36Sopenharmony_ci **COMMIT_MESSAGE** 54562306a36Sopenharmony_ci The patch is missing a commit description. A brief 54662306a36Sopenharmony_ci description of the changes made by the patch should be added. 54762306a36Sopenharmony_ci 54862306a36Sopenharmony_ci See: https://www.kernel.org/doc/html/latest/process/submitting-patches.html#describe-your-changes 54962306a36Sopenharmony_ci 55062306a36Sopenharmony_ci **EMAIL_SUBJECT** 55162306a36Sopenharmony_ci Naming the tool that found the issue is not very useful in the 55262306a36Sopenharmony_ci subject line. A good subject line summarizes the change that 55362306a36Sopenharmony_ci the patch brings. 55462306a36Sopenharmony_ci 55562306a36Sopenharmony_ci See: https://www.kernel.org/doc/html/latest/process/submitting-patches.html#describe-your-changes 55662306a36Sopenharmony_ci 55762306a36Sopenharmony_ci **FROM_SIGN_OFF_MISMATCH** 55862306a36Sopenharmony_ci The author's email does not match with that in the Signed-off-by: 55962306a36Sopenharmony_ci line(s). This can be sometimes caused due to an improperly configured 56062306a36Sopenharmony_ci email client. 56162306a36Sopenharmony_ci 56262306a36Sopenharmony_ci This message is emitted due to any of the following reasons:: 56362306a36Sopenharmony_ci 56462306a36Sopenharmony_ci - The email names do not match. 56562306a36Sopenharmony_ci - The email addresses do not match. 56662306a36Sopenharmony_ci - The email subaddresses do not match. 56762306a36Sopenharmony_ci - The email comments do not match. 56862306a36Sopenharmony_ci 56962306a36Sopenharmony_ci **MISSING_SIGN_OFF** 57062306a36Sopenharmony_ci The patch is missing a Signed-off-by line. A signed-off-by 57162306a36Sopenharmony_ci line should be added according to Developer's certificate of 57262306a36Sopenharmony_ci Origin. 57362306a36Sopenharmony_ci 57462306a36Sopenharmony_ci See: https://www.kernel.org/doc/html/latest/process/submitting-patches.html#sign-your-work-the-developer-s-certificate-of-origin 57562306a36Sopenharmony_ci 57662306a36Sopenharmony_ci **NO_AUTHOR_SIGN_OFF** 57762306a36Sopenharmony_ci The author of the patch has not signed off the patch. It is 57862306a36Sopenharmony_ci required that a simple sign off line should be present at the 57962306a36Sopenharmony_ci end of explanation of the patch to denote that the author has 58062306a36Sopenharmony_ci written it or otherwise has the rights to pass it on as an open 58162306a36Sopenharmony_ci source patch. 58262306a36Sopenharmony_ci 58362306a36Sopenharmony_ci See: https://www.kernel.org/doc/html/latest/process/submitting-patches.html#sign-your-work-the-developer-s-certificate-of-origin 58462306a36Sopenharmony_ci 58562306a36Sopenharmony_ci **DIFF_IN_COMMIT_MSG** 58662306a36Sopenharmony_ci Avoid having diff content in commit message. 58762306a36Sopenharmony_ci This causes problems when one tries to apply a file containing both 58862306a36Sopenharmony_ci the changelog and the diff because patch(1) tries to apply the diff 58962306a36Sopenharmony_ci which it found in the changelog. 59062306a36Sopenharmony_ci 59162306a36Sopenharmony_ci See: https://lore.kernel.org/lkml/20150611134006.9df79a893e3636019ad2759e@linux-foundation.org/ 59262306a36Sopenharmony_ci 59362306a36Sopenharmony_ci **GERRIT_CHANGE_ID** 59462306a36Sopenharmony_ci To be picked up by gerrit, the footer of the commit message might 59562306a36Sopenharmony_ci have a Change-Id like:: 59662306a36Sopenharmony_ci 59762306a36Sopenharmony_ci Change-Id: Ic8aaa0728a43936cd4c6e1ed590e01ba8f0fbf5b 59862306a36Sopenharmony_ci Signed-off-by: A. U. Thor <author@example.com> 59962306a36Sopenharmony_ci 60062306a36Sopenharmony_ci The Change-Id line must be removed before submitting. 60162306a36Sopenharmony_ci 60262306a36Sopenharmony_ci **GIT_COMMIT_ID** 60362306a36Sopenharmony_ci The proper way to reference a commit id is: 60462306a36Sopenharmony_ci commit <12+ chars of sha1> ("<title line>") 60562306a36Sopenharmony_ci 60662306a36Sopenharmony_ci An example may be:: 60762306a36Sopenharmony_ci 60862306a36Sopenharmony_ci Commit e21d2170f36602ae2708 ("video: remove unnecessary 60962306a36Sopenharmony_ci platform_set_drvdata()") removed the unnecessary 61062306a36Sopenharmony_ci platform_set_drvdata(), but left the variable "dev" unused, 61162306a36Sopenharmony_ci delete it. 61262306a36Sopenharmony_ci 61362306a36Sopenharmony_ci See: https://www.kernel.org/doc/html/latest/process/submitting-patches.html#describe-your-changes 61462306a36Sopenharmony_ci 61562306a36Sopenharmony_ci **BAD_FIXES_TAG** 61662306a36Sopenharmony_ci The Fixes: tag is malformed or does not follow the community conventions. 61762306a36Sopenharmony_ci This can occur if the tag have been split into multiple lines (e.g., when 61862306a36Sopenharmony_ci pasted in an email program with word wrapping enabled). 61962306a36Sopenharmony_ci 62062306a36Sopenharmony_ci See: https://www.kernel.org/doc/html/latest/process/submitting-patches.html#describe-your-changes 62162306a36Sopenharmony_ci 62262306a36Sopenharmony_ci 62362306a36Sopenharmony_ciComparison style 62462306a36Sopenharmony_ci---------------- 62562306a36Sopenharmony_ci 62662306a36Sopenharmony_ci **ASSIGN_IN_IF** 62762306a36Sopenharmony_ci Do not use assignments in if condition. 62862306a36Sopenharmony_ci Example:: 62962306a36Sopenharmony_ci 63062306a36Sopenharmony_ci if ((foo = bar(...)) < BAZ) { 63162306a36Sopenharmony_ci 63262306a36Sopenharmony_ci should be written as:: 63362306a36Sopenharmony_ci 63462306a36Sopenharmony_ci foo = bar(...); 63562306a36Sopenharmony_ci if (foo < BAZ) { 63662306a36Sopenharmony_ci 63762306a36Sopenharmony_ci **BOOL_COMPARISON** 63862306a36Sopenharmony_ci Comparisons of A to true and false are better written 63962306a36Sopenharmony_ci as A and !A. 64062306a36Sopenharmony_ci 64162306a36Sopenharmony_ci See: https://lore.kernel.org/lkml/1365563834.27174.12.camel@joe-AO722/ 64262306a36Sopenharmony_ci 64362306a36Sopenharmony_ci **COMPARISON_TO_NULL** 64462306a36Sopenharmony_ci Comparisons to NULL in the form (foo == NULL) or (foo != NULL) 64562306a36Sopenharmony_ci are better written as (!foo) and (foo). 64662306a36Sopenharmony_ci 64762306a36Sopenharmony_ci **CONSTANT_COMPARISON** 64862306a36Sopenharmony_ci Comparisons with a constant or upper case identifier on the left 64962306a36Sopenharmony_ci side of the test should be avoided. 65062306a36Sopenharmony_ci 65162306a36Sopenharmony_ci 65262306a36Sopenharmony_ciIndentation and Line Breaks 65362306a36Sopenharmony_ci--------------------------- 65462306a36Sopenharmony_ci 65562306a36Sopenharmony_ci **CODE_INDENT** 65662306a36Sopenharmony_ci Code indent should use tabs instead of spaces. 65762306a36Sopenharmony_ci Outside of comments, documentation and Kconfig, 65862306a36Sopenharmony_ci spaces are never used for indentation. 65962306a36Sopenharmony_ci 66062306a36Sopenharmony_ci See: https://www.kernel.org/doc/html/latest/process/coding-style.html#indentation 66162306a36Sopenharmony_ci 66262306a36Sopenharmony_ci **DEEP_INDENTATION** 66362306a36Sopenharmony_ci Indentation with 6 or more tabs usually indicate overly indented 66462306a36Sopenharmony_ci code. 66562306a36Sopenharmony_ci 66662306a36Sopenharmony_ci It is suggested to refactor excessive indentation of 66762306a36Sopenharmony_ci if/else/for/do/while/switch statements. 66862306a36Sopenharmony_ci 66962306a36Sopenharmony_ci See: https://lore.kernel.org/lkml/1328311239.21255.24.camel@joe2Laptop/ 67062306a36Sopenharmony_ci 67162306a36Sopenharmony_ci **SWITCH_CASE_INDENT_LEVEL** 67262306a36Sopenharmony_ci switch should be at the same indent as case. 67362306a36Sopenharmony_ci Example:: 67462306a36Sopenharmony_ci 67562306a36Sopenharmony_ci switch (suffix) { 67662306a36Sopenharmony_ci case 'G': 67762306a36Sopenharmony_ci case 'g': 67862306a36Sopenharmony_ci mem <<= 30; 67962306a36Sopenharmony_ci break; 68062306a36Sopenharmony_ci case 'M': 68162306a36Sopenharmony_ci case 'm': 68262306a36Sopenharmony_ci mem <<= 20; 68362306a36Sopenharmony_ci break; 68462306a36Sopenharmony_ci case 'K': 68562306a36Sopenharmony_ci case 'k': 68662306a36Sopenharmony_ci mem <<= 10; 68762306a36Sopenharmony_ci fallthrough; 68862306a36Sopenharmony_ci default: 68962306a36Sopenharmony_ci break; 69062306a36Sopenharmony_ci } 69162306a36Sopenharmony_ci 69262306a36Sopenharmony_ci See: https://www.kernel.org/doc/html/latest/process/coding-style.html#indentation 69362306a36Sopenharmony_ci 69462306a36Sopenharmony_ci **LONG_LINE** 69562306a36Sopenharmony_ci The line has exceeded the specified maximum length. 69662306a36Sopenharmony_ci To use a different maximum line length, the --max-line-length=n option 69762306a36Sopenharmony_ci may be added while invoking checkpatch. 69862306a36Sopenharmony_ci 69962306a36Sopenharmony_ci Earlier, the default line length was 80 columns. Commit bdc48fa11e46 70062306a36Sopenharmony_ci ("checkpatch/coding-style: deprecate 80-column warning") increased the 70162306a36Sopenharmony_ci limit to 100 columns. This is not a hard limit either and it's 70262306a36Sopenharmony_ci preferable to stay within 80 columns whenever possible. 70362306a36Sopenharmony_ci 70462306a36Sopenharmony_ci See: https://www.kernel.org/doc/html/latest/process/coding-style.html#breaking-long-lines-and-strings 70562306a36Sopenharmony_ci 70662306a36Sopenharmony_ci **LONG_LINE_STRING** 70762306a36Sopenharmony_ci A string starts before but extends beyond the maximum line length. 70862306a36Sopenharmony_ci To use a different maximum line length, the --max-line-length=n option 70962306a36Sopenharmony_ci may be added while invoking checkpatch. 71062306a36Sopenharmony_ci 71162306a36Sopenharmony_ci See: https://www.kernel.org/doc/html/latest/process/coding-style.html#breaking-long-lines-and-strings 71262306a36Sopenharmony_ci 71362306a36Sopenharmony_ci **LONG_LINE_COMMENT** 71462306a36Sopenharmony_ci A comment starts before but extends beyond the maximum line length. 71562306a36Sopenharmony_ci To use a different maximum line length, the --max-line-length=n option 71662306a36Sopenharmony_ci may be added while invoking checkpatch. 71762306a36Sopenharmony_ci 71862306a36Sopenharmony_ci See: https://www.kernel.org/doc/html/latest/process/coding-style.html#breaking-long-lines-and-strings 71962306a36Sopenharmony_ci 72062306a36Sopenharmony_ci **SPLIT_STRING** 72162306a36Sopenharmony_ci Quoted strings that appear as messages in userspace and can be 72262306a36Sopenharmony_ci grepped, should not be split across multiple lines. 72362306a36Sopenharmony_ci 72462306a36Sopenharmony_ci See: https://lore.kernel.org/lkml/20120203052727.GA15035@leaf/ 72562306a36Sopenharmony_ci 72662306a36Sopenharmony_ci **MULTILINE_DEREFERENCE** 72762306a36Sopenharmony_ci A single dereferencing identifier spanned on multiple lines like:: 72862306a36Sopenharmony_ci 72962306a36Sopenharmony_ci struct_identifier->member[index]. 73062306a36Sopenharmony_ci member = <foo>; 73162306a36Sopenharmony_ci 73262306a36Sopenharmony_ci is generally hard to follow. It can easily lead to typos and so makes 73362306a36Sopenharmony_ci the code vulnerable to bugs. 73462306a36Sopenharmony_ci 73562306a36Sopenharmony_ci If fixing the multiple line dereferencing leads to an 80 column 73662306a36Sopenharmony_ci violation, then either rewrite the code in a more simple way or if the 73762306a36Sopenharmony_ci starting part of the dereferencing identifier is the same and used at 73862306a36Sopenharmony_ci multiple places then store it in a temporary variable, and use that 73962306a36Sopenharmony_ci temporary variable only at all the places. For example, if there are 74062306a36Sopenharmony_ci two dereferencing identifiers:: 74162306a36Sopenharmony_ci 74262306a36Sopenharmony_ci member1->member2->member3.foo1; 74362306a36Sopenharmony_ci member1->member2->member3.foo2; 74462306a36Sopenharmony_ci 74562306a36Sopenharmony_ci then store the member1->member2->member3 part in a temporary variable. 74662306a36Sopenharmony_ci It not only helps to avoid the 80 column violation but also reduces 74762306a36Sopenharmony_ci the program size by removing the unnecessary dereferences. 74862306a36Sopenharmony_ci 74962306a36Sopenharmony_ci But if none of the above methods work then ignore the 80 column 75062306a36Sopenharmony_ci violation because it is much easier to read a dereferencing identifier 75162306a36Sopenharmony_ci on a single line. 75262306a36Sopenharmony_ci 75362306a36Sopenharmony_ci **TRAILING_STATEMENTS** 75462306a36Sopenharmony_ci Trailing statements (for example after any conditional) should be 75562306a36Sopenharmony_ci on the next line. 75662306a36Sopenharmony_ci Statements, such as:: 75762306a36Sopenharmony_ci 75862306a36Sopenharmony_ci if (x == y) break; 75962306a36Sopenharmony_ci 76062306a36Sopenharmony_ci should be:: 76162306a36Sopenharmony_ci 76262306a36Sopenharmony_ci if (x == y) 76362306a36Sopenharmony_ci break; 76462306a36Sopenharmony_ci 76562306a36Sopenharmony_ci 76662306a36Sopenharmony_ciMacros, Attributes and Symbols 76762306a36Sopenharmony_ci------------------------------ 76862306a36Sopenharmony_ci 76962306a36Sopenharmony_ci **ARRAY_SIZE** 77062306a36Sopenharmony_ci The ARRAY_SIZE(foo) macro should be preferred over 77162306a36Sopenharmony_ci sizeof(foo)/sizeof(foo[0]) for finding number of elements in an 77262306a36Sopenharmony_ci array. 77362306a36Sopenharmony_ci 77462306a36Sopenharmony_ci The macro is defined in include/linux/kernel.h:: 77562306a36Sopenharmony_ci 77662306a36Sopenharmony_ci #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) 77762306a36Sopenharmony_ci 77862306a36Sopenharmony_ci **AVOID_EXTERNS** 77962306a36Sopenharmony_ci Function prototypes don't need to be declared extern in .h 78062306a36Sopenharmony_ci files. It's assumed by the compiler and is unnecessary. 78162306a36Sopenharmony_ci 78262306a36Sopenharmony_ci **AVOID_L_PREFIX** 78362306a36Sopenharmony_ci Local symbol names that are prefixed with `.L` should be avoided, 78462306a36Sopenharmony_ci as this has special meaning for the assembler; a symbol entry will 78562306a36Sopenharmony_ci not be emitted into the symbol table. This can prevent `objtool` 78662306a36Sopenharmony_ci from generating correct unwind info. 78762306a36Sopenharmony_ci 78862306a36Sopenharmony_ci Symbols with STB_LOCAL binding may still be used, and `.L` prefixed 78962306a36Sopenharmony_ci local symbol names are still generally usable within a function, 79062306a36Sopenharmony_ci but `.L` prefixed local symbol names should not be used to denote 79162306a36Sopenharmony_ci the beginning or end of code regions via 79262306a36Sopenharmony_ci `SYM_CODE_START_LOCAL`/`SYM_CODE_END` 79362306a36Sopenharmony_ci 79462306a36Sopenharmony_ci **BIT_MACRO** 79562306a36Sopenharmony_ci Defines like: 1 << <digit> could be BIT(digit). 79662306a36Sopenharmony_ci The BIT() macro is defined via include/linux/bits.h:: 79762306a36Sopenharmony_ci 79862306a36Sopenharmony_ci #define BIT(nr) (1UL << (nr)) 79962306a36Sopenharmony_ci 80062306a36Sopenharmony_ci **CONST_READ_MOSTLY** 80162306a36Sopenharmony_ci When a variable is tagged with the __read_mostly annotation, it is a 80262306a36Sopenharmony_ci signal to the compiler that accesses to the variable will be mostly 80362306a36Sopenharmony_ci reads and rarely(but NOT never) a write. 80462306a36Sopenharmony_ci 80562306a36Sopenharmony_ci const __read_mostly does not make any sense as const data is already 80662306a36Sopenharmony_ci read-only. The __read_mostly annotation thus should be removed. 80762306a36Sopenharmony_ci 80862306a36Sopenharmony_ci **DATE_TIME** 80962306a36Sopenharmony_ci It is generally desirable that building the same source code with 81062306a36Sopenharmony_ci the same set of tools is reproducible, i.e. the output is always 81162306a36Sopenharmony_ci exactly the same. 81262306a36Sopenharmony_ci 81362306a36Sopenharmony_ci The kernel does *not* use the ``__DATE__`` and ``__TIME__`` macros, 81462306a36Sopenharmony_ci and enables warnings if they are used as they can lead to 81562306a36Sopenharmony_ci non-deterministic builds. 81662306a36Sopenharmony_ci 81762306a36Sopenharmony_ci See: https://www.kernel.org/doc/html/latest/kbuild/reproducible-builds.html#timestamps 81862306a36Sopenharmony_ci 81962306a36Sopenharmony_ci **DEFINE_ARCH_HAS** 82062306a36Sopenharmony_ci The ARCH_HAS_xyz and ARCH_HAVE_xyz patterns are wrong. 82162306a36Sopenharmony_ci 82262306a36Sopenharmony_ci For big conceptual features use Kconfig symbols instead. And for 82362306a36Sopenharmony_ci smaller things where we have compatibility fallback functions but 82462306a36Sopenharmony_ci want architectures able to override them with optimized ones, we 82562306a36Sopenharmony_ci should either use weak functions (appropriate for some cases), or 82662306a36Sopenharmony_ci the symbol that protects them should be the same symbol we use. 82762306a36Sopenharmony_ci 82862306a36Sopenharmony_ci See: https://lore.kernel.org/lkml/CA+55aFycQ9XJvEOsiM3txHL5bjUc8CeKWJNR_H+MiicaddB42Q@mail.gmail.com/ 82962306a36Sopenharmony_ci 83062306a36Sopenharmony_ci **DO_WHILE_MACRO_WITH_TRAILING_SEMICOLON** 83162306a36Sopenharmony_ci do {} while(0) macros should not have a trailing semicolon. 83262306a36Sopenharmony_ci 83362306a36Sopenharmony_ci **INIT_ATTRIBUTE** 83462306a36Sopenharmony_ci Const init definitions should use __initconst instead of 83562306a36Sopenharmony_ci __initdata. 83662306a36Sopenharmony_ci 83762306a36Sopenharmony_ci Similarly init definitions without const require a separate 83862306a36Sopenharmony_ci use of const. 83962306a36Sopenharmony_ci 84062306a36Sopenharmony_ci **INLINE_LOCATION** 84162306a36Sopenharmony_ci The inline keyword should sit between storage class and type. 84262306a36Sopenharmony_ci 84362306a36Sopenharmony_ci For example, the following segment:: 84462306a36Sopenharmony_ci 84562306a36Sopenharmony_ci inline static int example_function(void) 84662306a36Sopenharmony_ci { 84762306a36Sopenharmony_ci ... 84862306a36Sopenharmony_ci } 84962306a36Sopenharmony_ci 85062306a36Sopenharmony_ci should be:: 85162306a36Sopenharmony_ci 85262306a36Sopenharmony_ci static inline int example_function(void) 85362306a36Sopenharmony_ci { 85462306a36Sopenharmony_ci ... 85562306a36Sopenharmony_ci } 85662306a36Sopenharmony_ci 85762306a36Sopenharmony_ci **MISPLACED_INIT** 85862306a36Sopenharmony_ci It is possible to use section markers on variables in a way 85962306a36Sopenharmony_ci which gcc doesn't understand (or at least not the way the 86062306a36Sopenharmony_ci developer intended):: 86162306a36Sopenharmony_ci 86262306a36Sopenharmony_ci static struct __initdata samsung_pll_clock exynos4_plls[nr_plls] = { 86362306a36Sopenharmony_ci 86462306a36Sopenharmony_ci does not put exynos4_plls in the .initdata section. The __initdata 86562306a36Sopenharmony_ci marker can be virtually anywhere on the line, except right after 86662306a36Sopenharmony_ci "struct". The preferred location is before the "=" sign if there is 86762306a36Sopenharmony_ci one, or before the trailing ";" otherwise. 86862306a36Sopenharmony_ci 86962306a36Sopenharmony_ci See: https://lore.kernel.org/lkml/1377655732.3619.19.camel@joe-AO722/ 87062306a36Sopenharmony_ci 87162306a36Sopenharmony_ci **MULTISTATEMENT_MACRO_USE_DO_WHILE** 87262306a36Sopenharmony_ci Macros with multiple statements should be enclosed in a 87362306a36Sopenharmony_ci do - while block. Same should also be the case for macros 87462306a36Sopenharmony_ci starting with `if` to avoid logic defects:: 87562306a36Sopenharmony_ci 87662306a36Sopenharmony_ci #define macrofun(a, b, c) \ 87762306a36Sopenharmony_ci do { \ 87862306a36Sopenharmony_ci if (a == 5) \ 87962306a36Sopenharmony_ci do_this(b, c); \ 88062306a36Sopenharmony_ci } while (0) 88162306a36Sopenharmony_ci 88262306a36Sopenharmony_ci See: https://www.kernel.org/doc/html/latest/process/coding-style.html#macros-enums-and-rtl 88362306a36Sopenharmony_ci 88462306a36Sopenharmony_ci **PREFER_FALLTHROUGH** 88562306a36Sopenharmony_ci Use the `fallthrough;` pseudo keyword instead of 88662306a36Sopenharmony_ci `/* fallthrough */` like comments. 88762306a36Sopenharmony_ci 88862306a36Sopenharmony_ci **TRAILING_SEMICOLON** 88962306a36Sopenharmony_ci Macro definition should not end with a semicolon. The macro 89062306a36Sopenharmony_ci invocation style should be consistent with function calls. 89162306a36Sopenharmony_ci This can prevent any unexpected code paths:: 89262306a36Sopenharmony_ci 89362306a36Sopenharmony_ci #define MAC do_something; 89462306a36Sopenharmony_ci 89562306a36Sopenharmony_ci If this macro is used within a if else statement, like:: 89662306a36Sopenharmony_ci 89762306a36Sopenharmony_ci if (some_condition) 89862306a36Sopenharmony_ci MAC; 89962306a36Sopenharmony_ci 90062306a36Sopenharmony_ci else 90162306a36Sopenharmony_ci do_something; 90262306a36Sopenharmony_ci 90362306a36Sopenharmony_ci Then there would be a compilation error, because when the macro is 90462306a36Sopenharmony_ci expanded there are two trailing semicolons, so the else branch gets 90562306a36Sopenharmony_ci orphaned. 90662306a36Sopenharmony_ci 90762306a36Sopenharmony_ci See: https://lore.kernel.org/lkml/1399671106.2912.21.camel@joe-AO725/ 90862306a36Sopenharmony_ci 90962306a36Sopenharmony_ci **SINGLE_STATEMENT_DO_WHILE_MACRO** 91062306a36Sopenharmony_ci For the multi-statement macros, it is necessary to use the do-while 91162306a36Sopenharmony_ci loop to avoid unpredictable code paths. The do-while loop helps to 91262306a36Sopenharmony_ci group the multiple statements into a single one so that a 91362306a36Sopenharmony_ci function-like macro can be used as a function only. 91462306a36Sopenharmony_ci 91562306a36Sopenharmony_ci But for the single statement macros, it is unnecessary to use the 91662306a36Sopenharmony_ci do-while loop. Although the code is syntactically correct but using 91762306a36Sopenharmony_ci the do-while loop is redundant. So remove the do-while loop for single 91862306a36Sopenharmony_ci statement macros. 91962306a36Sopenharmony_ci 92062306a36Sopenharmony_ci **WEAK_DECLARATION** 92162306a36Sopenharmony_ci Using weak declarations like __attribute__((weak)) or __weak 92262306a36Sopenharmony_ci can have unintended link defects. Avoid using them. 92362306a36Sopenharmony_ci 92462306a36Sopenharmony_ci 92562306a36Sopenharmony_ciFunctions and Variables 92662306a36Sopenharmony_ci----------------------- 92762306a36Sopenharmony_ci 92862306a36Sopenharmony_ci **CAMELCASE** 92962306a36Sopenharmony_ci Avoid CamelCase Identifiers. 93062306a36Sopenharmony_ci 93162306a36Sopenharmony_ci See: https://www.kernel.org/doc/html/latest/process/coding-style.html#naming 93262306a36Sopenharmony_ci 93362306a36Sopenharmony_ci **CONST_CONST** 93462306a36Sopenharmony_ci Using `const <type> const *` is generally meant to be 93562306a36Sopenharmony_ci written `const <type> * const`. 93662306a36Sopenharmony_ci 93762306a36Sopenharmony_ci **CONST_STRUCT** 93862306a36Sopenharmony_ci Using const is generally a good idea. Checkpatch reads 93962306a36Sopenharmony_ci a list of frequently used structs that are always or 94062306a36Sopenharmony_ci almost always constant. 94162306a36Sopenharmony_ci 94262306a36Sopenharmony_ci The existing structs list can be viewed from 94362306a36Sopenharmony_ci `scripts/const_structs.checkpatch`. 94462306a36Sopenharmony_ci 94562306a36Sopenharmony_ci See: https://lore.kernel.org/lkml/alpine.DEB.2.10.1608281509480.3321@hadrien/ 94662306a36Sopenharmony_ci 94762306a36Sopenharmony_ci **EMBEDDED_FUNCTION_NAME** 94862306a36Sopenharmony_ci Embedded function names are less appropriate to use as 94962306a36Sopenharmony_ci refactoring can cause function renaming. Prefer the use of 95062306a36Sopenharmony_ci "%s", __func__ to embedded function names. 95162306a36Sopenharmony_ci 95262306a36Sopenharmony_ci Note that this does not work with -f (--file) checkpatch option 95362306a36Sopenharmony_ci as it depends on patch context providing the function name. 95462306a36Sopenharmony_ci 95562306a36Sopenharmony_ci **FUNCTION_ARGUMENTS** 95662306a36Sopenharmony_ci This warning is emitted due to any of the following reasons: 95762306a36Sopenharmony_ci 95862306a36Sopenharmony_ci 1. Arguments for the function declaration do not follow 95962306a36Sopenharmony_ci the identifier name. Example:: 96062306a36Sopenharmony_ci 96162306a36Sopenharmony_ci void foo 96262306a36Sopenharmony_ci (int bar, int baz) 96362306a36Sopenharmony_ci 96462306a36Sopenharmony_ci This should be corrected to:: 96562306a36Sopenharmony_ci 96662306a36Sopenharmony_ci void foo(int bar, int baz) 96762306a36Sopenharmony_ci 96862306a36Sopenharmony_ci 2. Some arguments for the function definition do not 96962306a36Sopenharmony_ci have an identifier name. Example:: 97062306a36Sopenharmony_ci 97162306a36Sopenharmony_ci void foo(int) 97262306a36Sopenharmony_ci 97362306a36Sopenharmony_ci All arguments should have identifier names. 97462306a36Sopenharmony_ci 97562306a36Sopenharmony_ci **FUNCTION_WITHOUT_ARGS** 97662306a36Sopenharmony_ci Function declarations without arguments like:: 97762306a36Sopenharmony_ci 97862306a36Sopenharmony_ci int foo() 97962306a36Sopenharmony_ci 98062306a36Sopenharmony_ci should be:: 98162306a36Sopenharmony_ci 98262306a36Sopenharmony_ci int foo(void) 98362306a36Sopenharmony_ci 98462306a36Sopenharmony_ci **GLOBAL_INITIALISERS** 98562306a36Sopenharmony_ci Global variables should not be initialized explicitly to 98662306a36Sopenharmony_ci 0 (or NULL, false, etc.). Your compiler (or rather your 98762306a36Sopenharmony_ci loader, which is responsible for zeroing out the relevant 98862306a36Sopenharmony_ci sections) automatically does it for you. 98962306a36Sopenharmony_ci 99062306a36Sopenharmony_ci **INITIALISED_STATIC** 99162306a36Sopenharmony_ci Static variables should not be initialized explicitly to zero. 99262306a36Sopenharmony_ci Your compiler (or rather your loader) automatically does 99362306a36Sopenharmony_ci it for you. 99462306a36Sopenharmony_ci 99562306a36Sopenharmony_ci **MULTIPLE_ASSIGNMENTS** 99662306a36Sopenharmony_ci Multiple assignments on a single line makes the code unnecessarily 99762306a36Sopenharmony_ci complicated. So on a single line assign value to a single variable 99862306a36Sopenharmony_ci only, this makes the code more readable and helps avoid typos. 99962306a36Sopenharmony_ci 100062306a36Sopenharmony_ci **RETURN_PARENTHESES** 100162306a36Sopenharmony_ci return is not a function and as such doesn't need parentheses:: 100262306a36Sopenharmony_ci 100362306a36Sopenharmony_ci return (bar); 100462306a36Sopenharmony_ci 100562306a36Sopenharmony_ci can simply be:: 100662306a36Sopenharmony_ci 100762306a36Sopenharmony_ci return bar; 100862306a36Sopenharmony_ci 100962306a36Sopenharmony_ci 101062306a36Sopenharmony_ciPermissions 101162306a36Sopenharmony_ci----------- 101262306a36Sopenharmony_ci 101362306a36Sopenharmony_ci **DEVICE_ATTR_PERMS** 101462306a36Sopenharmony_ci The permissions used in DEVICE_ATTR are unusual. 101562306a36Sopenharmony_ci Typically only three permissions are used - 0644 (RW), 0444 (RO) 101662306a36Sopenharmony_ci and 0200 (WO). 101762306a36Sopenharmony_ci 101862306a36Sopenharmony_ci See: https://www.kernel.org/doc/html/latest/filesystems/sysfs.html#attributes 101962306a36Sopenharmony_ci 102062306a36Sopenharmony_ci **EXECUTE_PERMISSIONS** 102162306a36Sopenharmony_ci There is no reason for source files to be executable. The executable 102262306a36Sopenharmony_ci bit can be removed safely. 102362306a36Sopenharmony_ci 102462306a36Sopenharmony_ci **EXPORTED_WORLD_WRITABLE** 102562306a36Sopenharmony_ci Exporting world writable sysfs/debugfs files is usually a bad thing. 102662306a36Sopenharmony_ci When done arbitrarily they can introduce serious security bugs. 102762306a36Sopenharmony_ci In the past, some of the debugfs vulnerabilities would seemingly allow 102862306a36Sopenharmony_ci any local user to write arbitrary values into device registers - a 102962306a36Sopenharmony_ci situation from which little good can be expected to emerge. 103062306a36Sopenharmony_ci 103162306a36Sopenharmony_ci See: https://lore.kernel.org/linux-arm-kernel/cover.1296818921.git.segoon@openwall.com/ 103262306a36Sopenharmony_ci 103362306a36Sopenharmony_ci **NON_OCTAL_PERMISSIONS** 103462306a36Sopenharmony_ci Permission bits should use 4 digit octal permissions (like 0700 or 0444). 103562306a36Sopenharmony_ci Avoid using any other base like decimal. 103662306a36Sopenharmony_ci 103762306a36Sopenharmony_ci **SYMBOLIC_PERMS** 103862306a36Sopenharmony_ci Permission bits in the octal form are more readable and easier to 103962306a36Sopenharmony_ci understand than their symbolic counterparts because many command-line 104062306a36Sopenharmony_ci tools use this notation. Experienced kernel developers have been using 104162306a36Sopenharmony_ci these traditional Unix permission bits for decades and so they find it 104262306a36Sopenharmony_ci easier to understand the octal notation than the symbolic macros. 104362306a36Sopenharmony_ci For example, it is harder to read S_IWUSR|S_IRUGO than 0644, which 104462306a36Sopenharmony_ci obscures the developer's intent rather than clarifying it. 104562306a36Sopenharmony_ci 104662306a36Sopenharmony_ci See: https://lore.kernel.org/lkml/CA+55aFw5v23T-zvDZp-MmD_EYxF8WbafwwB59934FV7g21uMGQ@mail.gmail.com/ 104762306a36Sopenharmony_ci 104862306a36Sopenharmony_ci 104962306a36Sopenharmony_ciSpacing and Brackets 105062306a36Sopenharmony_ci-------------------- 105162306a36Sopenharmony_ci 105262306a36Sopenharmony_ci **ASSIGNMENT_CONTINUATIONS** 105362306a36Sopenharmony_ci Assignment operators should not be written at the start of a 105462306a36Sopenharmony_ci line but should follow the operand at the previous line. 105562306a36Sopenharmony_ci 105662306a36Sopenharmony_ci **BRACES** 105762306a36Sopenharmony_ci The placement of braces is stylistically incorrect. 105862306a36Sopenharmony_ci The preferred way is to put the opening brace last on the line, 105962306a36Sopenharmony_ci and put the closing brace first:: 106062306a36Sopenharmony_ci 106162306a36Sopenharmony_ci if (x is true) { 106262306a36Sopenharmony_ci we do y 106362306a36Sopenharmony_ci } 106462306a36Sopenharmony_ci 106562306a36Sopenharmony_ci This applies for all non-functional blocks. 106662306a36Sopenharmony_ci However, there is one special case, namely functions: they have the 106762306a36Sopenharmony_ci opening brace at the beginning of the next line, thus:: 106862306a36Sopenharmony_ci 106962306a36Sopenharmony_ci int function(int x) 107062306a36Sopenharmony_ci { 107162306a36Sopenharmony_ci body of function 107262306a36Sopenharmony_ci } 107362306a36Sopenharmony_ci 107462306a36Sopenharmony_ci See: https://www.kernel.org/doc/html/latest/process/coding-style.html#placing-braces-and-spaces 107562306a36Sopenharmony_ci 107662306a36Sopenharmony_ci **BRACKET_SPACE** 107762306a36Sopenharmony_ci Whitespace before opening bracket '[' is prohibited. 107862306a36Sopenharmony_ci There are some exceptions: 107962306a36Sopenharmony_ci 108062306a36Sopenharmony_ci 1. With a type on the left:: 108162306a36Sopenharmony_ci 108262306a36Sopenharmony_ci int [] a; 108362306a36Sopenharmony_ci 108462306a36Sopenharmony_ci 2. At the beginning of a line for slice initialisers:: 108562306a36Sopenharmony_ci 108662306a36Sopenharmony_ci [0...10] = 5, 108762306a36Sopenharmony_ci 108862306a36Sopenharmony_ci 3. Inside a curly brace:: 108962306a36Sopenharmony_ci 109062306a36Sopenharmony_ci = { [0...10] = 5 } 109162306a36Sopenharmony_ci 109262306a36Sopenharmony_ci **CONCATENATED_STRING** 109362306a36Sopenharmony_ci Concatenated elements should have a space in between. 109462306a36Sopenharmony_ci Example:: 109562306a36Sopenharmony_ci 109662306a36Sopenharmony_ci printk(KERN_INFO"bar"); 109762306a36Sopenharmony_ci 109862306a36Sopenharmony_ci should be:: 109962306a36Sopenharmony_ci 110062306a36Sopenharmony_ci printk(KERN_INFO "bar"); 110162306a36Sopenharmony_ci 110262306a36Sopenharmony_ci **ELSE_AFTER_BRACE** 110362306a36Sopenharmony_ci `else {` should follow the closing block `}` on the same line. 110462306a36Sopenharmony_ci 110562306a36Sopenharmony_ci See: https://www.kernel.org/doc/html/latest/process/coding-style.html#placing-braces-and-spaces 110662306a36Sopenharmony_ci 110762306a36Sopenharmony_ci **LINE_SPACING** 110862306a36Sopenharmony_ci Vertical space is wasted given the limited number of lines an 110962306a36Sopenharmony_ci editor window can display when multiple blank lines are used. 111062306a36Sopenharmony_ci 111162306a36Sopenharmony_ci See: https://www.kernel.org/doc/html/latest/process/coding-style.html#spaces 111262306a36Sopenharmony_ci 111362306a36Sopenharmony_ci **OPEN_BRACE** 111462306a36Sopenharmony_ci The opening brace should be following the function definitions on the 111562306a36Sopenharmony_ci next line. For any non-functional block it should be on the same line 111662306a36Sopenharmony_ci as the last construct. 111762306a36Sopenharmony_ci 111862306a36Sopenharmony_ci See: https://www.kernel.org/doc/html/latest/process/coding-style.html#placing-braces-and-spaces 111962306a36Sopenharmony_ci 112062306a36Sopenharmony_ci **POINTER_LOCATION** 112162306a36Sopenharmony_ci When using pointer data or a function that returns a pointer type, 112262306a36Sopenharmony_ci the preferred use of * is adjacent to the data name or function name 112362306a36Sopenharmony_ci and not adjacent to the type name. 112462306a36Sopenharmony_ci Examples:: 112562306a36Sopenharmony_ci 112662306a36Sopenharmony_ci char *linux_banner; 112762306a36Sopenharmony_ci unsigned long long memparse(char *ptr, char **retptr); 112862306a36Sopenharmony_ci char *match_strdup(substring_t *s); 112962306a36Sopenharmony_ci 113062306a36Sopenharmony_ci See: https://www.kernel.org/doc/html/latest/process/coding-style.html#spaces 113162306a36Sopenharmony_ci 113262306a36Sopenharmony_ci **SPACING** 113362306a36Sopenharmony_ci Whitespace style used in the kernel sources is described in kernel docs. 113462306a36Sopenharmony_ci 113562306a36Sopenharmony_ci See: https://www.kernel.org/doc/html/latest/process/coding-style.html#spaces 113662306a36Sopenharmony_ci 113762306a36Sopenharmony_ci **TRAILING_WHITESPACE** 113862306a36Sopenharmony_ci Trailing whitespace should always be removed. 113962306a36Sopenharmony_ci Some editors highlight the trailing whitespace and cause visual 114062306a36Sopenharmony_ci distractions when editing files. 114162306a36Sopenharmony_ci 114262306a36Sopenharmony_ci See: https://www.kernel.org/doc/html/latest/process/coding-style.html#spaces 114362306a36Sopenharmony_ci 114462306a36Sopenharmony_ci **UNNECESSARY_PARENTHESES** 114562306a36Sopenharmony_ci Parentheses are not required in the following cases: 114662306a36Sopenharmony_ci 114762306a36Sopenharmony_ci 1. Function pointer uses:: 114862306a36Sopenharmony_ci 114962306a36Sopenharmony_ci (foo->bar)(); 115062306a36Sopenharmony_ci 115162306a36Sopenharmony_ci could be:: 115262306a36Sopenharmony_ci 115362306a36Sopenharmony_ci foo->bar(); 115462306a36Sopenharmony_ci 115562306a36Sopenharmony_ci 2. Comparisons in if:: 115662306a36Sopenharmony_ci 115762306a36Sopenharmony_ci if ((foo->bar) && (foo->baz)) 115862306a36Sopenharmony_ci if ((foo == bar)) 115962306a36Sopenharmony_ci 116062306a36Sopenharmony_ci could be:: 116162306a36Sopenharmony_ci 116262306a36Sopenharmony_ci if (foo->bar && foo->baz) 116362306a36Sopenharmony_ci if (foo == bar) 116462306a36Sopenharmony_ci 116562306a36Sopenharmony_ci 3. addressof/dereference single Lvalues:: 116662306a36Sopenharmony_ci 116762306a36Sopenharmony_ci &(foo->bar) 116862306a36Sopenharmony_ci *(foo->bar) 116962306a36Sopenharmony_ci 117062306a36Sopenharmony_ci could be:: 117162306a36Sopenharmony_ci 117262306a36Sopenharmony_ci &foo->bar 117362306a36Sopenharmony_ci *foo->bar 117462306a36Sopenharmony_ci 117562306a36Sopenharmony_ci **WHILE_AFTER_BRACE** 117662306a36Sopenharmony_ci while should follow the closing bracket on the same line:: 117762306a36Sopenharmony_ci 117862306a36Sopenharmony_ci do { 117962306a36Sopenharmony_ci ... 118062306a36Sopenharmony_ci } while(something); 118162306a36Sopenharmony_ci 118262306a36Sopenharmony_ci See: https://www.kernel.org/doc/html/latest/process/coding-style.html#placing-braces-and-spaces 118362306a36Sopenharmony_ci 118462306a36Sopenharmony_ci 118562306a36Sopenharmony_ciOthers 118662306a36Sopenharmony_ci------ 118762306a36Sopenharmony_ci 118862306a36Sopenharmony_ci **CONFIG_DESCRIPTION** 118962306a36Sopenharmony_ci Kconfig symbols should have a help text which fully describes 119062306a36Sopenharmony_ci it. 119162306a36Sopenharmony_ci 119262306a36Sopenharmony_ci **CORRUPTED_PATCH** 119362306a36Sopenharmony_ci The patch seems to be corrupted or lines are wrapped. 119462306a36Sopenharmony_ci Please regenerate the patch file before sending it to the maintainer. 119562306a36Sopenharmony_ci 119662306a36Sopenharmony_ci **CVS_KEYWORD** 119762306a36Sopenharmony_ci Since linux moved to git, the CVS markers are no longer used. 119862306a36Sopenharmony_ci So, CVS style keywords ($Id$, $Revision$, $Log$) should not be 119962306a36Sopenharmony_ci added. 120062306a36Sopenharmony_ci 120162306a36Sopenharmony_ci **DEFAULT_NO_BREAK** 120262306a36Sopenharmony_ci switch default case is sometimes written as "default:;". This can 120362306a36Sopenharmony_ci cause new cases added below default to be defective. 120462306a36Sopenharmony_ci 120562306a36Sopenharmony_ci A "break;" should be added after empty default statement to avoid 120662306a36Sopenharmony_ci unwanted fallthrough. 120762306a36Sopenharmony_ci 120862306a36Sopenharmony_ci **DOS_LINE_ENDINGS** 120962306a36Sopenharmony_ci For DOS-formatted patches, there are extra ^M symbols at the end of 121062306a36Sopenharmony_ci the line. These should be removed. 121162306a36Sopenharmony_ci 121262306a36Sopenharmony_ci **DT_SCHEMA_BINDING_PATCH** 121362306a36Sopenharmony_ci DT bindings moved to a json-schema based format instead of 121462306a36Sopenharmony_ci freeform text. 121562306a36Sopenharmony_ci 121662306a36Sopenharmony_ci See: https://www.kernel.org/doc/html/latest/devicetree/bindings/writing-schema.html 121762306a36Sopenharmony_ci 121862306a36Sopenharmony_ci **DT_SPLIT_BINDING_PATCH** 121962306a36Sopenharmony_ci Devicetree bindings should be their own patch. This is because 122062306a36Sopenharmony_ci bindings are logically independent from a driver implementation, 122162306a36Sopenharmony_ci they have a different maintainer (even though they often 122262306a36Sopenharmony_ci are applied via the same tree), and it makes for a cleaner history in the 122362306a36Sopenharmony_ci DT only tree created with git-filter-branch. 122462306a36Sopenharmony_ci 122562306a36Sopenharmony_ci See: https://www.kernel.org/doc/html/latest/devicetree/bindings/submitting-patches.html#i-for-patch-submitters 122662306a36Sopenharmony_ci 122762306a36Sopenharmony_ci **EMBEDDED_FILENAME** 122862306a36Sopenharmony_ci Embedding the complete filename path inside the file isn't particularly 122962306a36Sopenharmony_ci useful as often the path is moved around and becomes incorrect. 123062306a36Sopenharmony_ci 123162306a36Sopenharmony_ci **FILE_PATH_CHANGES** 123262306a36Sopenharmony_ci Whenever files are added, moved, or deleted, the MAINTAINERS file 123362306a36Sopenharmony_ci patterns can be out of sync or outdated. 123462306a36Sopenharmony_ci 123562306a36Sopenharmony_ci So MAINTAINERS might need updating in these cases. 123662306a36Sopenharmony_ci 123762306a36Sopenharmony_ci **MEMSET** 123862306a36Sopenharmony_ci The memset use appears to be incorrect. This may be caused due to 123962306a36Sopenharmony_ci badly ordered parameters. Please recheck the usage. 124062306a36Sopenharmony_ci 124162306a36Sopenharmony_ci **NOT_UNIFIED_DIFF** 124262306a36Sopenharmony_ci The patch file does not appear to be in unified-diff format. Please 124362306a36Sopenharmony_ci regenerate the patch file before sending it to the maintainer. 124462306a36Sopenharmony_ci 124562306a36Sopenharmony_ci **PRINTF_0XDECIMAL** 124662306a36Sopenharmony_ci Prefixing 0x with decimal output is defective and should be corrected. 124762306a36Sopenharmony_ci 124862306a36Sopenharmony_ci **SPDX_LICENSE_TAG** 124962306a36Sopenharmony_ci The source file is missing or has an improper SPDX identifier tag. 125062306a36Sopenharmony_ci The Linux kernel requires the precise SPDX identifier in all source files, 125162306a36Sopenharmony_ci and it is thoroughly documented in the kernel docs. 125262306a36Sopenharmony_ci 125362306a36Sopenharmony_ci See: https://www.kernel.org/doc/html/latest/process/license-rules.html 125462306a36Sopenharmony_ci 125562306a36Sopenharmony_ci **TYPO_SPELLING** 125662306a36Sopenharmony_ci Some words may have been misspelled. Consider reviewing them. 1257