Skip to content

Commit 1fc524d

Browse files
Sean O. Stalleytorvalds
authored andcommitted
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>
1 parent 01a7fd3 commit 1fc524d

1 file changed

Lines changed: 84 additions & 0 deletions

File tree

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
10+
virtual context
11+
virtual patch
12+
virtual org
13+
virtual report
14+
15+
//----------------------------------------------------------
16+
// For context mode
17+
//----------------------------------------------------------
18+
19+
@depends on context@
20+
expression x;
21+
statement 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@
33+
expression x;
34+
expression a,b,c;
35+
statement 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@
44+
expression x;
45+
expression a,b,c;
46+
statement 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@
59+
expression x;
60+
expression a,b,c;
61+
statement S;
62+
position 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@
70+
p << r.p;
71+
x << r.x;
72+
@@
73+
74+
msg="%s" % (x)
75+
msg_safe=msg.replace("[","@(").replace("]",")")
76+
coccilib.org.print_todo(p[0], msg_safe)
77+
78+
@script:python depends on report@
79+
p << r.p;
80+
x << r.x;
81+
@@
82+
83+
msg="WARNING: *_pool_zalloc should be used for %s, instead of *_pool_alloc/memset" % (x)
84+
coccilib.report.print_report(p[0], msg)

0 commit comments

Comments
 (0)