Release coccinelle-0.1
[bpt/coccinelle.git] / demos / janitorings / kzalloc-orig.cocci
1 // have to duplicate a lot of rules because T E only matches if E has a known
2 // type, even if T is not used elsewhere.
3
4 // originally, the whens were when != x, but that doesn't work because x
5 // only binds to the outermost expression, not all possible expressions, and
6 // the value returned by kmalloc is usually used as a subexpression.
7 // so we have considered the typical uses that may cause problems; a function
8 // call or dereference
9
10 //\(x->fld\|f(...,x,...)\|x=E\)
11
12 @@
13 type T, T2;
14 expression x;
15 identifier f,fld;
16 expression E;
17 expression E1,E2;
18 expression e1,e2,e3,y;
19 statement S;
20 @@
21
22 - x = (T)kmalloc(E1,E2)
23 + x = kzalloc(E1,E2)
24 ... when != \(x->fld=E;\|y=f(...,x,...);\|f(...,x,...);\|x=E;\|while(...) S\|for(e1;e2;e3) S\)
25 - memset((T2)x,0,E1);
26
27 @@
28 type T, T2;
29 type T1;
30 T1 *x;
31 identifier f,fld;
32 expression E;
33 expression E2;
34 expression e1,e2,e3,y;
35 statement S;
36 @@
37
38 - x = (T)kmalloc(sizeof(T1),E2)
39 + x = kzalloc(sizeof(T1),E2)
40 ... when != \(x->fld=E;\|y=f(...,x,...);\|f(...,x,...);\|x=E;\|while(...) S\|for(e1;e2;e3) S\)
41 - memset((T2)x,0,sizeof(*x));
42
43 @@
44 type T, T2;
45 type T1;
46 T1 *x;
47 identifier f,fld;
48 expression E;
49 expression E2;
50 expression e1,e2,e3,y;
51 statement S;
52 @@
53
54 - x = (T)kmalloc(sizeof(*x),E2)
55 + x = kzalloc(sizeof(*x),E2)
56 ... when != \(x->fld=E;\|y=f(...,x,...);\|f(...,x,...);\|x=E;\|while(...) S\|for(e1;e2;e3) S\)
57 - memset((T2)x,0,sizeof(T1));
58
59 // ---------------------------------------------------------------------
60 // ---------------------------------------------------------------------
61 @@
62 type T, T2;
63 expression x;
64 identifier f,fld;
65 expression E;
66 expression E1,E2;
67 expression e1,e2,e3,y;
68 statement S, S1;
69 @@
70
71 - x = (T)kmalloc(E1,E2)
72 + x = kzalloc(E1,E2)
73 ... when != \(x->fld=E;\|y=f(...,x,...);\|f(...,x,...);\|x=E;\|while(...) S\|for(e1;e2;e3) S\)
74 if(x != NULL) {
75 ... when != \(x->fld=E;\|y=f(...,x,...);\|f(...,x,...);\|x=E;\|while(...) S\|for(e1;e2;e3) S\)
76 - memset((T2)x,0,E1);
77 ...
78 } else S1
79
80 @@
81 type T, T2;
82 type T1;
83 T1 *x;
84 identifier f,fld;
85 expression E;
86 expression E2;
87 expression e1,e2,e3,y;
88 statement S, S1;
89 @@
90
91 - x = (T)kmalloc(sizeof(T1),E2)
92 + x = kzalloc(sizeof(T1),E2)
93 ... when != \(x->fld=E;\|y=f(...,x,...);\|f(...,x,...);\|x=E;\|while(...) S\|for(e1;e2;e3) S\)
94 if(x != NULL) {
95 ... when != \(x->fld=E;\|y=f(...,x,...);\|f(...,x,...);\|x=E;\|while(...) S\|for(e1;e2;e3) S\)
96 - memset((T2)x,0,sizeof(*x));
97 ...
98 } else S1
99
100 @@
101 type T, T2;
102 type T1;
103 T1 *x;
104 identifier f,fld;
105 expression E;
106 expression E2;
107 expression e1,e2,e3,y;
108 statement S, S1;
109 @@
110
111 - x = (T)kmalloc(sizeof(*x),E2)
112 + x = kzalloc(sizeof(*x),E2)
113 ... when != \(x->fld=E;\|y=f(...,x,...);\|f(...,x,...);\|x=E;\|while(...) S\|for(e1;e2;e3) S\)
114 if(x != NULL) {
115 ... when != \(x->fld=E;\|y=f(...,x,...);\|f(...,x,...);\|x=E;\|while(...) S\|for(e1;e2;e3) S\)
116 - memset((T2)x,0,sizeof(T1));
117 ...
118 } else S1
119
120 // ---------------------------------------------------------------------
121 // ---------------------------------------------------------------------
122 @@
123 type T, T2;
124 type T1;
125 identifier x;
126 identifier f,fld;
127 expression E;
128 expression E1,E2;
129 expression e1,e2,e3,y;
130 statement S;
131 @@
132
133 - T1 x = (T)kmalloc(E1,E2);
134 + T1 x = kzalloc(E1,E2);
135 ... when != \(x->fld=E;\|y=f(...,x,...);\|f(...,x,...);\|x=E;\|while(...) S\|for(e1;e2;e3) S\)
136 - memset((T2)x,0,E1);
137
138 @@
139 type T, T2;
140 type T1;
141 identifier x;
142 identifier f,fld;
143 expression E;
144 expression E2;
145 expression e1,e2,e3,y;
146 statement S;
147 @@
148
149 - T1 x = (T)kmalloc(sizeof(T1),E2);
150 + T1 x = kzalloc(sizeof(T1),E2);
151 ... when != \(x->fld=E;\|y=f(...,x,...);\|f(...,x,...);\|x=E;\|while(...) S\|for(e1;e2;e3) S\)
152 - memset((T2)x,0,sizeof(*x));
153
154 @@
155 type T, T2;
156 type T1;
157 identifier x;
158 identifier f,fld;
159 expression E;
160 expression E2;
161 expression e1,e2,e3,y;
162 statement S;
163 @@
164
165 - T1 x = (T)kmalloc(sizeof(*x),E2);
166 + T1 x = kzalloc(sizeof(*x),E2);
167 ... when != \(x->fld=E;\|y=f(...,x,...);\|f(...,x,...);\|x=E;\|while(...) S\|for(e1;e2;e3) S\)
168 - memset((T2)x,0,sizeof(T1));
169
170 // ---------------------------------------------------------------------
171 // ---------------------------------------------------------------------
172 @@
173 type T, T2;
174 type T1;
175 identifier x;
176 identifier f,fld;
177 expression E;
178 expression E1,E2;
179 expression e1,e2,e3,y;
180 statement S, S1;
181 @@
182
183 - T1 x = (T)kmalloc(E1,E2);
184 + T1 x = kzalloc(E1,E2);
185 ... when != \(x->fld=E;\|y=f(...,x,...);\|f(...,x,...);\|x=E;\|while(...) S\|for(e1;e2;e3) S\)
186 if(x != NULL) {
187 ... when != \(x->fld=E;\|y=f(...,x,...);\|f(...,x,...);\|x=E;\|while(...) S\|for(e1;e2;e3) S\)
188 - memset((T2)x,0,E1);
189 ...
190 } else S1
191
192 @@
193 type T, T2;
194 type T1;
195 identifier x;
196 identifier f,fld;
197 expression E;
198 expression E2;
199 expression e1,e2,e3,y;
200 statement S, S1;
201 @@
202
203 - T1 x = (T)kmalloc(sizeof(T1),E2);
204 + T1 x = kzalloc(sizeof(T1),E2);
205 ... when != \(x->fld=E;\|y=f(...,x,...);\|f(...,x,...);\|x=E;\|while(...) S\|for(e1;e2;e3) S\)
206 if(x != NULL) {
207 ... when != \(x->fld=E;\|y=f(...,x,...);\|f(...,x,...);\|x=E;\|while(...) S\|for(e1;e2;e3) S\)
208 - memset((T2)x,0,sizeof(*x));
209 ...
210 } else S1
211
212 @@
213 type T, T2;
214 type T1;
215 identifier x;
216 identifier f,fld;
217 expression E;
218 expression E2;
219 expression e1,e2,e3,y;
220 statement S, S1;
221 @@
222
223 - T1 x = (T)kmalloc(sizeof(*x),E2);
224 + T1 x = kzalloc(sizeof(*x),E2);
225 ... when != \(x->fld=E;\|y=f(...,x,...);\|f(...,x,...);\|x=E;\|while(...) S\|for(e1;e2;e3) S\)
226 if(x != NULL) {
227 ... when != \(x->fld=E;\|y=f(...,x,...);\|f(...,x,...);\|x=E;\|while(...) S\|for(e1;e2;e3) S\)
228 - memset((T2)x,0,sizeof(T1));
229 ...
230 } else S1
231
232 // ---------------------------------------------------------------------
233 // ---------------------------------------------------------------------
234 @@
235 expression E1,E2,E3;
236 @@
237
238 - kzalloc(E1 * E2,E3)
239 + kcalloc(E1,E2,E3)