These changes are the raw update to linux-4.4.6-rt14. Kernel sources
[kvmfornfv.git] / kernel / scripts / coccinelle / api / alloc / pool_zalloc-simple.cocci
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)