Skip to content

Commit d0565de

Browse files
committed
btrfs-progs: docs: update kernel coding style
[ci skip] Signed-off-by: David Sterba <dsterba@suse.com>
1 parent ac1938f commit d0565de

File tree

1 file changed

+33
-9
lines changed

1 file changed

+33
-9
lines changed

Documentation/dev/Development-notes.rst

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@ attention to detail. Once written the code could stay unchanged for years but
224224
will be read many times. `Read more
225225
<https://simpleprogrammer.com/maintaining-code/>`__.
226226

227+
General advice: *Try to keep the same style and formatting of the code that's
228+
already there.*
229+
227230
Patches
228231
^^^^^^^
229232

@@ -277,6 +280,8 @@ Headers
277280
^^^^^^^
278281

279282
- leave one newline before #endif in headers
283+
- include headers that add usage of a data structure or API, also remove such
284+
header with last use of the API
280285

281286
Comments
282287
^^^^^^^^
@@ -330,6 +335,9 @@ Misc
330335
- fix spelling, grammar and formatting of comments that get moved or changed
331336
- fix coding style in code that's only moved
332337
- one newline between functions
338+
- 80 chars per line are recommended but longer lines are OK (up to 90) if the
339+
code "looks better" without the line break, e.g. if half of the word is beyond 80 chars
340+
but it's clear what it is, or function prototypes do not need to wrap arguments
333341

334342
Locking
335343
^^^^^^^
@@ -346,8 +354,20 @@ Code
346354
- default function return value is *int ret*, temporary return values should
347355
be named like *ret2* etc
348356
- structure initializers should use *{ 0 }*
349-
- do not use *short* type if possible, if it fits to char/u8 use it instead,
350-
or plain int
357+
- do not use *short int* type if possible, if it fits to char/u8 use it instead,
358+
or plain int/u32
359+
- memory barriers need to be always documented
360+
- add *const* to parameters that are not modified
361+
- use bool for indicators and bool status variables (not int)
362+
- use matching int types (size, signedness), with exceptions
363+
- use ENUM_BIT for enumerated bit values (that don't have assigned fixed numbers)
364+
- add function annotations __cold, __init, __attribute_const__ if applicable
365+
- use automatic variable cleanup for:
366+
- *struct btrfs_path* with BTRFS_PATH_AUTO_FREE
367+
- use of ``unlikely()`` annotation is OK and recommended for the following cases:
368+
369+
- control flow of the function is changed due to error handling and it
370+
leads to *never-happens* errors like EUCLEAN, EIO
351371

352372
Output
353373
^^^^^^
@@ -368,7 +388,8 @@ Expressions, operators
368388
- *a \* b + c*, *(a << b) + c*, *(a % b) + c*
369389

370390
- 64bit division is not allowed, either avoid it completely, or use bit
371-
shifts or use div_u64 helpers
391+
shifts or use div_u64 helpers; do not use *do_div* for division as it's a
392+
macro and has side effects
372393
- do not use chained assignments: no *a = b = c;*
373394

374395
Variable declarations, parameters
@@ -380,6 +401,8 @@ Variable declarations, parameters
380401
- use *const* extensively
381402
- add temporary variable to store a value if it's used multiple times in the
382403
function, or if reading the value needs to chase a long pointer chain
404+
- do not mix declarations and statements (although kernel uses C standard that
405+
allos that)
383406

384407
Kernel config options
385408
---------------------
@@ -449,9 +472,9 @@ Please refer to the option documentation for further details.
449472
BUG: MAX_LOCKDEP_CHAIN_HLOCKS too low!
450473
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
451474

452-
Not a bug. The lockdep structures can get in some cases full and cannot
453-
properly track locks anymore. There's only a workaround to increase the kernel
454-
config value of CONFIG_LOCKDEP_CHAINS_BITS, default is
475+
Not a bug and please don't report it. The lockdep structures can get in some
476+
cases full and cannot properly track locks anymore. There's only a workaround
477+
to increase the kernel config value of CONFIG_LOCKDEP_CHAINS_BITS, default is
455478
16, 18 tends to work, increase if needed.
456479

457480
fstests setup
@@ -520,10 +543,11 @@ Note: This list may be incomplete.
520543
Storage environment
521544
^^^^^^^^^^^^^^^^^^^
522545

523-
- At least 4 identically sized partitions/disks/virtual disks, specified using
524-
``$SCRATCH_DEV_POOL``, some tests may require 8 such partitions
546+
- at least 4 identically sized partitions/disks/virtual disks, specified using
547+
``$SCRATCH_DEV_POOL``
548+
- some tests may require 8 equally sized``SCRATCH_DEV_POOL`` partitions
525549
- some tests need at least 10G of free space, as determined by ``df``, i.e.
526-
the size of the device may need to be larger
550+
the size of the device may need to be larger, 12G should work
527551
- some tests require ``$LOGWRITES_DEV``, yet another separate block device,
528552
for power fail testing
529553
- for testing trim and discard, the devices must be capable of that (physical

0 commit comments

Comments
 (0)