History

checkpatch: warn on bare unsigned or signed declarations without int

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.

Joe Perches committed 10 years ago

Commit a1ce18e1 parent 42e15291 file · +20 −0Browse files

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

Unified · Split

scripts/checkpatch.pl+20−0
@@ -3239,6 +3239,26 @@ sub process { · 3238 unmodified lines
32393239 #ignore lines not being added
32403240 next if ($line =~ /^[^\+]/);
32413241
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+
32423262 # TEST: allow direct testing of the type matcher.
32433263 if ($dbg_type) {
32443264 if ($line =~ /^.\s*$Declare\s*$/) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t