Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a1ce18e4 authored by Joe Perches's avatar Joe Perches Committed by Linus Torvalds
Browse files

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.

Signed-off-by: default avatarJoe Perches <joe@perches.com>
Acked-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 42e15293
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -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*$/) {