aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xscripts/checkpatch.pl44
1 files changed, 44 insertions, 0 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index c10befa118a5..10384cf40691 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -309,9 +309,12 @@ our $Operators = qr{
309our $c90_Keywords = qr{do|for|while|if|else|return|goto|continue|switch|default|case|break}x; 309our $c90_Keywords = qr{do|for|while|if|else|return|goto|continue|switch|default|case|break}x;
310 310
311our $NonptrType; 311our $NonptrType;
312our $NonptrTypeMisordered;
312our $NonptrTypeWithAttr; 313our $NonptrTypeWithAttr;
313our $Type; 314our $Type;
315our $TypeMisordered;
314our $Declare; 316our $Declare;
317our $DeclareMisordered;
315 318
316our $NON_ASCII_UTF8 = qr{ 319our $NON_ASCII_UTF8 = qr{
317 [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte 320 [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
@@ -353,6 +356,25 @@ our $signature_tags = qr{(?xi:
353 Cc: 356 Cc:
354)}; 357)};
355 358
359our @typeListMisordered = (
360 qr{char\s+(?:un)?signed},
361 qr{int\s+(?:(?:un)?signed\s+)?short\s},
362 qr{int\s+short(?:\s+(?:un)?signed)},
363 qr{short\s+int(?:\s+(?:un)?signed)},
364 qr{(?:un)?signed\s+int\s+short},
365 qr{short\s+(?:un)?signed},
366 qr{long\s+int\s+(?:un)?signed},
367 qr{int\s+long\s+(?:un)?signed},
368 qr{long\s+(?:un)?signed\s+int},
369 qr{int\s+(?:un)?signed\s+long},
370 qr{int\s+(?:un)?signed},
371 qr{int\s+long\s+long\s+(?:un)?signed},
372 qr{long\s+long\s+int\s+(?:un)?signed},
373 qr{long\s+long\s+(?:un)?signed\s+int},
374 qr{long\s+long\s+(?:un)?signed},
375 qr{long\s+(?:un)?signed},
376);
377
356our @typeList = ( 378our @typeList = (
357 qr{void}, 379 qr{void},
358 qr{(?:(?:un)?signed\s+)?char}, 380 qr{(?:(?:un)?signed\s+)?char},
@@ -373,6 +395,7 @@ our @typeList = (
373 qr{${Ident}_t}, 395 qr{${Ident}_t},
374 qr{${Ident}_handler}, 396 qr{${Ident}_handler},
375 qr{${Ident}_handler_fn}, 397 qr{${Ident}_handler_fn},
398 @typeListMisordered,
376); 399);
377our @typeListWithAttr = ( 400our @typeListWithAttr = (
378 @typeList, 401 @typeList,
@@ -414,6 +437,7 @@ our $allowed_asm_includes = qr{(?x:
414sub build_types { 437sub build_types {
415 my $mods = "(?x: \n" . join("|\n ", @modifierList) . "\n)"; 438 my $mods = "(?x: \n" . join("|\n ", @modifierList) . "\n)";
416 my $all = "(?x: \n" . join("|\n ", @typeList) . "\n)"; 439 my $all = "(?x: \n" . join("|\n ", @typeList) . "\n)";
440 my $Misordered = "(?x: \n" . join("|\n ", @typeListMisordered) . "\n)";
417 my $allWithAttr = "(?x: \n" . join("|\n ", @typeListWithAttr) . "\n)"; 441 my $allWithAttr = "(?x: \n" . join("|\n ", @typeListWithAttr) . "\n)";
418 $Modifier = qr{(?:$Attribute|$Sparse|$mods)}; 442 $Modifier = qr{(?:$Attribute|$Sparse|$mods)};
419 $NonptrType = qr{ 443 $NonptrType = qr{
@@ -425,6 +449,13 @@ sub build_types {
425 ) 449 )
426 (?:\s+$Modifier|\s+const)* 450 (?:\s+$Modifier|\s+const)*
427 }x; 451 }x;
452 $NonptrTypeMisordered = qr{
453 (?:$Modifier\s+|const\s+)*
454 (?:
455 (?:${Misordered}\b)
456 )
457 (?:\s+$Modifier|\s+const)*
458 }x;
428 $NonptrTypeWithAttr = qr{ 459 $NonptrTypeWithAttr = qr{
429 (?:$Modifier\s+|const\s+)* 460 (?:$Modifier\s+|const\s+)*
430 (?: 461 (?:
@@ -439,7 +470,13 @@ sub build_types {
439 (?:(?:\s|\*|\[\])+\s*const|(?:\s|\*\s*(?:const\s*)?|\[\])+|(?:\s*\[\s*\])+)? 470 (?:(?:\s|\*|\[\])+\s*const|(?:\s|\*\s*(?:const\s*)?|\[\])+|(?:\s*\[\s*\])+)?
440 (?:\s+$Inline|\s+$Modifier)* 471 (?:\s+$Inline|\s+$Modifier)*
441 }x; 472 }x;
473 $TypeMisordered = qr{
474 $NonptrTypeMisordered
475 (?:(?:\s|\*|\[\])+\s*const|(?:\s|\*\s*(?:const\s*)?|\[\])+|(?:\s*\[\s*\])+)?
476 (?:\s+$Inline|\s+$Modifier)*
477 }x;
442 $Declare = qr{(?:$Storage\s+(?:$Inline\s+)?)?$Type}; 478 $Declare = qr{(?:$Storage\s+(?:$Inline\s+)?)?$Type};
479 $DeclareMisordered = qr{(?:$Storage\s+(?:$Inline\s+)?)?$TypeMisordered};
443} 480}
444build_types(); 481build_types();
445 482
@@ -2987,6 +3024,13 @@ sub process {
2987 } 3024 }
2988 } 3025 }
2989 3026
3027# check for misordered declarations of char/short/int/long with signed/unsigned
3028 while ($sline =~ m{(\b$TypeMisordered\b)}g) {
3029 my $tmp = trim($1);
3030 WARN("MISORDERED_TYPE",
3031 "type '$tmp' should be specified in [[un]signed] [short|int|long|long long] order\n" . $herecurr);
3032 }
3033
2990# check for static const char * arrays. 3034# check for static const char * arrays.
2991 if ($line =~ /\bstatic\s+const\s+char\s*\*\s*(\w+)\s*\[\s*\]\s*=\s*/) { 3035 if ($line =~ /\bstatic\s+const\s+char\s*\*\s*(\w+)\s*\[\s*\]\s*=\s*/) {
2992 WARN("STATIC_CONST_CHAR_ARRAY", 3036 WARN("STATIC_CONST_CHAR_ARRAY",