aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorJoe Perches <joe@perches.com>2019-03-07 19:28:35 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2019-03-07 21:32:01 -0500
commite29a70f1537b1225daceae8d34bf5bfb80546138 (patch)
tree27b91961f33676c2ce3a94cff02729dbdfd7795c /scripts
parentfdf13693d370653013eec3bc7f80a3f535001bf0 (diff)
checkpatch: add some new alloc functions to various tests
Many new generic allocation functions like the kvmalloc family have been added recently to the kernel. The allocation functions test now includes: o kvmalloc and variants o kstrdup_const o kmemdup_nul o dma_alloc_coherent o alloc_skb and variants Add a separate $allocFunctions variable to help make the allocation functions test a bit more readable. Miscellanea: o Use $allocFunctions in the unnecessary OOM message test and add exclude uses with __GFP_NOWARN o Use $allocFunctions in the unnecessary cast test o Add the kvmalloc family to the preferred sizeof alloc style foo = kvmalloc(sizeof(*foo), ...) Link: http://lkml.kernel.org/r/a5e60a2b93e10baf84af063f6c8e56402273105d.camel@perches.com 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.pl19
1 files changed, 15 insertions, 4 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index c17cbc06911f..76748ab23ce9 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -466,6 +466,16 @@ our $logFunctions = qr{(?x:
466 seq_vprintf|seq_printf|seq_puts 466 seq_vprintf|seq_printf|seq_puts
467)}; 467)};
468 468
469our $allocFunctions = qr{(?x:
470 (?:(?:devm_)?
471 (?:kv|k|v)[czm]alloc(?:_node|_array)? |
472 kstrdup(?:_const)? |
473 kmemdup(?:_nul)?) |
474 (?:\w+)?alloc_skb(?:ip_align)? |
475 # dev_alloc_skb/netdev_alloc_skb, et al
476 dma_alloc_coherent
477)};
478
469our $signature_tags = qr{(?xi: 479our $signature_tags = qr{(?xi:
470 Signed-off-by:| 480 Signed-off-by:|
471 Co-developed-by:| 481 Co-developed-by:|
@@ -5553,7 +5563,8 @@ sub process {
5553 my ($s, $c) = ctx_statement_block($linenr - 3, $realcnt, 0); 5563 my ($s, $c) = ctx_statement_block($linenr - 3, $realcnt, 0);
5554# print("line: <$line>\nprevline: <$prevline>\ns: <$s>\nc: <$c>\n\n\n"); 5564# print("line: <$line>\nprevline: <$prevline>\ns: <$s>\nc: <$c>\n\n\n");
5555 5565
5556 if ($s =~ /(?:^|\n)[ \+]\s*(?:$Type\s*)?\Q$testval\E\s*=\s*(?:\([^\)]*\)\s*)?\s*(?:devm_)?(?:[kv][czm]alloc(?:_node|_array)?\b|kstrdup|kmemdup|(?:dev_)?alloc_skb)/) { 5566 if ($s =~ /(?:^|\n)[ \+]\s*(?:$Type\s*)?\Q$testval\E\s*=\s*(?:\([^\)]*\)\s*)?\s*$allocFunctions\s*\(/ &&
5567 $s !~ /\b__GFP_NOWARN\b/ ) {
5557 WARN("OOM_MESSAGE", 5568 WARN("OOM_MESSAGE",
5558 "Possible unnecessary 'out of memory' message\n" . $hereprev); 5569 "Possible unnecessary 'out of memory' message\n" . $hereprev);
5559 } 5570 }
@@ -6204,8 +6215,8 @@ sub process {
6204 } 6215 }
6205 } 6216 }
6206 6217
6207# check for pointless casting of kmalloc return 6218# check for pointless casting of alloc functions
6208 if ($line =~ /\*\s*\)\s*[kv][czm]alloc(_node){0,1}\b/) { 6219 if ($line =~ /\*\s*\)\s*$allocFunctions\b/) {
6209 WARN("UNNECESSARY_CASTS", 6220 WARN("UNNECESSARY_CASTS",
6210 "unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr); 6221 "unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr);
6211 } 6222 }
@@ -6213,7 +6224,7 @@ sub process {
6213# alloc style 6224# alloc style
6214# p = alloc(sizeof(struct foo), ...) should be p = alloc(sizeof(*p), ...) 6225# p = alloc(sizeof(struct foo), ...) should be p = alloc(sizeof(*p), ...)
6215 if ($perl_version_ok && 6226 if ($perl_version_ok &&
6216 $line =~ /\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*([kv][mz]alloc(?:_node)?)\s*\(\s*(sizeof\s*\(\s*struct\s+$Lval\s*\))/) { 6227 $line =~ /\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*((?:kv|k|v)[mz]alloc(?:_node)?)\s*\(\s*(sizeof\s*\(\s*struct\s+$Lval\s*\))/) {
6217 CHK("ALLOC_SIZEOF_STRUCT", 6228 CHK("ALLOC_SIZEOF_STRUCT",
6218 "Prefer $3(sizeof(*$1)...) over $3($4...)\n" . $herecurr); 6229 "Prefer $3(sizeof(*$1)...) over $3($4...)\n" . $herecurr);
6219 } 6230 }