diff options
author | Joe Perches <joe@perches.com> | 2015-06-25 18:02:49 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-06-25 20:00:41 -0400 |
commit | e6176fa4728fb6df4f66c3e9c08736c369e71f75 (patch) | |
tree | 97f9337a285c00467e8204c3958d9dc5bf26e37e /scripts/checkpatch.pl | |
parent | cb426e99ff9225e94fb56bd4c5cfcce8b78a3904 (diff) |
checkpatch: add --strict warning for c99 fixed size typedefs : int<size>_t
Using declarations like u_int16_t in kernel code is not preferred.
Suggest the kernel sized types instead of the c99 types when not in the
uapi directory.
Add a $typeC99Typedefs variable for the types to check and neaten the
other typedef variables.
Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'scripts/checkpatch.pl')
-rwxr-xr-x | scripts/checkpatch.pl | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 3f2ff26c631c..f7f222a1e908 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
@@ -347,15 +347,20 @@ our $UTF8 = qr{ | |||
347 | | $NON_ASCII_UTF8 | 347 | | $NON_ASCII_UTF8 |
348 | }x; | 348 | }x; |
349 | 349 | ||
350 | our $typeC99Typedefs = qr{(?:__)?(?:[us]_?)?int_?(?:8|16|32|64)_t}; | ||
350 | our $typeOtherOSTypedefs = qr{(?x: | 351 | our $typeOtherOSTypedefs = qr{(?x: |
351 | u_(?:char|short|int|long) | # bsd | 352 | u_(?:char|short|int|long) | # bsd |
352 | u(?:nchar|short|int|long) # sysv | 353 | u(?:nchar|short|int|long) # sysv |
353 | )}; | 354 | )}; |
354 | 355 | our $typeKernelTypedefs = qr{(?x: | |
355 | our $typeTypedefs = qr{(?x: | ||
356 | (?:__)?(?:u|s|be|le)(?:8|16|32|64)| | 356 | (?:__)?(?:u|s|be|le)(?:8|16|32|64)| |
357 | atomic_t | 357 | atomic_t |
358 | )}; | 358 | )}; |
359 | our $typeTypedefs = qr{(?x: | ||
360 | $typeC99Typedefs\b| | ||
361 | $typeOtherOSTypedefs\b| | ||
362 | $typeKernelTypedefs\b | ||
363 | )}; | ||
359 | 364 | ||
360 | our $logFunctions = qr{(?x: | 365 | our $logFunctions = qr{(?x: |
361 | printk(?:_ratelimited|_once|)| | 366 | printk(?:_ratelimited|_once|)| |
@@ -516,7 +521,6 @@ sub build_types { | |||
516 | my $allWithAttr = "(?x: \n" . join("|\n ", @typeListWithAttr) . "\n)"; | 521 | my $allWithAttr = "(?x: \n" . join("|\n ", @typeListWithAttr) . "\n)"; |
517 | $Modifier = qr{(?:$Attribute|$Sparse|$mods)}; | 522 | $Modifier = qr{(?:$Attribute|$Sparse|$mods)}; |
518 | $BasicType = qr{ | 523 | $BasicType = qr{ |
519 | (?:$typeOtherOSTypedefs\b)| | ||
520 | (?:$typeTypedefs\b)| | 524 | (?:$typeTypedefs\b)| |
521 | (?:${all}\b) | 525 | (?:${all}\b) |
522 | }x; | 526 | }x; |
@@ -524,7 +528,6 @@ sub build_types { | |||
524 | (?:$Modifier\s+|const\s+)* | 528 | (?:$Modifier\s+|const\s+)* |
525 | (?: | 529 | (?: |
526 | (?:typeof|__typeof__)\s*\([^\)]*\)| | 530 | (?:typeof|__typeof__)\s*\([^\)]*\)| |
527 | (?:$typeOtherOSTypedefs\b)| | ||
528 | (?:$typeTypedefs\b)| | 531 | (?:$typeTypedefs\b)| |
529 | (?:${all}\b) | 532 | (?:${all}\b) |
530 | ) | 533 | ) |
@@ -542,7 +545,6 @@ sub build_types { | |||
542 | (?: | 545 | (?: |
543 | (?:typeof|__typeof__)\s*\([^\)]*\)| | 546 | (?:typeof|__typeof__)\s*\([^\)]*\)| |
544 | (?:$typeTypedefs\b)| | 547 | (?:$typeTypedefs\b)| |
545 | (?:$typeOtherOSTypedefs\b)| | ||
546 | (?:${allWithAttr}\b) | 548 | (?:${allWithAttr}\b) |
547 | ) | 549 | ) |
548 | (?:\s+$Modifier|\s+const)* | 550 | (?:\s+$Modifier|\s+const)* |
@@ -3264,7 +3266,6 @@ sub process { | |||
3264 | $line !~ /\btypedef\s+$Type\s*\(\s*\*?$Ident\s*\)\s*\(/ && | 3266 | $line !~ /\btypedef\s+$Type\s*\(\s*\*?$Ident\s*\)\s*\(/ && |
3265 | $line !~ /\btypedef\s+$Type\s+$Ident\s*\(/ && | 3267 | $line !~ /\btypedef\s+$Type\s+$Ident\s*\(/ && |
3266 | $line !~ /\b$typeTypedefs\b/ && | 3268 | $line !~ /\b$typeTypedefs\b/ && |
3267 | $line !~ /\b$typeOtherOSTypedefs\b/ && | ||
3268 | $line !~ /\b__bitwise(?:__|)\b/) { | 3269 | $line !~ /\b__bitwise(?:__|)\b/) { |
3269 | WARN("NEW_TYPEDEFS", | 3270 | WARN("NEW_TYPEDEFS", |
3270 | "do not add new typedefs\n" . $herecurr); | 3271 | "do not add new typedefs\n" . $herecurr); |
@@ -4980,6 +4981,24 @@ sub process { | |||
4980 | "Using weak declarations can have unintended link defects\n" . $herecurr); | 4981 | "Using weak declarations can have unintended link defects\n" . $herecurr); |
4981 | } | 4982 | } |
4982 | 4983 | ||
4984 | # check for c99 types like uint8_t used outside of uapi/ | ||
4985 | if ($realfile !~ m@\binclude/uapi/@ && | ||
4986 | $line =~ /\b($Declare)\s*$Ident\s*[=;,\[]/) { | ||
4987 | my $type = $1; | ||
4988 | if ($type =~ /\b($typeC99Typedefs)\b/) { | ||
4989 | $type = $1; | ||
4990 | my $kernel_type = 'u'; | ||
4991 | $kernel_type = 's' if ($type =~ /^_*[si]/); | ||
4992 | $type =~ /(\d+)/; | ||
4993 | $kernel_type .= $1; | ||
4994 | if (CHK("PREFER_KERNEL_TYPES", | ||
4995 | "Prefer kernel type '$kernel_type' over '$type'\n" . $herecurr) && | ||
4996 | $fix) { | ||
4997 | $fixed[$fixlinenr] =~ s/\b$type\b/$kernel_type/; | ||
4998 | } | ||
4999 | } | ||
5000 | } | ||
5001 | |||
4983 | # check for sizeof(&) | 5002 | # check for sizeof(&) |
4984 | if ($line =~ /\bsizeof\s*\(\s*\&/) { | 5003 | if ($line =~ /\bsizeof\s*\(\s*\&/) { |
4985 | WARN("SIZEOF_ADDRESS", | 5004 | WARN("SIZEOF_ADDRESS", |