Kernel style prefers "unsigned int <foo>" over "unsigned <foo>" and "signed int <foo>" over "signed <foo>". Emit a warning for these simple signed/unsigned <foo> declarations. Fix it too if desired.
Showing the changes to scripts/checkpatch.pl (1 of 1 file). Show all
Unified · Split
| @@ -3239,6 +3239,26 @@ sub process { · 3238 unmodified lines | ||
| 3239 | 3239 | #ignore lines not being added |
| 3240 | 3240 | next if ($line =~ /^[^\+]/); |
| 3241 | 3241 | |
| 3242 | +# check for declarations of signed or unsigned without int | |
| 3243 | + while ($line =~ m{($Declare++)\s*($Ident)\s*[=,;\[\)]}g) { | |
| 3244 | + my $type = $1; | |
| 3245 | + my $var = $2; | |
| 3246 | + if ($type =~ /^((?:un)?signed)((?:\s*\*)*)\s*$/) { | |
| 3247 | + my $sign = $1; | |
| 3248 | + my $pointer = $2; | |
| 3249 | + | |
| 3250 | + $pointer = "" if (!defined $pointer); | |
| 3251 | + | |
| 3252 | + if (WARN("UNSPECIFIED_INT", | |
| 3253 | + "Prefer '" . trim($sign) . " int" . rtrim($pointer) . "' to bare use of '$sign" . rtrim($pointer) . "'\n" . $herecurr) && | |
| 3254 | + $fix) { | |
| 3255 | + my $decl = trim($sign) . " int "; | |
| 3256 | + $decl .= trim($pointer) if (rtrim($pointer) ne ""); | |
| 3257 | + $fixed[$fixlinenr] =~ s@\b\Q$type\E\s*$var\b@$decl$var@; | |
| 3258 | + } | |
| 3259 | + } | |
| 3260 | + } | |
| 3261 | + | |
| 3242 | 3262 | # TEST: allow direct testing of the type matcher. |
| 3243 | 3263 | if ($dbg_type) { |
| 3244 | 3264 | if ($line =~ /^.\s*$Declare\s*$/) { |