summaryrefslogtreecommitdiffstats
path: root/scripts/checkpatch.pl
diff options
context:
space:
mode:
authorJoe Perches2013-11-13 00:10:15 +0100
committerLinus Torvalds2013-11-13 04:09:25 +0100
commit823b794ce176bcf135a062075737be71a78629dd (patch)
tree27ee885ad9d07e3421f04e846a3507b74ffe1fa7 /scripts/checkpatch.pl
parentcheckpatch: don't require kernel style __attribute__ shortcuts in uapi paths (diff)
downloadkernel-qcow2-linux-823b794ce176bcf135a062075737be71a78629dd.tar.gz
kernel-qcow2-linux-823b794ce176bcf135a062075737be71a78629dd.tar.xz
kernel-qcow2-linux-823b794ce176bcf135a062075737be71a78629dd.zip
checkpatch: add check for sscanf without return use
Naked use sscanf can be troublesome because the pointed to variables may not have been set. Add a warning when the sscanf return value is not used. For now, do not add __must_check to the sscanf prototype because that will cause a couple of hundred new warnings when compiling a kernel. Signed-off-by: Joe Perches <joe@perches.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'scripts/checkpatch.pl')
-rwxr-xr-xscripts/checkpatch.pl17
1 files changed, 17 insertions, 0 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 1eb5d2fa8d20..61090e0ff613 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -4019,6 +4019,23 @@ sub process {
}
}
+# check for naked sscanf
+ if ($^V && $^V ge 5.10.0 &&
+ defined $stat &&
+ $stat =~ /\bsscanf\b/ &&
+ ($stat !~ /$Ident\s*=\s*sscanf\s*$balanced_parens/ &&
+ $stat !~ /\bsscanf\s*$balanced_parens\s*(?:$Compare)/ &&
+ $stat !~ /(?:$Compare)\s*\bsscanf\s*$balanced_parens/)) {
+ my $lc = $stat =~ tr@\n@@;
+ $lc = $lc + $linenr;
+ my $stat_real = raw_line($linenr, 0);
+ for (my $count = $linenr + 1; $count <= $lc; $count++) {
+ $stat_real = $stat_real . "\n" . raw_line($count, 0);
+ }
+ WARN("NAKED_SSCANF",
+ "unchecked sscanf return value\n" . "$here\n$stat_real\n");
+ }
+
# check for new externs in .h files.
if ($realfile =~ /\.h$/ &&
$line =~ /^\+\s*(extern\s+)$Type\s*$Ident\s*\(/s) {