From: Joe Perches Date: Tue, 15 Mar 2016 21:58:03 +0000 (-0700) Subject: checkpatch: warn on bare unsigned or signed declarations without int X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=a1ce18e4f941d20;p=linux-beck.git checkpatch: warn on bare unsigned or signed declarations without int Kernel style prefers "unsigned int " over "unsigned " and "signed int " over "signed ". Emit a warning for these simple signed/unsigned declarations. Fix it too if desired. Signed-off-by: Joe Perches Acked-by: David S. Miller Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 5c00c1c02dab..4b314bd15a0d 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -3239,6 +3239,26 @@ sub process { #ignore lines not being added next if ($line =~ /^[^\+]/); +# check for declarations of signed or unsigned without int + while ($line =~ m{($Declare++)\s*($Ident)\s*[=,;\[\)]}g) { + my $type = $1; + my $var = $2; + if ($type =~ /^((?:un)?signed)((?:\s*\*)*)\s*$/) { + my $sign = $1; + my $pointer = $2; + + $pointer = "" if (!defined $pointer); + + if (WARN("UNSPECIFIED_INT", + "Prefer '" . trim($sign) . " int" . rtrim($pointer) . "' to bare use of '$sign" . rtrim($pointer) . "'\n" . $herecurr) && + $fix) { + my $decl = trim($sign) . " int "; + $decl .= trim($pointer) if (rtrim($pointer) ne ""); + $fixed[$fixlinenr] =~ s@\b\Q$type\E\s*$var\b@$decl$var@; + } + } + } + # TEST: allow direct testing of the type matcher. if ($dbg_type) { if ($line =~ /^.\s*$Declare\s*$/) {