From: Joe Perches Date: Wed, 4 Jun 2014 23:12:08 +0000 (-0700) Subject: checkpatch: prefer kstrto to sscanf(buf, "%", &bar); X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=afc819ab0293be3bd5c16d9eba26f9d57f61c42a;p=GitHub%2FLineageOS%2Fandroid_kernel_motorola_exynos9610.git checkpatch: prefer kstrto to sscanf(buf, "%", &bar); Use the kstrto functions in preference to sscanf. Signed-off-by: Joe Perches Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 77740252bbed..862cc7a740e2 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -4314,6 +4314,27 @@ sub process { "unchecked sscanf return value\n" . "$here\n$stat_real\n"); } +# check for simple sscanf that should be kstrto + if ($^V && $^V ge 5.10.0 && + defined $stat && + $line =~ /\bsscanf\b/) { + 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); + } + if ($stat_real =~ /\bsscanf\b\s*\(\s*$FuncArg\s*,\s*("[^"]+")/) { + my $format = $6; + my $count = $format =~ tr@%@%@; + if ($count == 1 && + $format =~ /^"\%(?i:ll[udxi]|[udxi]ll|ll|[hl]h?[udxi]|[udxi][hl]h?|[hl]h?|[udxi])"$/) { + WARN("SSCANF_TO_KSTRTO", + "Prefer kstrto to single variable sscanf\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) {