lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1497189236-4666-1-git-send-email-Julia.Lawall@lip6.fr>
Date:   Sun, 11 Jun 2017 15:53:56 +0200
From:   Julia Lawall <Julia.Lawall@...6.fr>
To:     Julia Lawall <Julia.Lawall@...6.fr>
Cc:     kernel-janitors@...r.kernel.org,
        Gilles Muller <Gilles.Muller@...6.fr>,
        Nicolas Palix <nicolas.palix@...g.fr>,
        Michal Marek <mmarek@...e.com>, cocci@...teme.lip6.fr,
        linux-kernel@...r.kernel.org, Jonathan Cameron <jic23@...nel.org>,
        Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
        linux-iio@...r.kernel.org, Hartmut Knaack <knaack.h@....de>,
        Lars-Peter Clausen <lars@...afoo.de>,
        Peter Meerwald-Stadler <pmeerw@...erw.net>
Subject: [PATCH] scripts/coccinelle/api/gpiod_get_index.cocci: use gpiod_get variant when possible

Coccinelle script to use the shorter gpiod_get function when the third
argument to a gpiod_get_index function is 0.

This rule avoids modifying wrapper functions and cases where there is a
series of gpiod_get_index calls.

Signed-off-by: Julia Lawall <Julia.Lawall@...6.fr>

---
 scripts/coccinelle/api/gpiod_get_index.cocci |   92 +++++++++++++++++++++++++++
 1 file changed, 92 insertions(+)

diff --git a/scripts/coccinelle/api/gpiod_get_index.cocci b/scripts/coccinelle/api/gpiod_get_index.cocci
new file mode 100644
index 0000000..a670a29
--- /dev/null
+++ b/scripts/coccinelle/api/gpiod_get_index.cocci
@@ -0,0 +1,92 @@
+/// Use the shorter gpiod_get function when the third argument to a
+/// gpiod_get_index function is 0.
+//# The change might not be desired when there is a series of calls, for 0, 1,
+//# 2, etc.  This rule checks for another such call subsequently only.
+///
+// Confidence: Moderate
+// Copyright: (C) 2017 Julia Lawall, Inria. GPLv2.
+// URL: http://coccinelle.lip6.fr/
+// Options: --no-includes --include-headers
+// Keywords: gpiod_get_index
+
+virtual patch
+virtual context
+virtual org
+virtual report
+
+@...tialize:python@
+@@
+
+def not_wrapper(p):
+  return (p[0].current_element != "devm_gpiod_get_optional" and
+          p[0].current_element != "devm_gpiod_get" and
+          p[0].current_element != "gpiod_get_optional" and
+          p[0].current_element != "gpiod_get");
+
+@r depends on patch && !context && !org && !report@
+expression e1,e2,e3,e4,e5,e6,n != 0;
+position p : script:python() { not_wrapper(p) };
+@@
+
+(
+- devm_gpiod_get_index_optional@p
++ devm_gpiod_get_optional
+|
+- devm_gpiod_get_index@p
++ devm_gpiod_get
+|
+- gpiod_get_index_optional@p
++ gpiod_get_optional
+|
+- gpiod_get_index@p
++ gpiod_get
+)
+   (e1,e2,
+-   0,
+    e3)
+ ... when != devm_gpiod_get_index_optional(e4,e5,n,e6)
+     when != devm_gpiod_get_index(e4,e5,n,e6)
+     when != gpiod_get_index_optional(e4,e5,n,e6)
+     when != gpiod_get_index(e4,e5,n,e6)
+
+// ----------------------------------------------------------------------------
+
+@...ontext depends on !patch && (context || org || report) forall@
+expression e1, e2, e3, e4, e5, e6, n != 0;
+position p: script:python () { not_wrapper(p) };
+@@
+
+(
+*  devm_gpiod_get_index_optional@p
+|
+*  devm_gpiod_get_index@p
+|
+*  gpiod_get_index_optional@p
+|
+*  gpiod_get_index@p
+)
+   (e1,e2,
+*    0,
+    e3)
+ ... when != devm_gpiod_get_index_optional(e4,e5,n,e6)
+     when != devm_gpiod_get_index(e4,e5,n,e6)
+     when != gpiod_get_index_optional(e4,e5,n,e6)
+     when != gpiod_get_index(e4,e5,n,e6)
+
+// ----------------------------------------------------------------------------
+
+@...ipt:python r_org depends on org@
+p << r_context.p;
+@@
+
+msg = "Use non _index variant in 0 case."
+coccilib.org.print_todo(p[0], msg)
+
+// ----------------------------------------------------------------------------
+
+@...ipt:python r_report depends on report@
+p << r_context.p;
+@@
+
+msg = "Use non _index variant in 0 case around line %s." % (p[0].line)
+coccilib.report.print_report(p[0], msg)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ