aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorAndy Whitcroft <apw@canonical.com>2012-01-10 18:09:57 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2012-01-10 19:30:50 -0500
commit554e165cf32610ec9596a183fa1b54a5707fc3cb (patch)
tree027354f186b71c033929a5ecf8df80f131c9ce7b /scripts
parentf74bd1942e04a0cedd1e9c8b331141e75add49c0 (diff)
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>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/checkpatch.pl28
1 files changed, 22 insertions, 6 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 06e22caa5692..8199d59d0ad7 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3120,6 +3120,28 @@ sub process {
3120 "Avoid line continuations in quoted strings\n" . $herecurr); 3120 "Avoid line continuations in quoted strings\n" . $herecurr);
3121 } 3121 }
3122 3122
3123# Check for misused memsets
3124 if (defined $stat && $stat =~ /\bmemset\s*\((.*)\)/s) {
3125 my $args = $1;
3126
3127 # Flatten any parentheses and braces
3128 while ($args =~ s/\([^\(\)]*\)/10/s ||
3129 $args =~ s/\{[^\{\}]*\}/10/s ||
3130 $args =~ s/\[[^\[\]]*\]/10/s)
3131 {
3132 }
3133 # Extract the simplified arguments.
3134 my ($ms_addr, $ms_val, $ms_size) =
3135 split(/\s*,\s*/, $args);
3136 if ($ms_size =~ /^(0x|)0$/i) {
3137 ERROR("MEMSET",
3138 "memset size is 3rd argument, not the second.\n" . $herecurr);
3139 } elsif ($ms_size =~ /^(0x|)1$/i) {
3140 WARN("MEMSET",
3141 "single byte memset is suspicious. Swapped 2nd/3rd argument?\n" . $herecurr);
3142 }
3143 }
3144
3123# check for new externs in .c files. 3145# check for new externs in .c files.
3124 if ($realfile =~ /\.c$/ && defined $stat && 3146 if ($realfile =~ /\.c$/ && defined $stat &&
3125 $stat =~ /^.\s*(?:extern\s+)?$Type\s+($Ident)(\s*)\(/s) 3147 $stat =~ /^.\s*(?:extern\s+)?$Type\s+($Ident)(\s*)\(/s)
@@ -3291,12 +3313,6 @@ sub process {
3291 WARN("EXPORTED_WORLD_WRITABLE", 3313 WARN("EXPORTED_WORLD_WRITABLE",
3292 "Exporting world writable files is usually an error. Consider more restrictive permissions.\n" . $herecurr); 3314 "Exporting world writable files is usually an error. Consider more restrictive permissions.\n" . $herecurr);
3293 } 3315 }
3294
3295 # Check for memset with swapped arguments
3296 if ($line =~ /memset.*\,(\ |)(0x|)0(\ |0|)\);/) {
3297 ERROR("MEMSET",
3298 "memset size is 3rd argument, not the second.\n" . $herecurr);
3299 }
3300 } 3316 }
3301 3317
3302 # If we have no input at all, then there is nothing to report on 3318 # If we have no input at all, then there is nothing to report on