aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/coccinelle/api/alloc
diff options
context:
space:
mode:
authorSean O. Stalley <sean.stalley@intel.com>2015-09-08 18:02:33 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2015-09-08 18:35:28 -0400
commit1fc524d74cf40072a2de3f74a920818398dbff30 (patch)
tree0eb168ce6d839778140ba9b2338f6e760926e193 /scripts/coccinelle/api/alloc
parent01a7fd337b2c2af97e9c55bb9406a222a2e209d3 (diff)
coccinelle: mm: scripts/coccinelle/api/alloc/pool_zalloc-simple.cocci
add [pci|dma]_pool_zalloc coccinelle check. replaces instances of [pci|dma]_pool_alloc() followed by memset(0) with [pci|dma]_pool_zalloc(). Signed-off-by: Sean O. Stalley <sean.stalley@intel.com> Acked-by: Julia Lawall <julia.lawall@lip6.fr> Cc: Vinod Koul <vinod.koul@intel.com> Cc: Bjorn Helgaas <bhelgaas@google.com> Cc: Gilles Muller <Gilles.Muller@lip6.fr> Cc: Nicolas Palix <nicolas.palix@imag.fr> Cc: Michal Marek <mmarek@suse.cz> Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Cc: Jonathan Corbet <corbet@lwn.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'scripts/coccinelle/api/alloc')
-rw-r--r--scripts/coccinelle/api/alloc/pool_zalloc-simple.cocci84
1 files changed, 84 insertions, 0 deletions
diff --git a/scripts/coccinelle/api/alloc/pool_zalloc-simple.cocci b/scripts/coccinelle/api/alloc/pool_zalloc-simple.cocci
new file mode 100644
index 000000000000..9b7eb321a025
--- /dev/null
+++ b/scripts/coccinelle/api/alloc/pool_zalloc-simple.cocci
@@ -0,0 +1,84 @@
1///
2/// Use *_pool_zalloc rather than *_pool_alloc followed by memset with 0
3///
4// Copyright: (C) 2015 Intel Corp. GPLv2.
5// Options: --no-includes --include-headers
6//
7// Keywords: dma_pool_zalloc, pci_pool_zalloc
8//
9
10virtual context
11virtual patch
12virtual org
13virtual report
14
15//----------------------------------------------------------
16// For context mode
17//----------------------------------------------------------
18
19@depends on context@
20expression x;
21statement S;
22@@
23
24* x = \(dma_pool_alloc\|pci_pool_alloc\)(...);
25 if ((x==NULL) || ...) S
26* memset(x,0, ...);
27
28//----------------------------------------------------------
29// For patch mode
30//----------------------------------------------------------
31
32@depends on patch@
33expression x;
34expression a,b,c;
35statement S;
36@@
37
38- x = dma_pool_alloc(a,b,c);
39+ x = dma_pool_zalloc(a,b,c);
40 if ((x==NULL) || ...) S
41- memset(x,0,...);
42
43@depends on patch@
44expression x;
45expression a,b,c;
46statement S;
47@@
48
49- x = pci_pool_alloc(a,b,c);
50+ x = pci_pool_zalloc(a,b,c);
51 if ((x==NULL) || ...) S
52- memset(x,0,...);
53
54//----------------------------------------------------------
55// For org and report mode
56//----------------------------------------------------------
57
58@r depends on org || report@
59expression x;
60expression a,b,c;
61statement S;
62position p;
63@@
64
65 x = @p\(dma_pool_alloc\|pci_pool_alloc\)(a,b,c);
66 if ((x==NULL) || ...) S
67 memset(x,0, ...);
68
69@script:python depends on org@
70p << r.p;
71x << r.x;
72@@
73
74msg="%s" % (x)
75msg_safe=msg.replace("[","@(").replace("]",")")
76coccilib.org.print_todo(p[0], msg_safe)
77
78@script:python depends on report@
79p << r.p;
80x << r.x;
81@@
82
83msg="WARNING: *_pool_zalloc should be used for %s, instead of *_pool_alloc/memset" % (x)
84coccilib.report.print_report(p[0], msg)