linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Coccinelle: kzalloc-simple: Rename kzalloc-simple to zalloc-simple
@ 2018-01-13 15:57 Himanshu Jha
  2018-01-13 16:27 ` Julia Lawall
  2018-01-13 17:02 ` [Cocci] " Fabio Estevam
  0 siblings, 2 replies; 6+ messages in thread
From: Himanshu Jha @ 2018-01-13 15:57 UTC (permalink / raw)
  To: yamada.masahiro
  Cc: Julia.Lawall, Gilles.Muller, nicolas.palix, michal.lkml, cocci,
	linux-kernel, Himanshu Jha

Rename kzalloc-simple to zalloc-simple since now the rule is not
specific to kzalloc function only, but also to many other zero memory
allocating functions specified in the rule.

Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com>
---
 scripts/coccinelle/api/alloc/kzalloc-simple.cocci | 448 ----------------------
 scripts/coccinelle/api/alloc/zalloc.cocci         | 448 ++++++++++++++++++++++
 2 files changed, 448 insertions(+), 448 deletions(-)
 delete mode 100644 scripts/coccinelle/api/alloc/kzalloc-simple.cocci
 create mode 100644 scripts/coccinelle/api/alloc/zalloc.cocci

diff --git a/scripts/coccinelle/api/alloc/kzalloc-simple.cocci b/scripts/coccinelle/api/alloc/kzalloc-simple.cocci
deleted file mode 100644
index 92b2091..0000000
--- a/scripts/coccinelle/api/alloc/kzalloc-simple.cocci
+++ /dev/null
@@ -1,448 +0,0 @@
-///
-/// Use zeroing allocator rather than allocator followed by memset with 0
-///
-/// This considers some simple cases that are common and easy to validate
-/// Note in particular that there are no ...s in the rule, so all of the
-/// matched code has to be contiguous
-///
-// Confidence: High
-// Copyright: (C) 2009-2010 Julia Lawall, Nicolas Palix, DIKU.  GPLv2.
-// Copyright: (C) 2009-2010 Gilles Muller, INRIA/LiP6.  GPLv2.
-// Copyright: (C) 2017 Himanshu Jha GPLv2.
-// URL: http://coccinelle.lip6.fr/rules/kzalloc.html
-// Options: --no-includes --include-headers
-//
-// Keywords: kmalloc, kzalloc
-// Version min: < 2.6.12 kmalloc
-// Version min:   2.6.14 kzalloc
-//
-
-virtual context
-virtual patch
-virtual org
-virtual report
-
-//----------------------------------------------------------
-//  For context mode
-//----------------------------------------------------------
-
-@depends on context@
-type T, T2;
-expression x;
-expression E1;
-statement S;
-@@
-
-* x = (T)\(kmalloc(E1, ...)\|vmalloc(E1)\|dma_alloc_coherent(...,E1,...)\|
-  kmalloc_node(E1, ...)\|kmem_cache_alloc(...)\|kmem_alloc(E1, ...)\|
-  devm_kmalloc(...,E1,...)\|kvmalloc(E1, ...)\|pci_alloc_consistent(...,E1,...)\|
-  kvmalloc_node(E1,...)\);
-  if ((x==NULL) || ...) S
-* memset((T2)x,0,E1);
-
-//----------------------------------------------------------
-//  For patch mode
-//----------------------------------------------------------
-
-@depends on patch@
-type T, T2;
-expression x;
-expression E1,E2,E3,E4;
-statement S;
-@@
-
-(
-- x = kmalloc(E1,E2);
-+ x = kzalloc(E1,E2);
-|
-- x = (T *)kmalloc(E1,E2);
-+ x = kzalloc(E1,E2);
-|
-- x = (T)kmalloc(E1,E2);
-+ x = (T)kzalloc(E1,E2);
-|
-- x = vmalloc(E1);
-+ x = vzalloc(E1);
-|
-- x = (T *)vmalloc(E1);
-+ x = vzalloc(E1);
-|
-- x = (T)vmalloc(E1);
-+ x = (T)vzalloc(E1);
-|
-- x = dma_alloc_coherent(E2,E1,E3,E4);
-+ x = dma_zalloc_coherent(E2,E1,E3,E4);
-|
-- x = (T *)dma_alloc_coherent(E2,E1,E3,E4);
-+ x = dma_zalloc_coherent(E2,E1,E3,E4);
-|
-- x = (T)dma_alloc_coherent(E2,E1,E3,E4);
-+ x = (T)dma_zalloc_coherent(E2,E1,E3,E4);
-|
-- x = kmalloc_node(E1,E2,E3);
-+ x = kzalloc_node(E1,E2,E3);
-|
-- x = (T *)kmalloc_node(E1,E2,E3);
-+ x = kzalloc_node(E1,E2,E3);
-|
-- x = (T)kmalloc_node(E1,E2,E3);
-+ x = (T)kzalloc_node(E1,E2,E3);
-|
-- x = kmem_cache_alloc(E3,E4);
-+ x = kmem_cache_zalloc(E3,E4);
-|
-- x = (T *)kmem_cache_alloc(E3,E4);
-+ x = kmem_cache_zalloc(E3,E4);
-|
-- x = (T)kmem_cache_alloc(E3,E4);
-+ x = (T)kmem_cache_zalloc(E3,E4);
-|
-- x = kmem_alloc(E1,E2);
-+ x = kmem_zalloc(E1,E2);
-|
-- x = (T *)kmem_alloc(E1,E2);
-+ x = kmem_zalloc(E1,E2);
-|
-- x = (T)kmem_alloc(E1,E2);
-+ x = (T)kmem_zalloc(E1,E2);
-|
-- x = devm_kmalloc(E2,E1,E3);
-+ x = devm_kzalloc(E2,E1,E3);
-|
-- x = (T *)devm_kmalloc(E2,E1,E3);
-+ x = devm_kzalloc(E2,E1,E3);
-|
-- x = (T)devm_kmalloc(E2,E1,E3);
-+ x = (T)devm_kzalloc(E2,E1,E3);
-|
-- x = kvmalloc(E1,E2);
-+ x = kvzalloc(E1,E2);
-|
-- x = (T *)kvmalloc(E1,E2);
-+ x = kvzalloc(E1,E2);
-|
-- x = (T)kvmalloc(E1,E2);
-+ x = (T)kvzalloc(E1,E2);
-|
-- x = pci_alloc_consistent(E2,E1,E3);
-+ x = pci_zalloc_consistent(E2,E1,E3);
-|
-- x = (T *)pci_alloc_consistent(E2,E1,E3);
-+ x = pci_zalloc_consistent(E2,E1,E3);
-|
-- x = (T)pci_alloc_consistent(E2,E1,E3);
-+ x = (T)pci_zalloc_consistent(E2,E1,E3);
-|
-- x = kvmalloc_node(E1,E2,E3);
-+ x = kvzalloc_node(E1,E2,E3);
-|
-- x = (T *)kvmalloc_node(E1,E2,E3);
-+ x = kvzalloc_node(E1,E2,E3);
-|
-- x = (T)kvmalloc_node(E1,E2,E3);
-+ x = (T)kvzalloc_node(E1,E2,E3);
-)
-  if ((x==NULL) || ...) S
-- memset((T2)x,0,E1);
-
-//----------------------------------------------------------
-//  For org mode
-//----------------------------------------------------------
-
-@r depends on org || report@
-type T, T2;
-expression x;
-expression E1,E2;
-statement S;
-position p;
-@@
-
- x = (T)kmalloc@p(E1,E2);
- if ((x==NULL) || ...) S
- memset((T2)x,0,E1);
-
-@script:python depends on org@
-p << r.p;
-x << r.x;
-@@
-
-msg="%s" % (x)
-msg_safe=msg.replace("[","@(").replace("]",")")
-coccilib.org.print_todo(p[0], msg_safe)
-
-@script:python depends on report@
-p << r.p;
-x << r.x;
-@@
-
-msg="WARNING: kzalloc should be used for %s, instead of kmalloc/memset" % (x)
-coccilib.report.print_report(p[0], msg)
-
-//-----------------------------------------------------------------
-@r1 depends on org || report@
-type T, T2;
-expression x;
-expression E1;
-statement S;
-position p;
-@@
-
- x = (T)vmalloc@p(E1);
- if ((x==NULL) || ...) S
- memset((T2)x,0,E1);
-
-@script:python depends on org@
-p << r1.p;
-x << r1.x;
-@@
-
-msg="%s" % (x)
-msg_safe=msg.replace("[","@(").replace("]",")")
-coccilib.org.print_todo(p[0], msg_safe)
-
-@script:python depends on report@
-p << r1.p;
-x << r1.x;
-@@
-
-msg="WARNING: vzalloc should be used for %s, instead of vmalloc/memset" % (x)
-coccilib.report.print_report(p[0], msg)
-
-//-----------------------------------------------------------------
-@r2 depends on org || report@
-type T, T2;
-expression x;
-expression E1,E2,E3,E4;
-statement S;
-position p;
-@@
-
- x = (T)dma_alloc_coherent@p(E2,E1,E3,E4);
- if ((x==NULL) || ...) S
- memset((T2)x,0,E1);
-
-@script:python depends on org@
-p << r2.p;
-x << r2.x;
-@@
-
-msg="%s" % (x)
-msg_safe=msg.replace("[","@(").replace("]",")")
-coccilib.org.print_todo(p[0], msg_safe)
-
-@script:python depends on report@
-p << r2.p;
-x << r2.x;
-@@
-
-msg="WARNING: dma_zalloc_coherent should be used for %s, instead of dma_alloc_coherent/memset" % (x)
-coccilib.report.print_report(p[0], msg)
-
-//-----------------------------------------------------------------
-@r3 depends on org || report@
-type T, T2;
-expression x;
-expression E1,E2,E3;
-statement S;
-position p;
-@@
-
- x = (T)kmalloc_node@p(E1,E2,E3);
- if ((x==NULL) || ...) S
- memset((T2)x,0,E1);
-
-@script:python depends on org@
-p << r3.p;
-x << r3.x;
-@@
-
-msg="%s" % (x)
-msg_safe=msg.replace("[","@(").replace("]",")")
-coccilib.org.print_todo(p[0], msg_safe)
-
-@script:python depends on report@
-p << r3.p;
-x << r3.x;
-@@
-
-msg="WARNING: kzalloc_node should be used for %s, instead of kmalloc_node/memset" % (x)
-coccilib.report.print_report(p[0], msg)
-
-//-----------------------------------------------------------------
-@r4 depends on org || report@
-type T, T2;
-expression x;
-expression E1,E2,E3;
-statement S;
-position p;
-@@
-
- x = (T)kmem_cache_alloc@p(E2,E3);
- if ((x==NULL) || ...) S
- memset((T2)x,0,E1);
-
-@script:python depends on org@
-p << r4.p;
-x << r4.x;
-@@
-
-msg="%s" % (x)
-msg_safe=msg.replace("[","@(").replace("]",")")
-coccilib.org.print_todo(p[0], msg_safe)
-
-@script:python depends on report@
-p << r4.p;
-x << r4.x;
-@@
-
-msg="WARNING: kmem_cache_zalloc should be used for %s, instead of kmem_cache_alloc/memset" % (x)
-coccilib.report.print_report(p[0], msg)
-
-//-----------------------------------------------------------------
-@r5 depends on org || report@
-type T, T2;
-expression x;
-expression E1,E2;
-statement S;
-position p;
-@@
-
- x = (T)kmem_alloc@p(E1,E2);
- if ((x==NULL) || ...) S
- memset((T2)x,0,E1);
-
-@script:python depends on org@
-p << r5.p;
-x << r5.x;
-@@
-
-msg="%s" % (x)
-msg_safe=msg.replace("[","@(").replace("]",")")
-coccilib.org.print_todo(p[0], msg_safe)
-
-@script:python depends on report@
-p << r5.p;
-x << r5.x;
-@@
-
-msg="WARNING: kmem_zalloc should be used for %s, instead of kmem_alloc/memset" % (x)
-coccilib.report.print_report(p[0], msg)
-
-//-----------------------------------------------------------------
-@r6 depends on org || report@
-type T, T2;
-expression x;
-expression E1,E2,E3;
-statement S;
-position p;
-@@
-
- x = (T)devm_kmalloc@p(E2,E1,E3);
- if ((x==NULL) || ...) S
- memset((T2)x,0,E1);
-
-@script:python depends on org@
-p << r6.p;
-x << r6.x;
-@@
-
-msg="%s" % (x)
-msg_safe=msg.replace("[","@(").replace("]",")")
-coccilib.org.print_todo(p[0], msg_safe)
-
-@script:python depends on report@
-p << r6.p;
-x << r6.x;
-@@
-
-msg="WARNING: devm_kzalloc should be used for %s, instead of devm_kmalloc/memset" % (x)
-coccilib.report.print_report(p[0], msg)
-
-//-----------------------------------------------------------------
-@r7 depends on org || report@
-type T, T2;
-expression x;
-expression E1,E2;
-statement S;
-position p;
-@@
-
- x = (T)kvmalloc@p(E1,E2);
- if ((x==NULL) || ...) S
- memset((T2)x,0,E1);
-
-@script:python depends on org@
-p << r7.p;
-x << r7.x;
-@@
-
-msg="%s" % (x)
-msg_safe=msg.replace("[","@(").replace("]",")")
-coccilib.org.print_todo(p[0], msg_safe)
-
-@script:python depends on report@
-p << r7.p;
-x << r7.x;
-@@
-
-msg="WARNING: kvzalloc should be used for %s, instead of kvmalloc/memset" % (x)
-coccilib.report.print_report(p[0], msg)
-
-//-----------------------------------------------------------------
-@r8 depends on org || report@
-type T, T2;
-expression x;
-expression E1,E2,E3;
-statement S;
-position p;
-@@
-
- x = (T)pci_alloc_consistent@p(E2,E1,E3);
- if ((x==NULL) || ...) S
- memset((T2)x,0,E1);
-
-@script:python depends on org@
-p << r8.p;
-x << r8.x;
-@@
-
-msg="%s" % (x)
-msg_safe=msg.replace("[","@(").replace("]",")")
-coccilib.org.print_todo(p[0], msg_safe)
-
-@script:python depends on report@
-p << r8.p;
-x << r8.x;
-@@
-
-msg="WARNING: pci_zalloc_consistent should be used for %s, instead of pci_alloc_consistent/memset" % (x)
-coccilib.report.print_report(p[0], msg)
-//-----------------------------------------------------------------
-@r9 depends on org || report@
-type T, T2;
-expression x;
-expression E1,E2,E3;
-statement S;
-position p;
-@@
-
- x = (T)kvmalloc_node@p(E1,E2,E3);
- if ((x==NULL) || ...) S
- memset((T2)x,0,E1);
-
-@script:python depends on org@
-p << r9.p;
-x << r9.x;
-@@
-
-msg="%s" % (x)
-msg_safe=msg.replace("[","@(").replace("]",")")
-coccilib.org.print_todo(p[0], msg_safe)
-
-@script:python depends on report@
-p << r9.p;
-x << r9.x;
-@@
-
-msg="WARNING: kvzalloc_node should be used for %s, instead of kvmalloc_node/memset" % (x)
-coccilib.report.print_report(p[0], msg)
diff --git a/scripts/coccinelle/api/alloc/zalloc.cocci b/scripts/coccinelle/api/alloc/zalloc.cocci
new file mode 100644
index 0000000..92b2091
--- /dev/null
+++ b/scripts/coccinelle/api/alloc/zalloc.cocci
@@ -0,0 +1,448 @@
+///
+/// Use zeroing allocator rather than allocator followed by memset with 0
+///
+/// This considers some simple cases that are common and easy to validate
+/// Note in particular that there are no ...s in the rule, so all of the
+/// matched code has to be contiguous
+///
+// Confidence: High
+// Copyright: (C) 2009-2010 Julia Lawall, Nicolas Palix, DIKU.  GPLv2.
+// Copyright: (C) 2009-2010 Gilles Muller, INRIA/LiP6.  GPLv2.
+// Copyright: (C) 2017 Himanshu Jha GPLv2.
+// URL: http://coccinelle.lip6.fr/rules/kzalloc.html
+// Options: --no-includes --include-headers
+//
+// Keywords: kmalloc, kzalloc
+// Version min: < 2.6.12 kmalloc
+// Version min:   2.6.14 kzalloc
+//
+
+virtual context
+virtual patch
+virtual org
+virtual report
+
+//----------------------------------------------------------
+//  For context mode
+//----------------------------------------------------------
+
+@depends on context@
+type T, T2;
+expression x;
+expression E1;
+statement S;
+@@
+
+* x = (T)\(kmalloc(E1, ...)\|vmalloc(E1)\|dma_alloc_coherent(...,E1,...)\|
+  kmalloc_node(E1, ...)\|kmem_cache_alloc(...)\|kmem_alloc(E1, ...)\|
+  devm_kmalloc(...,E1,...)\|kvmalloc(E1, ...)\|pci_alloc_consistent(...,E1,...)\|
+  kvmalloc_node(E1,...)\);
+  if ((x==NULL) || ...) S
+* memset((T2)x,0,E1);
+
+//----------------------------------------------------------
+//  For patch mode
+//----------------------------------------------------------
+
+@depends on patch@
+type T, T2;
+expression x;
+expression E1,E2,E3,E4;
+statement S;
+@@
+
+(
+- x = kmalloc(E1,E2);
++ x = kzalloc(E1,E2);
+|
+- x = (T *)kmalloc(E1,E2);
++ x = kzalloc(E1,E2);
+|
+- x = (T)kmalloc(E1,E2);
++ x = (T)kzalloc(E1,E2);
+|
+- x = vmalloc(E1);
++ x = vzalloc(E1);
+|
+- x = (T *)vmalloc(E1);
++ x = vzalloc(E1);
+|
+- x = (T)vmalloc(E1);
++ x = (T)vzalloc(E1);
+|
+- x = dma_alloc_coherent(E2,E1,E3,E4);
++ x = dma_zalloc_coherent(E2,E1,E3,E4);
+|
+- x = (T *)dma_alloc_coherent(E2,E1,E3,E4);
++ x = dma_zalloc_coherent(E2,E1,E3,E4);
+|
+- x = (T)dma_alloc_coherent(E2,E1,E3,E4);
++ x = (T)dma_zalloc_coherent(E2,E1,E3,E4);
+|
+- x = kmalloc_node(E1,E2,E3);
++ x = kzalloc_node(E1,E2,E3);
+|
+- x = (T *)kmalloc_node(E1,E2,E3);
++ x = kzalloc_node(E1,E2,E3);
+|
+- x = (T)kmalloc_node(E1,E2,E3);
++ x = (T)kzalloc_node(E1,E2,E3);
+|
+- x = kmem_cache_alloc(E3,E4);
++ x = kmem_cache_zalloc(E3,E4);
+|
+- x = (T *)kmem_cache_alloc(E3,E4);
++ x = kmem_cache_zalloc(E3,E4);
+|
+- x = (T)kmem_cache_alloc(E3,E4);
++ x = (T)kmem_cache_zalloc(E3,E4);
+|
+- x = kmem_alloc(E1,E2);
++ x = kmem_zalloc(E1,E2);
+|
+- x = (T *)kmem_alloc(E1,E2);
++ x = kmem_zalloc(E1,E2);
+|
+- x = (T)kmem_alloc(E1,E2);
++ x = (T)kmem_zalloc(E1,E2);
+|
+- x = devm_kmalloc(E2,E1,E3);
++ x = devm_kzalloc(E2,E1,E3);
+|
+- x = (T *)devm_kmalloc(E2,E1,E3);
++ x = devm_kzalloc(E2,E1,E3);
+|
+- x = (T)devm_kmalloc(E2,E1,E3);
++ x = (T)devm_kzalloc(E2,E1,E3);
+|
+- x = kvmalloc(E1,E2);
++ x = kvzalloc(E1,E2);
+|
+- x = (T *)kvmalloc(E1,E2);
++ x = kvzalloc(E1,E2);
+|
+- x = (T)kvmalloc(E1,E2);
++ x = (T)kvzalloc(E1,E2);
+|
+- x = pci_alloc_consistent(E2,E1,E3);
++ x = pci_zalloc_consistent(E2,E1,E3);
+|
+- x = (T *)pci_alloc_consistent(E2,E1,E3);
++ x = pci_zalloc_consistent(E2,E1,E3);
+|
+- x = (T)pci_alloc_consistent(E2,E1,E3);
++ x = (T)pci_zalloc_consistent(E2,E1,E3);
+|
+- x = kvmalloc_node(E1,E2,E3);
++ x = kvzalloc_node(E1,E2,E3);
+|
+- x = (T *)kvmalloc_node(E1,E2,E3);
++ x = kvzalloc_node(E1,E2,E3);
+|
+- x = (T)kvmalloc_node(E1,E2,E3);
++ x = (T)kvzalloc_node(E1,E2,E3);
+)
+  if ((x==NULL) || ...) S
+- memset((T2)x,0,E1);
+
+//----------------------------------------------------------
+//  For org mode
+//----------------------------------------------------------
+
+@r depends on org || report@
+type T, T2;
+expression x;
+expression E1,E2;
+statement S;
+position p;
+@@
+
+ x = (T)kmalloc@p(E1,E2);
+ if ((x==NULL) || ...) S
+ memset((T2)x,0,E1);
+
+@script:python depends on org@
+p << r.p;
+x << r.x;
+@@
+
+msg="%s" % (x)
+msg_safe=msg.replace("[","@(").replace("]",")")
+coccilib.org.print_todo(p[0], msg_safe)
+
+@script:python depends on report@
+p << r.p;
+x << r.x;
+@@
+
+msg="WARNING: kzalloc should be used for %s, instead of kmalloc/memset" % (x)
+coccilib.report.print_report(p[0], msg)
+
+//-----------------------------------------------------------------
+@r1 depends on org || report@
+type T, T2;
+expression x;
+expression E1;
+statement S;
+position p;
+@@
+
+ x = (T)vmalloc@p(E1);
+ if ((x==NULL) || ...) S
+ memset((T2)x,0,E1);
+
+@script:python depends on org@
+p << r1.p;
+x << r1.x;
+@@
+
+msg="%s" % (x)
+msg_safe=msg.replace("[","@(").replace("]",")")
+coccilib.org.print_todo(p[0], msg_safe)
+
+@script:python depends on report@
+p << r1.p;
+x << r1.x;
+@@
+
+msg="WARNING: vzalloc should be used for %s, instead of vmalloc/memset" % (x)
+coccilib.report.print_report(p[0], msg)
+
+//-----------------------------------------------------------------
+@r2 depends on org || report@
+type T, T2;
+expression x;
+expression E1,E2,E3,E4;
+statement S;
+position p;
+@@
+
+ x = (T)dma_alloc_coherent@p(E2,E1,E3,E4);
+ if ((x==NULL) || ...) S
+ memset((T2)x,0,E1);
+
+@script:python depends on org@
+p << r2.p;
+x << r2.x;
+@@
+
+msg="%s" % (x)
+msg_safe=msg.replace("[","@(").replace("]",")")
+coccilib.org.print_todo(p[0], msg_safe)
+
+@script:python depends on report@
+p << r2.p;
+x << r2.x;
+@@
+
+msg="WARNING: dma_zalloc_coherent should be used for %s, instead of dma_alloc_coherent/memset" % (x)
+coccilib.report.print_report(p[0], msg)
+
+//-----------------------------------------------------------------
+@r3 depends on org || report@
+type T, T2;
+expression x;
+expression E1,E2,E3;
+statement S;
+position p;
+@@
+
+ x = (T)kmalloc_node@p(E1,E2,E3);
+ if ((x==NULL) || ...) S
+ memset((T2)x,0,E1);
+
+@script:python depends on org@
+p << r3.p;
+x << r3.x;
+@@
+
+msg="%s" % (x)
+msg_safe=msg.replace("[","@(").replace("]",")")
+coccilib.org.print_todo(p[0], msg_safe)
+
+@script:python depends on report@
+p << r3.p;
+x << r3.x;
+@@
+
+msg="WARNING: kzalloc_node should be used for %s, instead of kmalloc_node/memset" % (x)
+coccilib.report.print_report(p[0], msg)
+
+//-----------------------------------------------------------------
+@r4 depends on org || report@
+type T, T2;
+expression x;
+expression E1,E2,E3;
+statement S;
+position p;
+@@
+
+ x = (T)kmem_cache_alloc@p(E2,E3);
+ if ((x==NULL) || ...) S
+ memset((T2)x,0,E1);
+
+@script:python depends on org@
+p << r4.p;
+x << r4.x;
+@@
+
+msg="%s" % (x)
+msg_safe=msg.replace("[","@(").replace("]",")")
+coccilib.org.print_todo(p[0], msg_safe)
+
+@script:python depends on report@
+p << r4.p;
+x << r4.x;
+@@
+
+msg="WARNING: kmem_cache_zalloc should be used for %s, instead of kmem_cache_alloc/memset" % (x)
+coccilib.report.print_report(p[0], msg)
+
+//-----------------------------------------------------------------
+@r5 depends on org || report@
+type T, T2;
+expression x;
+expression E1,E2;
+statement S;
+position p;
+@@
+
+ x = (T)kmem_alloc@p(E1,E2);
+ if ((x==NULL) || ...) S
+ memset((T2)x,0,E1);
+
+@script:python depends on org@
+p << r5.p;
+x << r5.x;
+@@
+
+msg="%s" % (x)
+msg_safe=msg.replace("[","@(").replace("]",")")
+coccilib.org.print_todo(p[0], msg_safe)
+
+@script:python depends on report@
+p << r5.p;
+x << r5.x;
+@@
+
+msg="WARNING: kmem_zalloc should be used for %s, instead of kmem_alloc/memset" % (x)
+coccilib.report.print_report(p[0], msg)
+
+//-----------------------------------------------------------------
+@r6 depends on org || report@
+type T, T2;
+expression x;
+expression E1,E2,E3;
+statement S;
+position p;
+@@
+
+ x = (T)devm_kmalloc@p(E2,E1,E3);
+ if ((x==NULL) || ...) S
+ memset((T2)x,0,E1);
+
+@script:python depends on org@
+p << r6.p;
+x << r6.x;
+@@
+
+msg="%s" % (x)
+msg_safe=msg.replace("[","@(").replace("]",")")
+coccilib.org.print_todo(p[0], msg_safe)
+
+@script:python depends on report@
+p << r6.p;
+x << r6.x;
+@@
+
+msg="WARNING: devm_kzalloc should be used for %s, instead of devm_kmalloc/memset" % (x)
+coccilib.report.print_report(p[0], msg)
+
+//-----------------------------------------------------------------
+@r7 depends on org || report@
+type T, T2;
+expression x;
+expression E1,E2;
+statement S;
+position p;
+@@
+
+ x = (T)kvmalloc@p(E1,E2);
+ if ((x==NULL) || ...) S
+ memset((T2)x,0,E1);
+
+@script:python depends on org@
+p << r7.p;
+x << r7.x;
+@@
+
+msg="%s" % (x)
+msg_safe=msg.replace("[","@(").replace("]",")")
+coccilib.org.print_todo(p[0], msg_safe)
+
+@script:python depends on report@
+p << r7.p;
+x << r7.x;
+@@
+
+msg="WARNING: kvzalloc should be used for %s, instead of kvmalloc/memset" % (x)
+coccilib.report.print_report(p[0], msg)
+
+//-----------------------------------------------------------------
+@r8 depends on org || report@
+type T, T2;
+expression x;
+expression E1,E2,E3;
+statement S;
+position p;
+@@
+
+ x = (T)pci_alloc_consistent@p(E2,E1,E3);
+ if ((x==NULL) || ...) S
+ memset((T2)x,0,E1);
+
+@script:python depends on org@
+p << r8.p;
+x << r8.x;
+@@
+
+msg="%s" % (x)
+msg_safe=msg.replace("[","@(").replace("]",")")
+coccilib.org.print_todo(p[0], msg_safe)
+
+@script:python depends on report@
+p << r8.p;
+x << r8.x;
+@@
+
+msg="WARNING: pci_zalloc_consistent should be used for %s, instead of pci_alloc_consistent/memset" % (x)
+coccilib.report.print_report(p[0], msg)
+//-----------------------------------------------------------------
+@r9 depends on org || report@
+type T, T2;
+expression x;
+expression E1,E2,E3;
+statement S;
+position p;
+@@
+
+ x = (T)kvmalloc_node@p(E1,E2,E3);
+ if ((x==NULL) || ...) S
+ memset((T2)x,0,E1);
+
+@script:python depends on org@
+p << r9.p;
+x << r9.x;
+@@
+
+msg="%s" % (x)
+msg_safe=msg.replace("[","@(").replace("]",")")
+coccilib.org.print_todo(p[0], msg_safe)
+
+@script:python depends on report@
+p << r9.p;
+x << r9.x;
+@@
+
+msg="WARNING: kvzalloc_node should be used for %s, instead of kvmalloc_node/memset" % (x)
+coccilib.report.print_report(p[0], msg)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] Coccinelle: kzalloc-simple: Rename kzalloc-simple to zalloc-simple
  2018-01-13 15:57 [PATCH] Coccinelle: kzalloc-simple: Rename kzalloc-simple to zalloc-simple Himanshu Jha
@ 2018-01-13 16:27 ` Julia Lawall
  2018-01-13 17:02 ` [Cocci] " Fabio Estevam
  1 sibling, 0 replies; 6+ messages in thread
From: Julia Lawall @ 2018-01-13 16:27 UTC (permalink / raw)
  To: Himanshu Jha
  Cc: yamada.masahiro, Julia.Lawall, Gilles Muller, nicolas.palix,
	michal.lkml, cocci, linux-kernel



On Sat, 13 Jan 2018, Himanshu Jha wrote:

> Rename kzalloc-simple to zalloc-simple since now the rule is not
> specific to kzalloc function only, but also to many other zero memory
> allocating functions specified in the rule.
>
> Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com>

Acked-by: Julia Lawall <julia.lawall@lip6.fr>

> ---
>  scripts/coccinelle/api/alloc/kzalloc-simple.cocci | 448 ----------------------
>  scripts/coccinelle/api/alloc/zalloc.cocci         | 448 ++++++++++++++++++++++
>  2 files changed, 448 insertions(+), 448 deletions(-)
>  delete mode 100644 scripts/coccinelle/api/alloc/kzalloc-simple.cocci
>  create mode 100644 scripts/coccinelle/api/alloc/zalloc.cocci
>
> diff --git a/scripts/coccinelle/api/alloc/kzalloc-simple.cocci b/scripts/coccinelle/api/alloc/kzalloc-simple.cocci
> deleted file mode 100644
> index 92b2091..0000000
> --- a/scripts/coccinelle/api/alloc/kzalloc-simple.cocci
> +++ /dev/null
> @@ -1,448 +0,0 @@
> -///
> -/// Use zeroing allocator rather than allocator followed by memset with 0
> -///
> -/// This considers some simple cases that are common and easy to validate
> -/// Note in particular that there are no ...s in the rule, so all of the
> -/// matched code has to be contiguous
> -///
> -// Confidence: High
> -// Copyright: (C) 2009-2010 Julia Lawall, Nicolas Palix, DIKU.  GPLv2.
> -// Copyright: (C) 2009-2010 Gilles Muller, INRIA/LiP6.  GPLv2.
> -// Copyright: (C) 2017 Himanshu Jha GPLv2.
> -// URL: http://coccinelle.lip6.fr/rules/kzalloc.html
> -// Options: --no-includes --include-headers
> -//
> -// Keywords: kmalloc, kzalloc
> -// Version min: < 2.6.12 kmalloc
> -// Version min:   2.6.14 kzalloc
> -//
> -
> -virtual context
> -virtual patch
> -virtual org
> -virtual report
> -
> -//----------------------------------------------------------
> -//  For context mode
> -//----------------------------------------------------------
> -
> -@depends on context@
> -type T, T2;
> -expression x;
> -expression E1;
> -statement S;
> -@@
> -
> -* x = (T)\(kmalloc(E1, ...)\|vmalloc(E1)\|dma_alloc_coherent(...,E1,...)\|
> -  kmalloc_node(E1, ...)\|kmem_cache_alloc(...)\|kmem_alloc(E1, ...)\|
> -  devm_kmalloc(...,E1,...)\|kvmalloc(E1, ...)\|pci_alloc_consistent(...,E1,...)\|
> -  kvmalloc_node(E1,...)\);
> -  if ((x==NULL) || ...) S
> -* memset((T2)x,0,E1);
> -
> -//----------------------------------------------------------
> -//  For patch mode
> -//----------------------------------------------------------
> -
> -@depends on patch@
> -type T, T2;
> -expression x;
> -expression E1,E2,E3,E4;
> -statement S;
> -@@
> -
> -(
> -- x = kmalloc(E1,E2);
> -+ x = kzalloc(E1,E2);
> -|
> -- x = (T *)kmalloc(E1,E2);
> -+ x = kzalloc(E1,E2);
> -|
> -- x = (T)kmalloc(E1,E2);
> -+ x = (T)kzalloc(E1,E2);
> -|
> -- x = vmalloc(E1);
> -+ x = vzalloc(E1);
> -|
> -- x = (T *)vmalloc(E1);
> -+ x = vzalloc(E1);
> -|
> -- x = (T)vmalloc(E1);
> -+ x = (T)vzalloc(E1);
> -|
> -- x = dma_alloc_coherent(E2,E1,E3,E4);
> -+ x = dma_zalloc_coherent(E2,E1,E3,E4);
> -|
> -- x = (T *)dma_alloc_coherent(E2,E1,E3,E4);
> -+ x = dma_zalloc_coherent(E2,E1,E3,E4);
> -|
> -- x = (T)dma_alloc_coherent(E2,E1,E3,E4);
> -+ x = (T)dma_zalloc_coherent(E2,E1,E3,E4);
> -|
> -- x = kmalloc_node(E1,E2,E3);
> -+ x = kzalloc_node(E1,E2,E3);
> -|
> -- x = (T *)kmalloc_node(E1,E2,E3);
> -+ x = kzalloc_node(E1,E2,E3);
> -|
> -- x = (T)kmalloc_node(E1,E2,E3);
> -+ x = (T)kzalloc_node(E1,E2,E3);
> -|
> -- x = kmem_cache_alloc(E3,E4);
> -+ x = kmem_cache_zalloc(E3,E4);
> -|
> -- x = (T *)kmem_cache_alloc(E3,E4);
> -+ x = kmem_cache_zalloc(E3,E4);
> -|
> -- x = (T)kmem_cache_alloc(E3,E4);
> -+ x = (T)kmem_cache_zalloc(E3,E4);
> -|
> -- x = kmem_alloc(E1,E2);
> -+ x = kmem_zalloc(E1,E2);
> -|
> -- x = (T *)kmem_alloc(E1,E2);
> -+ x = kmem_zalloc(E1,E2);
> -|
> -- x = (T)kmem_alloc(E1,E2);
> -+ x = (T)kmem_zalloc(E1,E2);
> -|
> -- x = devm_kmalloc(E2,E1,E3);
> -+ x = devm_kzalloc(E2,E1,E3);
> -|
> -- x = (T *)devm_kmalloc(E2,E1,E3);
> -+ x = devm_kzalloc(E2,E1,E3);
> -|
> -- x = (T)devm_kmalloc(E2,E1,E3);
> -+ x = (T)devm_kzalloc(E2,E1,E3);
> -|
> -- x = kvmalloc(E1,E2);
> -+ x = kvzalloc(E1,E2);
> -|
> -- x = (T *)kvmalloc(E1,E2);
> -+ x = kvzalloc(E1,E2);
> -|
> -- x = (T)kvmalloc(E1,E2);
> -+ x = (T)kvzalloc(E1,E2);
> -|
> -- x = pci_alloc_consistent(E2,E1,E3);
> -+ x = pci_zalloc_consistent(E2,E1,E3);
> -|
> -- x = (T *)pci_alloc_consistent(E2,E1,E3);
> -+ x = pci_zalloc_consistent(E2,E1,E3);
> -|
> -- x = (T)pci_alloc_consistent(E2,E1,E3);
> -+ x = (T)pci_zalloc_consistent(E2,E1,E3);
> -|
> -- x = kvmalloc_node(E1,E2,E3);
> -+ x = kvzalloc_node(E1,E2,E3);
> -|
> -- x = (T *)kvmalloc_node(E1,E2,E3);
> -+ x = kvzalloc_node(E1,E2,E3);
> -|
> -- x = (T)kvmalloc_node(E1,E2,E3);
> -+ x = (T)kvzalloc_node(E1,E2,E3);
> -)
> -  if ((x==NULL) || ...) S
> -- memset((T2)x,0,E1);
> -
> -//----------------------------------------------------------
> -//  For org mode
> -//----------------------------------------------------------
> -
> -@r depends on org || report@
> -type T, T2;
> -expression x;
> -expression E1,E2;
> -statement S;
> -position p;
> -@@
> -
> - x = (T)kmalloc@p(E1,E2);
> - if ((x==NULL) || ...) S
> - memset((T2)x,0,E1);
> -
> -@script:python depends on org@
> -p << r.p;
> -x << r.x;
> -@@
> -
> -msg="%s" % (x)
> -msg_safe=msg.replace("[","@(").replace("]",")")
> -coccilib.org.print_todo(p[0], msg_safe)
> -
> -@script:python depends on report@
> -p << r.p;
> -x << r.x;
> -@@
> -
> -msg="WARNING: kzalloc should be used for %s, instead of kmalloc/memset" % (x)
> -coccilib.report.print_report(p[0], msg)
> -
> -//-----------------------------------------------------------------
> -@r1 depends on org || report@
> -type T, T2;
> -expression x;
> -expression E1;
> -statement S;
> -position p;
> -@@
> -
> - x = (T)vmalloc@p(E1);
> - if ((x==NULL) || ...) S
> - memset((T2)x,0,E1);
> -
> -@script:python depends on org@
> -p << r1.p;
> -x << r1.x;
> -@@
> -
> -msg="%s" % (x)
> -msg_safe=msg.replace("[","@(").replace("]",")")
> -coccilib.org.print_todo(p[0], msg_safe)
> -
> -@script:python depends on report@
> -p << r1.p;
> -x << r1.x;
> -@@
> -
> -msg="WARNING: vzalloc should be used for %s, instead of vmalloc/memset" % (x)
> -coccilib.report.print_report(p[0], msg)
> -
> -//-----------------------------------------------------------------
> -@r2 depends on org || report@
> -type T, T2;
> -expression x;
> -expression E1,E2,E3,E4;
> -statement S;
> -position p;
> -@@
> -
> - x = (T)dma_alloc_coherent@p(E2,E1,E3,E4);
> - if ((x==NULL) || ...) S
> - memset((T2)x,0,E1);
> -
> -@script:python depends on org@
> -p << r2.p;
> -x << r2.x;
> -@@
> -
> -msg="%s" % (x)
> -msg_safe=msg.replace("[","@(").replace("]",")")
> -coccilib.org.print_todo(p[0], msg_safe)
> -
> -@script:python depends on report@
> -p << r2.p;
> -x << r2.x;
> -@@
> -
> -msg="WARNING: dma_zalloc_coherent should be used for %s, instead of dma_alloc_coherent/memset" % (x)
> -coccilib.report.print_report(p[0], msg)
> -
> -//-----------------------------------------------------------------
> -@r3 depends on org || report@
> -type T, T2;
> -expression x;
> -expression E1,E2,E3;
> -statement S;
> -position p;
> -@@
> -
> - x = (T)kmalloc_node@p(E1,E2,E3);
> - if ((x==NULL) || ...) S
> - memset((T2)x,0,E1);
> -
> -@script:python depends on org@
> -p << r3.p;
> -x << r3.x;
> -@@
> -
> -msg="%s" % (x)
> -msg_safe=msg.replace("[","@(").replace("]",")")
> -coccilib.org.print_todo(p[0], msg_safe)
> -
> -@script:python depends on report@
> -p << r3.p;
> -x << r3.x;
> -@@
> -
> -msg="WARNING: kzalloc_node should be used for %s, instead of kmalloc_node/memset" % (x)
> -coccilib.report.print_report(p[0], msg)
> -
> -//-----------------------------------------------------------------
> -@r4 depends on org || report@
> -type T, T2;
> -expression x;
> -expression E1,E2,E3;
> -statement S;
> -position p;
> -@@
> -
> - x = (T)kmem_cache_alloc@p(E2,E3);
> - if ((x==NULL) || ...) S
> - memset((T2)x,0,E1);
> -
> -@script:python depends on org@
> -p << r4.p;
> -x << r4.x;
> -@@
> -
> -msg="%s" % (x)
> -msg_safe=msg.replace("[","@(").replace("]",")")
> -coccilib.org.print_todo(p[0], msg_safe)
> -
> -@script:python depends on report@
> -p << r4.p;
> -x << r4.x;
> -@@
> -
> -msg="WARNING: kmem_cache_zalloc should be used for %s, instead of kmem_cache_alloc/memset" % (x)
> -coccilib.report.print_report(p[0], msg)
> -
> -//-----------------------------------------------------------------
> -@r5 depends on org || report@
> -type T, T2;
> -expression x;
> -expression E1,E2;
> -statement S;
> -position p;
> -@@
> -
> - x = (T)kmem_alloc@p(E1,E2);
> - if ((x==NULL) || ...) S
> - memset((T2)x,0,E1);
> -
> -@script:python depends on org@
> -p << r5.p;
> -x << r5.x;
> -@@
> -
> -msg="%s" % (x)
> -msg_safe=msg.replace("[","@(").replace("]",")")
> -coccilib.org.print_todo(p[0], msg_safe)
> -
> -@script:python depends on report@
> -p << r5.p;
> -x << r5.x;
> -@@
> -
> -msg="WARNING: kmem_zalloc should be used for %s, instead of kmem_alloc/memset" % (x)
> -coccilib.report.print_report(p[0], msg)
> -
> -//-----------------------------------------------------------------
> -@r6 depends on org || report@
> -type T, T2;
> -expression x;
> -expression E1,E2,E3;
> -statement S;
> -position p;
> -@@
> -
> - x = (T)devm_kmalloc@p(E2,E1,E3);
> - if ((x==NULL) || ...) S
> - memset((T2)x,0,E1);
> -
> -@script:python depends on org@
> -p << r6.p;
> -x << r6.x;
> -@@
> -
> -msg="%s" % (x)
> -msg_safe=msg.replace("[","@(").replace("]",")")
> -coccilib.org.print_todo(p[0], msg_safe)
> -
> -@script:python depends on report@
> -p << r6.p;
> -x << r6.x;
> -@@
> -
> -msg="WARNING: devm_kzalloc should be used for %s, instead of devm_kmalloc/memset" % (x)
> -coccilib.report.print_report(p[0], msg)
> -
> -//-----------------------------------------------------------------
> -@r7 depends on org || report@
> -type T, T2;
> -expression x;
> -expression E1,E2;
> -statement S;
> -position p;
> -@@
> -
> - x = (T)kvmalloc@p(E1,E2);
> - if ((x==NULL) || ...) S
> - memset((T2)x,0,E1);
> -
> -@script:python depends on org@
> -p << r7.p;
> -x << r7.x;
> -@@
> -
> -msg="%s" % (x)
> -msg_safe=msg.replace("[","@(").replace("]",")")
> -coccilib.org.print_todo(p[0], msg_safe)
> -
> -@script:python depends on report@
> -p << r7.p;
> -x << r7.x;
> -@@
> -
> -msg="WARNING: kvzalloc should be used for %s, instead of kvmalloc/memset" % (x)
> -coccilib.report.print_report(p[0], msg)
> -
> -//-----------------------------------------------------------------
> -@r8 depends on org || report@
> -type T, T2;
> -expression x;
> -expression E1,E2,E3;
> -statement S;
> -position p;
> -@@
> -
> - x = (T)pci_alloc_consistent@p(E2,E1,E3);
> - if ((x==NULL) || ...) S
> - memset((T2)x,0,E1);
> -
> -@script:python depends on org@
> -p << r8.p;
> -x << r8.x;
> -@@
> -
> -msg="%s" % (x)
> -msg_safe=msg.replace("[","@(").replace("]",")")
> -coccilib.org.print_todo(p[0], msg_safe)
> -
> -@script:python depends on report@
> -p << r8.p;
> -x << r8.x;
> -@@
> -
> -msg="WARNING: pci_zalloc_consistent should be used for %s, instead of pci_alloc_consistent/memset" % (x)
> -coccilib.report.print_report(p[0], msg)
> -//-----------------------------------------------------------------
> -@r9 depends on org || report@
> -type T, T2;
> -expression x;
> -expression E1,E2,E3;
> -statement S;
> -position p;
> -@@
> -
> - x = (T)kvmalloc_node@p(E1,E2,E3);
> - if ((x==NULL) || ...) S
> - memset((T2)x,0,E1);
> -
> -@script:python depends on org@
> -p << r9.p;
> -x << r9.x;
> -@@
> -
> -msg="%s" % (x)
> -msg_safe=msg.replace("[","@(").replace("]",")")
> -coccilib.org.print_todo(p[0], msg_safe)
> -
> -@script:python depends on report@
> -p << r9.p;
> -x << r9.x;
> -@@
> -
> -msg="WARNING: kvzalloc_node should be used for %s, instead of kvmalloc_node/memset" % (x)
> -coccilib.report.print_report(p[0], msg)
> diff --git a/scripts/coccinelle/api/alloc/zalloc.cocci b/scripts/coccinelle/api/alloc/zalloc.cocci
> new file mode 100644
> index 0000000..92b2091
> --- /dev/null
> +++ b/scripts/coccinelle/api/alloc/zalloc.cocci
> @@ -0,0 +1,448 @@
> +///
> +/// Use zeroing allocator rather than allocator followed by memset with 0
> +///
> +/// This considers some simple cases that are common and easy to validate
> +/// Note in particular that there are no ...s in the rule, so all of the
> +/// matched code has to be contiguous
> +///
> +// Confidence: High
> +// Copyright: (C) 2009-2010 Julia Lawall, Nicolas Palix, DIKU.  GPLv2.
> +// Copyright: (C) 2009-2010 Gilles Muller, INRIA/LiP6.  GPLv2.
> +// Copyright: (C) 2017 Himanshu Jha GPLv2.
> +// URL: http://coccinelle.lip6.fr/rules/kzalloc.html
> +// Options: --no-includes --include-headers
> +//
> +// Keywords: kmalloc, kzalloc
> +// Version min: < 2.6.12 kmalloc
> +// Version min:   2.6.14 kzalloc
> +//
> +
> +virtual context
> +virtual patch
> +virtual org
> +virtual report
> +
> +//----------------------------------------------------------
> +//  For context mode
> +//----------------------------------------------------------
> +
> +@depends on context@
> +type T, T2;
> +expression x;
> +expression E1;
> +statement S;
> +@@
> +
> +* x = (T)\(kmalloc(E1, ...)\|vmalloc(E1)\|dma_alloc_coherent(...,E1,...)\|
> +  kmalloc_node(E1, ...)\|kmem_cache_alloc(...)\|kmem_alloc(E1, ...)\|
> +  devm_kmalloc(...,E1,...)\|kvmalloc(E1, ...)\|pci_alloc_consistent(...,E1,...)\|
> +  kvmalloc_node(E1,...)\);
> +  if ((x==NULL) || ...) S
> +* memset((T2)x,0,E1);
> +
> +//----------------------------------------------------------
> +//  For patch mode
> +//----------------------------------------------------------
> +
> +@depends on patch@
> +type T, T2;
> +expression x;
> +expression E1,E2,E3,E4;
> +statement S;
> +@@
> +
> +(
> +- x = kmalloc(E1,E2);
> ++ x = kzalloc(E1,E2);
> +|
> +- x = (T *)kmalloc(E1,E2);
> ++ x = kzalloc(E1,E2);
> +|
> +- x = (T)kmalloc(E1,E2);
> ++ x = (T)kzalloc(E1,E2);
> +|
> +- x = vmalloc(E1);
> ++ x = vzalloc(E1);
> +|
> +- x = (T *)vmalloc(E1);
> ++ x = vzalloc(E1);
> +|
> +- x = (T)vmalloc(E1);
> ++ x = (T)vzalloc(E1);
> +|
> +- x = dma_alloc_coherent(E2,E1,E3,E4);
> ++ x = dma_zalloc_coherent(E2,E1,E3,E4);
> +|
> +- x = (T *)dma_alloc_coherent(E2,E1,E3,E4);
> ++ x = dma_zalloc_coherent(E2,E1,E3,E4);
> +|
> +- x = (T)dma_alloc_coherent(E2,E1,E3,E4);
> ++ x = (T)dma_zalloc_coherent(E2,E1,E3,E4);
> +|
> +- x = kmalloc_node(E1,E2,E3);
> ++ x = kzalloc_node(E1,E2,E3);
> +|
> +- x = (T *)kmalloc_node(E1,E2,E3);
> ++ x = kzalloc_node(E1,E2,E3);
> +|
> +- x = (T)kmalloc_node(E1,E2,E3);
> ++ x = (T)kzalloc_node(E1,E2,E3);
> +|
> +- x = kmem_cache_alloc(E3,E4);
> ++ x = kmem_cache_zalloc(E3,E4);
> +|
> +- x = (T *)kmem_cache_alloc(E3,E4);
> ++ x = kmem_cache_zalloc(E3,E4);
> +|
> +- x = (T)kmem_cache_alloc(E3,E4);
> ++ x = (T)kmem_cache_zalloc(E3,E4);
> +|
> +- x = kmem_alloc(E1,E2);
> ++ x = kmem_zalloc(E1,E2);
> +|
> +- x = (T *)kmem_alloc(E1,E2);
> ++ x = kmem_zalloc(E1,E2);
> +|
> +- x = (T)kmem_alloc(E1,E2);
> ++ x = (T)kmem_zalloc(E1,E2);
> +|
> +- x = devm_kmalloc(E2,E1,E3);
> ++ x = devm_kzalloc(E2,E1,E3);
> +|
> +- x = (T *)devm_kmalloc(E2,E1,E3);
> ++ x = devm_kzalloc(E2,E1,E3);
> +|
> +- x = (T)devm_kmalloc(E2,E1,E3);
> ++ x = (T)devm_kzalloc(E2,E1,E3);
> +|
> +- x = kvmalloc(E1,E2);
> ++ x = kvzalloc(E1,E2);
> +|
> +- x = (T *)kvmalloc(E1,E2);
> ++ x = kvzalloc(E1,E2);
> +|
> +- x = (T)kvmalloc(E1,E2);
> ++ x = (T)kvzalloc(E1,E2);
> +|
> +- x = pci_alloc_consistent(E2,E1,E3);
> ++ x = pci_zalloc_consistent(E2,E1,E3);
> +|
> +- x = (T *)pci_alloc_consistent(E2,E1,E3);
> ++ x = pci_zalloc_consistent(E2,E1,E3);
> +|
> +- x = (T)pci_alloc_consistent(E2,E1,E3);
> ++ x = (T)pci_zalloc_consistent(E2,E1,E3);
> +|
> +- x = kvmalloc_node(E1,E2,E3);
> ++ x = kvzalloc_node(E1,E2,E3);
> +|
> +- x = (T *)kvmalloc_node(E1,E2,E3);
> ++ x = kvzalloc_node(E1,E2,E3);
> +|
> +- x = (T)kvmalloc_node(E1,E2,E3);
> ++ x = (T)kvzalloc_node(E1,E2,E3);
> +)
> +  if ((x==NULL) || ...) S
> +- memset((T2)x,0,E1);
> +
> +//----------------------------------------------------------
> +//  For org mode
> +//----------------------------------------------------------
> +
> +@r depends on org || report@
> +type T, T2;
> +expression x;
> +expression E1,E2;
> +statement S;
> +position p;
> +@@
> +
> + x = (T)kmalloc@p(E1,E2);
> + if ((x==NULL) || ...) S
> + memset((T2)x,0,E1);
> +
> +@script:python depends on org@
> +p << r.p;
> +x << r.x;
> +@@
> +
> +msg="%s" % (x)
> +msg_safe=msg.replace("[","@(").replace("]",")")
> +coccilib.org.print_todo(p[0], msg_safe)
> +
> +@script:python depends on report@
> +p << r.p;
> +x << r.x;
> +@@
> +
> +msg="WARNING: kzalloc should be used for %s, instead of kmalloc/memset" % (x)
> +coccilib.report.print_report(p[0], msg)
> +
> +//-----------------------------------------------------------------
> +@r1 depends on org || report@
> +type T, T2;
> +expression x;
> +expression E1;
> +statement S;
> +position p;
> +@@
> +
> + x = (T)vmalloc@p(E1);
> + if ((x==NULL) || ...) S
> + memset((T2)x,0,E1);
> +
> +@script:python depends on org@
> +p << r1.p;
> +x << r1.x;
> +@@
> +
> +msg="%s" % (x)
> +msg_safe=msg.replace("[","@(").replace("]",")")
> +coccilib.org.print_todo(p[0], msg_safe)
> +
> +@script:python depends on report@
> +p << r1.p;
> +x << r1.x;
> +@@
> +
> +msg="WARNING: vzalloc should be used for %s, instead of vmalloc/memset" % (x)
> +coccilib.report.print_report(p[0], msg)
> +
> +//-----------------------------------------------------------------
> +@r2 depends on org || report@
> +type T, T2;
> +expression x;
> +expression E1,E2,E3,E4;
> +statement S;
> +position p;
> +@@
> +
> + x = (T)dma_alloc_coherent@p(E2,E1,E3,E4);
> + if ((x==NULL) || ...) S
> + memset((T2)x,0,E1);
> +
> +@script:python depends on org@
> +p << r2.p;
> +x << r2.x;
> +@@
> +
> +msg="%s" % (x)
> +msg_safe=msg.replace("[","@(").replace("]",")")
> +coccilib.org.print_todo(p[0], msg_safe)
> +
> +@script:python depends on report@
> +p << r2.p;
> +x << r2.x;
> +@@
> +
> +msg="WARNING: dma_zalloc_coherent should be used for %s, instead of dma_alloc_coherent/memset" % (x)
> +coccilib.report.print_report(p[0], msg)
> +
> +//-----------------------------------------------------------------
> +@r3 depends on org || report@
> +type T, T2;
> +expression x;
> +expression E1,E2,E3;
> +statement S;
> +position p;
> +@@
> +
> + x = (T)kmalloc_node@p(E1,E2,E3);
> + if ((x==NULL) || ...) S
> + memset((T2)x,0,E1);
> +
> +@script:python depends on org@
> +p << r3.p;
> +x << r3.x;
> +@@
> +
> +msg="%s" % (x)
> +msg_safe=msg.replace("[","@(").replace("]",")")
> +coccilib.org.print_todo(p[0], msg_safe)
> +
> +@script:python depends on report@
> +p << r3.p;
> +x << r3.x;
> +@@
> +
> +msg="WARNING: kzalloc_node should be used for %s, instead of kmalloc_node/memset" % (x)
> +coccilib.report.print_report(p[0], msg)
> +
> +//-----------------------------------------------------------------
> +@r4 depends on org || report@
> +type T, T2;
> +expression x;
> +expression E1,E2,E3;
> +statement S;
> +position p;
> +@@
> +
> + x = (T)kmem_cache_alloc@p(E2,E3);
> + if ((x==NULL) || ...) S
> + memset((T2)x,0,E1);
> +
> +@script:python depends on org@
> +p << r4.p;
> +x << r4.x;
> +@@
> +
> +msg="%s" % (x)
> +msg_safe=msg.replace("[","@(").replace("]",")")
> +coccilib.org.print_todo(p[0], msg_safe)
> +
> +@script:python depends on report@
> +p << r4.p;
> +x << r4.x;
> +@@
> +
> +msg="WARNING: kmem_cache_zalloc should be used for %s, instead of kmem_cache_alloc/memset" % (x)
> +coccilib.report.print_report(p[0], msg)
> +
> +//-----------------------------------------------------------------
> +@r5 depends on org || report@
> +type T, T2;
> +expression x;
> +expression E1,E2;
> +statement S;
> +position p;
> +@@
> +
> + x = (T)kmem_alloc@p(E1,E2);
> + if ((x==NULL) || ...) S
> + memset((T2)x,0,E1);
> +
> +@script:python depends on org@
> +p << r5.p;
> +x << r5.x;
> +@@
> +
> +msg="%s" % (x)
> +msg_safe=msg.replace("[","@(").replace("]",")")
> +coccilib.org.print_todo(p[0], msg_safe)
> +
> +@script:python depends on report@
> +p << r5.p;
> +x << r5.x;
> +@@
> +
> +msg="WARNING: kmem_zalloc should be used for %s, instead of kmem_alloc/memset" % (x)
> +coccilib.report.print_report(p[0], msg)
> +
> +//-----------------------------------------------------------------
> +@r6 depends on org || report@
> +type T, T2;
> +expression x;
> +expression E1,E2,E3;
> +statement S;
> +position p;
> +@@
> +
> + x = (T)devm_kmalloc@p(E2,E1,E3);
> + if ((x==NULL) || ...) S
> + memset((T2)x,0,E1);
> +
> +@script:python depends on org@
> +p << r6.p;
> +x << r6.x;
> +@@
> +
> +msg="%s" % (x)
> +msg_safe=msg.replace("[","@(").replace("]",")")
> +coccilib.org.print_todo(p[0], msg_safe)
> +
> +@script:python depends on report@
> +p << r6.p;
> +x << r6.x;
> +@@
> +
> +msg="WARNING: devm_kzalloc should be used for %s, instead of devm_kmalloc/memset" % (x)
> +coccilib.report.print_report(p[0], msg)
> +
> +//-----------------------------------------------------------------
> +@r7 depends on org || report@
> +type T, T2;
> +expression x;
> +expression E1,E2;
> +statement S;
> +position p;
> +@@
> +
> + x = (T)kvmalloc@p(E1,E2);
> + if ((x==NULL) || ...) S
> + memset((T2)x,0,E1);
> +
> +@script:python depends on org@
> +p << r7.p;
> +x << r7.x;
> +@@
> +
> +msg="%s" % (x)
> +msg_safe=msg.replace("[","@(").replace("]",")")
> +coccilib.org.print_todo(p[0], msg_safe)
> +
> +@script:python depends on report@
> +p << r7.p;
> +x << r7.x;
> +@@
> +
> +msg="WARNING: kvzalloc should be used for %s, instead of kvmalloc/memset" % (x)
> +coccilib.report.print_report(p[0], msg)
> +
> +//-----------------------------------------------------------------
> +@r8 depends on org || report@
> +type T, T2;
> +expression x;
> +expression E1,E2,E3;
> +statement S;
> +position p;
> +@@
> +
> + x = (T)pci_alloc_consistent@p(E2,E1,E3);
> + if ((x==NULL) || ...) S
> + memset((T2)x,0,E1);
> +
> +@script:python depends on org@
> +p << r8.p;
> +x << r8.x;
> +@@
> +
> +msg="%s" % (x)
> +msg_safe=msg.replace("[","@(").replace("]",")")
> +coccilib.org.print_todo(p[0], msg_safe)
> +
> +@script:python depends on report@
> +p << r8.p;
> +x << r8.x;
> +@@
> +
> +msg="WARNING: pci_zalloc_consistent should be used for %s, instead of pci_alloc_consistent/memset" % (x)
> +coccilib.report.print_report(p[0], msg)
> +//-----------------------------------------------------------------
> +@r9 depends on org || report@
> +type T, T2;
> +expression x;
> +expression E1,E2,E3;
> +statement S;
> +position p;
> +@@
> +
> + x = (T)kvmalloc_node@p(E1,E2,E3);
> + if ((x==NULL) || ...) S
> + memset((T2)x,0,E1);
> +
> +@script:python depends on org@
> +p << r9.p;
> +x << r9.x;
> +@@
> +
> +msg="%s" % (x)
> +msg_safe=msg.replace("[","@(").replace("]",")")
> +coccilib.org.print_todo(p[0], msg_safe)
> +
> +@script:python depends on report@
> +p << r9.p;
> +x << r9.x;
> +@@
> +
> +msg="WARNING: kvzalloc_node should be used for %s, instead of kvmalloc_node/memset" % (x)
> +coccilib.report.print_report(p[0], msg)
> --
> 2.7.4
>
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Cocci] [PATCH] Coccinelle: kzalloc-simple: Rename kzalloc-simple to zalloc-simple
  2018-01-13 15:57 [PATCH] Coccinelle: kzalloc-simple: Rename kzalloc-simple to zalloc-simple Himanshu Jha
  2018-01-13 16:27 ` Julia Lawall
@ 2018-01-13 17:02 ` Fabio Estevam
  2018-01-13 17:53   ` Himanshu Jha
  1 sibling, 1 reply; 6+ messages in thread
From: Fabio Estevam @ 2018-01-13 17:02 UTC (permalink / raw)
  To: Himanshu Jha
  Cc: Masahiro Yamada, michal.lkml, nicolas.palix, linux-kernel, cocci

On Sat, Jan 13, 2018 at 1:57 PM, Himanshu Jha
<himanshujha199640@gmail.com> wrote:
> Rename kzalloc-simple to zalloc-simple since now the rule is not
> specific to kzalloc function only, but also to many other zero memory
> allocating functions specified in the rule.
>
> Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com>
> ---
>  scripts/coccinelle/api/alloc/kzalloc-simple.cocci | 448 ----------------------
>  scripts/coccinelle/api/alloc/zalloc.cocci         | 448 ++++++++++++++++++++++

You could use 'git mv' and 'git format -1 -M', so that git detects the rename.

Then the patch would look like this:

 scripts/coccinelle/api/alloc/{kzalloc-simple.cocci => zalloc.cocci} | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename scripts/coccinelle/api/alloc/{kzalloc-simple.cocci =>
zalloc.cocci} (100%)

diff --git a/scripts/coccinelle/api/alloc/kzalloc-simple.cocci
b/scripts/coccinelle/api/alloc/zalloc.cocci
similarity index 100%
rename from scripts/coccinelle/api/alloc/kzalloc-simple.cocci
rename to scripts/coccinelle/api/alloc/zalloc.cocci

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Cocci] [PATCH] Coccinelle: kzalloc-simple: Rename kzalloc-simple to zalloc-simple
  2018-01-13 17:02 ` [Cocci] " Fabio Estevam
@ 2018-01-13 17:53   ` Himanshu Jha
  2018-01-13 19:13     ` Fabio Estevam
  0 siblings, 1 reply; 6+ messages in thread
From: Himanshu Jha @ 2018-01-13 17:53 UTC (permalink / raw)
  To: Fabio Estevam
  Cc: Masahiro Yamada, michal.lkml, nicolas.palix, linux-kernel, cocci

On Sat, Jan 13, 2018 at 03:02:10PM -0200, Fabio Estevam wrote:
> On Sat, Jan 13, 2018 at 1:57 PM, Himanshu Jha
> <himanshujha199640@gmail.com> wrote:
> > Rename kzalloc-simple to zalloc-simple since now the rule is not
> > specific to kzalloc function only, but also to many other zero memory
> > allocating functions specified in the rule.
> >
> > Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com>
> > ---
> >  scripts/coccinelle/api/alloc/kzalloc-simple.cocci | 448 ----------------------
> >  scripts/coccinelle/api/alloc/zalloc.cocci         | 448 ++++++++++++++++++++++
> 
> You could use 'git mv' and 'git format -1 -M', so that git detects the rename.

Yes, I used 'git mv'.

It doesn't matter when applying through 'git am', both will result the
same AFAIK and only difference is that the patch files generated by 'git
format-patch' are different. But that is not important I think.

Masahiro if have any problem then please tell me, I can send again as
stated by Fabio.

-- 
Thanks
Himanshu Jha

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Cocci] [PATCH] Coccinelle: kzalloc-simple: Rename kzalloc-simple to zalloc-simple
  2018-01-13 17:53   ` Himanshu Jha
@ 2018-01-13 19:13     ` Fabio Estevam
  2018-01-13 19:52       ` Himanshu Jha
  0 siblings, 1 reply; 6+ messages in thread
From: Fabio Estevam @ 2018-01-13 19:13 UTC (permalink / raw)
  To: Himanshu Jha
  Cc: Masahiro Yamada, michal.lkml, nicolas.palix, linux-kernel, cocci

On Sat, Jan 13, 2018 at 3:53 PM, Himanshu Jha
<himanshujha199640@gmail.com> wrote:

> Yes, I used 'git mv'.
>
> It doesn't matter when applying through 'git am', both will result the
> same AFAIK and only difference is that the patch files generated by 'git
> format-patch' are different. But that is not important I think.

You missed the -M option when running 'git format'.

For reviewers it is not that easy to realize that the 448 lines of the
original file are the same as the ones in the new file.

The -M option generates a much cleaner patch.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Cocci] [PATCH] Coccinelle: kzalloc-simple: Rename kzalloc-simple to zalloc-simple
  2018-01-13 19:13     ` Fabio Estevam
@ 2018-01-13 19:52       ` Himanshu Jha
  0 siblings, 0 replies; 6+ messages in thread
From: Himanshu Jha @ 2018-01-13 19:52 UTC (permalink / raw)
  To: Fabio Estevam
  Cc: Masahiro Yamada, michal.lkml, nicolas.palix, linux-kernel, cocci

On Sat, Jan 13, 2018 at 05:13:36PM -0200, Fabio Estevam wrote:
> On Sat, Jan 13, 2018 at 3:53 PM, Himanshu Jha
> <himanshujha199640@gmail.com> wrote:
> 
> > Yes, I used 'git mv'.
> >
> > It doesn't matter when applying through 'git am', both will result the
> > same AFAIK and only difference is that the patch files generated by 'git
> > format-patch' are different. But that is not important I think.
> 
> You missed the -M option when running 'git format'.
> 
> For reviewers it is not that easy to realize that the 448 lines of the
> original file are the same as the ones in the new file.
> 
> The -M option generates a much cleaner patch.

I guess you're right because patch has many lines.
No problem, I will send again with a much cleaner patch. :-)

-- 
Thanks
Himanshu Jha

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-01-13 19:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-13 15:57 [PATCH] Coccinelle: kzalloc-simple: Rename kzalloc-simple to zalloc-simple Himanshu Jha
2018-01-13 16:27 ` Julia Lawall
2018-01-13 17:02 ` [Cocci] " Fabio Estevam
2018-01-13 17:53   ` Himanshu Jha
2018-01-13 19:13     ` Fabio Estevam
2018-01-13 19:52       ` Himanshu Jha

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).