| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /// |
|---|
| 2 | 3 | /// Use zeroing allocator rather than allocator followed by memset with 0 |
|---|
| 3 | 4 | /// |
|---|
| .. | .. |
|---|
| 6 | 7 | /// matched code has to be contiguous |
|---|
| 7 | 8 | /// |
|---|
| 8 | 9 | // 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 |
|---|
| 12 | 13 | // URL: http://coccinelle.lip6.fr/rules/kzalloc.html |
|---|
| 13 | 14 | // Options: --no-includes --include-headers |
|---|
| 14 | 15 | // |
|---|
| .. | .. |
|---|
| 69 | 70 | - x = (T)vmalloc(E1); |
|---|
| 70 | 71 | + x = (T)vzalloc(E1); |
|---|
| 71 | 72 | | |
|---|
| 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 | | -| |
|---|
| 81 | 73 | - x = kmalloc_node(E1,E2,E3); |
|---|
| 82 | 74 | + x = kzalloc_node(E1,E2,E3); |
|---|
| 83 | 75 | | |
|---|
| .. | .. |
|---|
| 134 | 126 | ) |
|---|
| 135 | 127 | if ((x==NULL) || ...) S |
|---|
| 136 | 128 | - 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); |
|---|
| 137 | 139 | |
|---|
| 138 | 140 | //---------------------------------------------------------- |
|---|
| 139 | 141 | // For org mode |
|---|
| .. | .. |
|---|
| 207 | 209 | position p; |
|---|
| 208 | 210 | @@ |
|---|
| 209 | 211 | |
|---|
| 210 | | - x = (T)dma_alloc_coherent@p(E2,E1,E3,E4); |
|---|
| 212 | + x = (T)dma_alloc_coherent@p(E1,E2,E3,E4); |
|---|
| 211 | 213 | if ((x==NULL) || ...) S |
|---|
| 212 | | - memset((T2)x,0,E1); |
|---|
| 214 | + memset((T2)x,0,E2); |
|---|
| 213 | 215 | |
|---|
| 214 | 216 | @script:python depends on org@ |
|---|
| 215 | 217 | p << r2.p; |
|---|
| .. | .. |
|---|
| 225 | 227 | x << r2.x; |
|---|
| 226 | 228 | @@ |
|---|
| 227 | 229 | |
|---|
| 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) |
|---|
| 229 | 231 | coccilib.report.print_report(p[0], msg) |
|---|
| 230 | 232 | |
|---|
| 231 | 233 | //----------------------------------------------------------------- |
|---|