History

checkpatch: add a --strict test for structs with bool member definitions

A struct with a bool member can have different sizes on various architectures because neither bool size nor alignment is standardized. So emit a message on the use of bool in structs only in .h files and not .c files. There is the real possibility that this test could have a false positive when a bool is declared as an automatic, so limit the test to .h files where the only false positive is for declarations in static inline functions.

Joe Perches committed 8 years ago

Commit d7295931 parent de9df391 file · +7 −0Browse files

Showing the changes to scripts/checkpatch.pl (1 of 1 file). Show all

Unified · Split

scripts/checkpatch.pl+7−0
@@ -6251,6 +6251,13 @@ sub process { · 6250 unmodified lines
62516251 "Avoid using bool as bitfield. Prefer bool bitfields as unsigned int or u<8|16|32>\n" . $herecurr);
62526252 }
62536253
6254+# check for bool use in .h files
6255+ if ($realfile =~ /\.h$/ &&
6256+ $sline =~ /^.\s+bool\s*$Ident\s*(?::\s*d+\s*)?;/) {
6257+ CHK("BOOL_MEMBER",
6258+ "Avoid using bool structure members because of possible alignment issues - see: https://lkml.org/lkml/2017/11/21/384\n" . $herecurr);
6259+ }
6260+
62546261 # check for semaphores initialized locked
62556262 if ($line =~ /^.\s*sema_init.+,\W?0\W?\)/) {
62566263 WARN("CONSIDER_COMPLETION",