diff options
| author | Sean O. Stalley <sean.stalley@intel.com> | 2015-09-08 18:02:33 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-09-08 18:35:28 -0400 |
| commit | 1fc524d74cf40072a2de3f74a920818398dbff30 (patch) | |
| tree | 0eb168ce6d839778140ba9b2338f6e760926e193 /scripts/coccinelle/api/alloc | |
| parent | 01a7fd337b2c2af97e9c55bb9406a222a2e209d3 (diff) | |
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>
Diffstat (limited to 'scripts/coccinelle/api/alloc')
| -rw-r--r-- | scripts/coccinelle/api/alloc/pool_zalloc-simple.cocci | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/scripts/coccinelle/api/alloc/pool_zalloc-simple.cocci b/scripts/coccinelle/api/alloc/pool_zalloc-simple.cocci new file mode 100644 index 000000000000..9b7eb321a025 --- /dev/null +++ b/scripts/coccinelle/api/alloc/pool_zalloc-simple.cocci | |||
| @@ -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) | ||
