aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorJoe Perches <joe@perches.com>2015-04-16 15:44:36 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2015-04-17 09:03:58 -0400
commitb598b67060f14eb8c34d0cef1db4727dab56ef91 (patch)
treeeae35ba4c7ad7e538a0c273a504169f540b50b15 /scripts
parent6d07d01b62b2d81500803058f736b46677ec873a (diff)
checkpatch: add 'Prefer ARRAY_SIZE" test
Add a test for sizeof(foo)/sizeof(foo[0]) that could be ARRAY_SIZE(foo). Signed-off-by: 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.pl13
1 files changed, 13 insertions, 0 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index ea628ebfa20e..6c11cb61e9f4 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3227,6 +3227,19 @@ sub process {
3227 $herecurr); 3227 $herecurr);
3228 } 3228 }
3229 3229
3230# check for sizeof(foo)/sizeof(foo[0]) that could be ARRAY_SIZE(foo)
3231 if ($line =~ m@\bsizeof\s*\(\s*($Lval)\s*\)@) {
3232 my $array = $1;
3233 if ($line =~ m@\b(sizeof\s*\(\s*\Q$array\E\s*\)\s*/\s*sizeof\s*\(\s*\Q$array\E\s*\[\s*0\s*\]\s*\))@) {
3234 my $array_div = $1;
3235 if (WARN("ARRAY_SIZE",
3236 "Prefer ARRAY_SIZE($array)\n" . $herecurr) &&
3237 $fix) {
3238 $fixed[$fixlinenr] =~ s/\Q$array_div\E/ARRAY_SIZE($array)/;
3239 }
3240 }
3241 }
3242
3230# check for function declarations without arguments like "int foo()" 3243# check for function declarations without arguments like "int foo()"
3231 if ($line =~ /(\b$Type\s+$Ident)\s*\(\s*\)/) { 3244 if ($line =~ /(\b$Type\s+$Ident)\s*\(\s*\)/) {
3232 if (ERROR("FUNCTION_WITHOUT_ARGS", 3245 if (ERROR("FUNCTION_WITHOUT_ARGS",