提交 afc819ab 编写于 作者: J Joe Perches 提交者: Linus Torvalds

checkpatch: prefer kstrto<foo> to sscanf(buf, "%<lhuidx>", &bar);

Use the kstrto<foo> functions in preference to sscanf.
Signed-off-by: NJoe Perches <joe@perches.com>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 60a55369
...@@ -4314,6 +4314,27 @@ sub process { ...@@ -4314,6 +4314,27 @@ sub process {
"unchecked sscanf return value\n" . "$here\n$stat_real\n"); "unchecked sscanf return value\n" . "$here\n$stat_real\n");
} }
# check for simple sscanf that should be kstrto<foo>
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<type> to single variable sscanf\n" . "$here\n$stat_real\n");
}
}
}
# check for new externs in .h files. # check for new externs in .h files.
if ($realfile =~ /\.h$/ && if ($realfile =~ /\.h$/ &&
$line =~ /^\+\s*(extern\s+)$Type\s*$Ident\s*\(/s) { $line =~ /^\+\s*(extern\s+)$Type\s*$Ident\s*\(/s) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册