History

checkpatch: warn on unnecessary int declarations

On Sun, 2018-08-05 at 08:52 -0700, Linus Torvalds wrote: > "long unsigned int" isn't _technically_ wrong. But we normally > call that type "unsigned long". So add a checkpatch test for it.

Joe Perches committed 8 years ago

Commit 809e0821 parent 6ad724e1 file · +20 −0Browse files

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

Unified · Split

scripts/checkpatch.pl+20−0
@@ -3829,6 +3829,26 @@ sub process { · 3828 unmodified lines
3829 "type '$tmp' should be specified in [[un]signed] [short|int|long|long long] order\n" . $herecurr);3829 "type '$tmp' should be specified in [[un]signed] [short|int|long|long long] order\n" . $herecurr);
3830 }3830 }
3831 3831
3832# check for unnecessary <signed> int declarations of short/long/long long
3833 while ($sline =~ m{\b($TypeMisordered(\s*\*)*|$C90_int_types)\b}g) {
3834 my $type = trim($1);
3835 next if ($type !~ /\bint\b/);
3836 next if ($type !~ /\b(?:short|long\s+long|long)\b/);
3837 my $new_type = $type;
3838 $new_type =~ s/\b\s*int\s*\b/ /;
3839 $new_type =~ s/\b\s*(?:un)?signed\b\s*/ /;
3840 $new_type =~ s/^const\s+//;
3841 $new_type = "unsigned $new_type" if ($type =~ /\bunsigned\b/);
3842 $new_type = "const $new_type" if ($type =~ /^const\b/);
3843 $new_type =~ s/\s+/ /g;
3844 $new_type = trim($new_type);
3845 if (WARN("UNNECESSARY_INT",
3846 "Prefer '$new_type' over '$type' as the int is unnecessary\n" . $herecurr) &&
3847 $fix) {
3848 $fixed[$fixlinenr] =~ s/\b\Q$type\E\b/$new_type/;
3849 }
3850 }
3851
3832# check for static const char * arrays.3852# check for static const char * arrays.
3833 if ($line =~ /\bstatic\s+const\s+char\s*\*\s*(\w+)\s*\[\s*\]\s*=\s*/) {3853 if ($line =~ /\bstatic\s+const\s+char\s*\*\s*(\w+)\s*\[\s*\]\s*=\s*/) {
3834 WARN("STATIC_CONST_CHAR_ARRAY",3854 WARN("STATIC_CONST_CHAR_ARRAY",