Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1350804 > unrolled thread

[PATCH] checkpatch: Warn on bare unsigned or signed declarations without int

Started byJoe Perches <joe@perches.com>
First post2016-03-05 06:30 +0100
Last post2016-03-05 17:20 +0100
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] checkpatch: Warn on bare unsigned or signed declarations without int Joe Perches <joe@perches.com> - 2016-03-05 06:30 +0100
    Re: [PATCH] checkpatch: Warn on bare unsigned or signed  declarations without int David Miller <davem@davemloft.net> - 2016-03-05 17:20 +0100

#1350804 — [PATCH] checkpatch: Warn on bare unsigned or signed declarations without int

FromJoe Perches <joe@perches.com>
Date2016-03-05 06:30 +0100
Subject[PATCH] checkpatch: Warn on bare unsigned or signed declarations without int
Message-ID<r9cWR-1q5-1@gated-at.bofh.it>
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: Joe Perches <joe@perches.com>
---
 scripts/checkpatch.pl | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 874132b..c48b658 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3240,6 +3240,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*$/) {
-- 
2.6.3.368.gf34be46

[toc] | [next] | [standalone]


#1350929 — Re: [PATCH] checkpatch: Warn on bare unsigned or signed declarations without int

FromDavid Miller <davem@davemloft.net>
Date2016-03-05 17:20 +0100
SubjectRe: [PATCH] checkpatch: Warn on bare unsigned or signed declarations without int
Message-ID<r9n5T-fd-1@gated-at.bofh.it>
In reply to#1350804
From: Joe Perches <joe@perches.com>
Date: Fri,  4 Mar 2016 21:23:44 -0800

> 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: Joe Perches <joe@perches.com>

Acked-by: David S. Miller <davem@davemloft.net>

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web