0001 // SPDX-License-Identifier: GPL-2.0-only
0002 ///
0003 /// Use *_pool_zalloc rather than *_pool_alloc followed by memset with 0
0004 ///
0005 // Copyright: (C) 2015 Intel Corp.
0006 // Options: --no-includes --include-headers
0007 //
0008 // Keywords: dma_pool_zalloc, pci_pool_zalloc
0009 //
0010
0011 virtual context
0012 virtual patch
0013 virtual org
0014 virtual report
0015
0016 //----------------------------------------------------------
0017 // For context mode
0018 //----------------------------------------------------------
0019
0020 @depends on context@
0021 expression x;
0022 statement S;
0023 @@
0024
0025 * x = \(dma_pool_alloc\|pci_pool_alloc\)(...);
0026 if ((x==NULL) || ...) S
0027 * memset(x,0, ...);
0028
0029 //----------------------------------------------------------
0030 // For patch mode
0031 //----------------------------------------------------------
0032
0033 @depends on patch@
0034 expression x;
0035 expression a,b,c;
0036 statement S;
0037 @@
0038
0039 - x = dma_pool_alloc(a,b,c);
0040 + x = dma_pool_zalloc(a,b,c);
0041 if ((x==NULL) || ...) S
0042 - memset(x,0,...);
0043
0044 @depends on patch@
0045 expression x;
0046 expression a,b,c;
0047 statement S;
0048 @@
0049
0050 - x = pci_pool_alloc(a,b,c);
0051 + x = pci_pool_zalloc(a,b,c);
0052 if ((x==NULL) || ...) S
0053 - memset(x,0,...);
0054
0055 //----------------------------------------------------------
0056 // For org and report mode
0057 //----------------------------------------------------------
0058
0059 @r depends on org || report@
0060 expression x;
0061 expression a,b,c;
0062 statement S;
0063 position p;
0064 @@
0065
0066 x = @p\(dma_pool_alloc\|pci_pool_alloc\)(a,b,c);
0067 if ((x==NULL) || ...) S
0068 memset(x,0, ...);
0069
0070 @script:python depends on org@
0071 p << r.p;
0072 x << r.x;
0073 @@
0074
0075 msg="%s" % (x)
0076 msg_safe=msg.replace("[","@(").replace("]",")")
0077 coccilib.org.print_todo(p[0], msg_safe)
0078
0079 @script:python depends on report@
0080 p << r.p;
0081 x << r.x;
0082 @@
0083
0084 msg="WARNING: *_pool_zalloc should be used for %s, instead of *_pool_alloc/memset" % (x)
0085 coccilib.report.print_report(p[0], msg)