]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
checkpatch: Add check for kcalloc argument order
authorJoe Perches <joe@perches.com>
Wed, 20 Feb 2013 02:15:35 +0000 (13:15 +1100)
committerStephen Rothwell <sfr@canb.auug.org.au>
Wed, 20 Feb 2013 05:53:20 +0000 (16:53 +1100)
kcalloc is sometimes misused with the first and second arguments switched.

Same issue with kmalloc_array too.

Bleat if sizeof is the first argument

Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
scripts/checkpatch.pl

index 2c50eb4c4e6654f741a9e8cce82e0d3530ab19ac..7b40a3f729a774f3a417fbafb185ab063a5ba705 100755 (executable)
@@ -3476,6 +3476,12 @@ sub process {
                             "unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr);
                }
 
+# check for alloc argument mismatch
+               if ($line =~ /\b(kcalloc|kmalloc_array)\s*\(\s*sizeof\b/) {
+                       WARN("ALLOC_ARRAY_ARGS",
+                            "$1 uses number as first arg, sizeof is generally wrong\n" . $herecurr);
+               }
+
 # check for multiple semicolons
                if ($line =~ /;\s*;\s*$/) {
                        WARN("ONE_SEMICOLON",