checkpatch: check for common memset parameter issues against statments
Move the memset checks over to work against the statement. Also add checks for 0 and 1 used as lengths. Generally these indicate badly ordered parameters. Signed-off-by: Andy Whitcroft <apw@canonical.com> Cc: Joe Perches <joe@perches.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
f74bd1942e
commit
554e165cf3
|
@ -3120,6 +3120,28 @@ sub process {
|
||||||
"Avoid line continuations in quoted strings\n" . $herecurr);
|
"Avoid line continuations in quoted strings\n" . $herecurr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Check for misused memsets
|
||||||
|
if (defined $stat && $stat =~ /\bmemset\s*\((.*)\)/s) {
|
||||||
|
my $args = $1;
|
||||||
|
|
||||||
|
# Flatten any parentheses and braces
|
||||||
|
while ($args =~ s/\([^\(\)]*\)/10/s ||
|
||||||
|
$args =~ s/\{[^\{\}]*\}/10/s ||
|
||||||
|
$args =~ s/\[[^\[\]]*\]/10/s)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
# Extract the simplified arguments.
|
||||||
|
my ($ms_addr, $ms_val, $ms_size) =
|
||||||
|
split(/\s*,\s*/, $args);
|
||||||
|
if ($ms_size =~ /^(0x|)0$/i) {
|
||||||
|
ERROR("MEMSET",
|
||||||
|
"memset size is 3rd argument, not the second.\n" . $herecurr);
|
||||||
|
} elsif ($ms_size =~ /^(0x|)1$/i) {
|
||||||
|
WARN("MEMSET",
|
||||||
|
"single byte memset is suspicious. Swapped 2nd/3rd argument?\n" . $herecurr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# check for new externs in .c files.
|
# check for new externs in .c files.
|
||||||
if ($realfile =~ /\.c$/ && defined $stat &&
|
if ($realfile =~ /\.c$/ && defined $stat &&
|
||||||
$stat =~ /^.\s*(?:extern\s+)?$Type\s+($Ident)(\s*)\(/s)
|
$stat =~ /^.\s*(?:extern\s+)?$Type\s+($Ident)(\s*)\(/s)
|
||||||
|
@ -3291,12 +3313,6 @@ sub process {
|
||||||
WARN("EXPORTED_WORLD_WRITABLE",
|
WARN("EXPORTED_WORLD_WRITABLE",
|
||||||
"Exporting world writable files is usually an error. Consider more restrictive permissions.\n" . $herecurr);
|
"Exporting world writable files is usually an error. Consider more restrictive permissions.\n" . $herecurr);
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check for memset with swapped arguments
|
|
||||||
if ($line =~ /memset.*\,(\ |)(0x|)0(\ |0|)\);/) {
|
|
||||||
ERROR("MEMSET",
|
|
||||||
"memset size is 3rd argument, not the second.\n" . $herecurr);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# If we have no input at all, then there is nothing to report on
|
# If we have no input at all, then there is nothing to report on
|
||||||
|
|
Loading…
Reference in New Issue