diff options
Diffstat (limited to 'scripts/checkpatch.pl')
| -rwxr-xr-x | scripts/checkpatch.pl | 28 |
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 |
