hc
2024-05-10 9999e48639b3cecb08ffb37358bcba3b48161b29
kernel/scripts/coccinelle/api/alloc/zalloc-simple.cocci
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 ///
23 /// Use zeroing allocator rather than allocator followed by memset with 0
34 ///
....@@ -6,9 +7,9 @@
67 /// matched code has to be contiguous
78 ///
89 // Confidence: High
9
-// Copyright: (C) 2009-2010 Julia Lawall, Nicolas Palix, DIKU. GPLv2.
10
-// Copyright: (C) 2009-2010 Gilles Muller, INRIA/LiP6. GPLv2.
11
-// Copyright: (C) 2017 Himanshu Jha GPLv2.
10
+// Copyright: (C) 2009-2010 Julia Lawall, Nicolas Palix, DIKU.
11
+// Copyright: (C) 2009-2010 Gilles Muller, INRIA/LiP6.
12
+// Copyright: (C) 2017 Himanshu Jha
1213 // URL: http://coccinelle.lip6.fr/rules/kzalloc.html
1314 // Options: --no-includes --include-headers
1415 //
....@@ -69,15 +70,6 @@
6970 - x = (T)vmalloc(E1);
7071 + x = (T)vzalloc(E1);
7172 |
72
-- x = dma_alloc_coherent(E2,E1,E3,E4);
73
-+ x = dma_zalloc_coherent(E2,E1,E3,E4);
74
-|
75
-- x = (T *)dma_alloc_coherent(E2,E1,E3,E4);
76
-+ x = dma_zalloc_coherent(E2,E1,E3,E4);
77
-|
78
-- x = (T)dma_alloc_coherent(E2,E1,E3,E4);
79
-+ x = (T)dma_zalloc_coherent(E2,E1,E3,E4);
80
-|
8173 - x = kmalloc_node(E1,E2,E3);
8274 + x = kzalloc_node(E1,E2,E3);
8375 |
....@@ -134,6 +126,16 @@
134126 )
135127 if ((x==NULL) || ...) S
136128 - memset((T2)x,0,E1);
129
+
130
+@depends on patch@
131
+type T, T2;
132
+expression x;
133
+expression E1,E2,E3,E4;
134
+statement S;
135
+@@
136
+ x = (T)dma_alloc_coherent(E1, E2, E3, E4);
137
+ if ((x==NULL) || ...) S
138
+- memset((T2)x, 0, E2);
137139
138140 //----------------------------------------------------------
139141 // For org mode
....@@ -207,9 +209,9 @@
207209 position p;
208210 @@
209211
210
- x = (T)dma_alloc_coherent@p(E2,E1,E3,E4);
212
+ x = (T)dma_alloc_coherent@p(E1,E2,E3,E4);
211213 if ((x==NULL) || ...) S
212
- memset((T2)x,0,E1);
214
+ memset((T2)x,0,E2);
213215
214216 @script:python depends on org@
215217 p << r2.p;
....@@ -225,7 +227,7 @@
225227 x << r2.x;
226228 @@
227229
228
-msg="WARNING: dma_zalloc_coherent should be used for %s, instead of dma_alloc_coherent/memset" % (x)
230
+msg="WARNING: dma_alloc_coherent used in %s already zeroes out memory, so memset is not needed" % (x)
229231 coccilib.report.print_report(p[0], msg)
230232
231233 //-----------------------------------------------------------------