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-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1536349307-20714-4-git-send-email-clabbe@baylibre.com>
Date:   Fri,  7 Sep 2018 19:41:45 +0000
From:   Corentin Labbe <clabbe@...libre.com>
To:     Gilles.Muller@...6.fr, Julia.Lawall@...6.fr, agust@...x.de,
        alexandre.torgue@...com, alistair@...ple.id.au,
        benh@...nel.crashing.org, carlo@...one.org, davem@...emloft.net,
        galak@...nel.crashing.org, joabreu@...opsys.com,
        khilman@...libre.com, maxime.ripard@...tlin.com,
        michal.lkml@...kovi.net, mpe@...erman.id.au,
        mporter@...nel.crashing.org, nicolas.palix@...g.fr,
        oss@...error.net, paulus@...ba.org, peppe.cavallaro@...com,
        tj@...nel.org, vitb@...nel.crashing.org, wens@...e.org
Cc:     cocci@...teme.lip6.fr, linux-amlogic@...ts.infradead.org,
        linux-arm-kernel@...ts.infradead.org, linux-ide@...r.kernel.org,
        linux-kernel@...r.kernel.org, linuxppc-dev@...ts.ozlabs.org,
        netdev@...r.kernel.org, linux-sunxi@...glegroups.com,
        Corentin Labbe <clabbe@...libre.com>
Subject: [PATCH RFC 3/5] coccinelle: add xxxsetbitsXX converting spatch

This patch add a spatch which convert all open coded of setbits32/clrbits32/clrsetbits32
and their 64 bits counterparts.

Signed-off-by: Corentin Labbe <clabbe@...libre.com>
---
 scripts/coccinelle/misc/setbits.cocci | 423 ++++++++++++++++++++++++++++++++++
 1 file changed, 423 insertions(+)
 create mode 100644 scripts/coccinelle/misc/setbits.cocci

diff --git a/scripts/coccinelle/misc/setbits.cocci b/scripts/coccinelle/misc/setbits.cocci
new file mode 100644
index 000000000000..c01ab6d75eb4
--- /dev/null
+++ b/scripts/coccinelle/misc/setbits.cocci
@@ -0,0 +1,423 @@
+virtual context
+
+@...rsetbits32a@
+identifier rr;
+expression reg;
+expression set;
+expression clear;
+@@
+
+  u32 rr;
+  ...
+- rr = readl(reg);
+- rr &= ~clear;
+- rr |= set;
+- writel(rr, reg);
++ clrsetbits32(reg, clear, set);
+
+@...rsetbits32b@
+identifier rr;
+expression reg;
+expression set;
+expression clear;
+@@
+
+  u32 rr;
+  ...
+- rr = readl(reg);
+- rr |= set;
+- rr &= ~clear;
+- writel(rr, reg);
++ clrsetbits32(reg, clear, set);
+
+@...rbits32@
+identifier rr;
+expression reg;
+expression clear;
+@@
+
+  u32 rr;
+  ...
+- rr = readl(reg);
+- rr &= ~clear;
+- writel(rr, reg);
++ clrbits32(reg, clear);
+
+@...tbits32@
+identifier rr;
+expression reg;
+expression set;
+@@
+
+  u32 rr;
+  ...
+- rr = readl(reg);
+- rr |= set;
+- writel(rr, reg);
++ setbits32(reg, set);
+
+@...tbits32b@
+identifier rr;
+expression reg;
+expression set1;
+expression set2;
+@@
+
+  u32 rr;
+  ...
+- rr = readl(reg);
+- rr |= set1;
+- rr |= set2;
+- writel(rr, reg);
++ setbits32(reg, set1 | set2);
+
+@...rsetbits64a@
+identifier rr;
+expression reg;
+expression set;
+expression clear;
+@@
+
+  u64 rr;
+  ...
+- rr = readq(reg);
+- rr &= ~clear;
+- rr |= set;
+- writeq(rr, reg);
++ clrsetbits64(reg, clear, set);
+
+@...rsetbits64b@
+identifier rr;
+expression reg;
+expression set;
+expression clear;
+@@
+
+  u64 rr;
+  ...
+- rr = readq(reg);
+- rr |= set;
+- rr &= ~clear;
+- writeq(rr, reg);
++ clrsetbits64(reg, clear, set);
+
+@...rbits64@
+identifier rr;
+expression reg;
+expression clear;
+@@
+
+  u64 rr;
+  ...
+- rr = readq(reg);
+- rr &= ~clear;
+- writeq(rr, reg);
++ clrbits64(reg, clear);
+
+@...tbits64@
+identifier rr;
+expression reg;
+expression set;
+@@
+
+  u64 rr;
+  ...
+- rr = readq(reg);
+- rr |= set;
+- writeq(rr, reg);
++ setbits64(reg, set);
+
+@@
+expression dwmac;
+expression reg;
+expression mask;
+expression value;
+@@
+
+- meson8b_dwmac_mask_bits(dwmac, reg, mask, value);
++ clrsetbits32(dwmac->regs + reg, mask, value);
+
+@...lrsetbits32a@
+identifier rr;
+expression reg;
+expression set;
+expression clear;
+@@
+
+- u32 rr = readl(reg);
+- rr &= ~clear;
+- rr |= set;
+- writel(rr, reg);
++ clrsetbits32(reg, clear, set);
+
+@...lrsetbits32b@
+identifier rr;
+expression reg;
+expression set;
+expression clear;
+@@
+
+- u32 rr = readl(reg);
+- rr |= set;
+- rr &= ~clear;
+- writel(rr, reg);
++ clrsetbits32(reg, clear, set);
+
+@...lrbits32@
+identifier rr;
+expression reg;
+expression clear;
+@@
+
+- u32 rr = readl(reg);
+- rr &= ~clear;
+- writel(rr, reg);
++ clrbits32(reg, clear);
+
+@...etbits32@
+identifier rr;
+expression reg;
+expression set;
+@@
+
+- u32 rr = readl(reg);
+- rr |= set;
+- writel(rr, reg);
++ setbits32(reg, set);
+
+@...lrsetbits64a@
+identifier rr;
+expression reg;
+expression set;
+expression clear;
+@@
+
+- u64 rr = readq(reg);
+- rr &= ~clear;
+- rr |= set;
+- writeq(rr, reg);
++ clrsetbits64(reg, clear, set);
+
+@...lrsetbits64b@
+identifier rr;
+expression reg;
+expression set;
+expression clear;
+@@
+
+- u64 rr = readq(reg);
+- rr |= set;
+- rr &= ~clear;
+- writeq(rr, reg);
++ clrsetbits64(reg, clear, set);
+
+@...lrbits64@
+identifier rr;
+expression reg;
+expression clear;
+@@
+
+- u64 rr = readq(reg);
+- rr &= ~clear;
+- writeq(rr, reg);
++ clrbits64(reg, clear);
+
+@...etbits64@
+identifier rr;
+expression reg;
+expression set;
+@@
+
+- u64 rr = readq(reg);
+- rr |= set;
+- writeq(rr, reg);
++ setbits64(reg, set);
+
+@..._set_clr@
+identifier rr;
+expression reg;
+expression set;
+expression clear;
+@@
+
+  u32 rr;
+  ...
+- rr = readl(reg);
+  if (...)
+- rr |= set;
++ setbits32(reg, set);
+  else
+- rr &= ~clear;
++ clrbits32(reg, clear);
+- writel(rr, reg);
+
+@...clrset@
+identifier rr;
+expression reg;
+expression set;
+expression clear;
+@@
+
+  u32 rr;
+  ...
+- rr = readl(reg);
+  if (...)
+- rr &= ~clear;
++ clrbits32(reg, clear);
+  else
+- rr |= set;
++ setbits32(reg, set);
+- writel(rr, reg);
+
+@..._set_clr64@
+identifier rr;
+expression reg;
+expression set;
+expression clear;
+@@
+
+  u64 rr;
+  ...
+- rr = readq(reg);
+  if (...)
+- rr |= set;
++ setbits64(reg, set);
+  else
+- rr &= ~clear;
++ clrbits64(reg, clear);
+- writeq(rr, reg);
+
+@..._clr_set64@
+identifier rr;
+expression reg;
+expression set;
+expression clear;
+@@
+
+  u64 rr;
+  ...
+- rr = readq(reg);
+  if (...)
+- rr &= ~clear;
++ clrbits64(reg, clear);
+  else
+- rr |= set;
++ setbits32(reg, set);
+- writeq(rr, reg);
+
+
+@...etbits32_m2@
+identifier rr;
+expression reg;
+expression set;
+@@
+
+  u32 rr;
+  ...
+- rr = readl(reg);
+- writel(rr | set, reg);
++ setbits32(reg, set);
+
+@...lrbits32_m2@
+identifier rr;
+expression reg;
+expression mask;
+@@
+
+  u32 rr;
+  ...
+- rr = readl(reg);
+- writel(rr & ~mask, reg);
++ clrbits32(reg, mask);
+
+
+@...etbits_oneliner@
+expression addr;
+expression set;
+@@
+- writel(readl(addr) | set, addr);
++ setbits32(addr, set);
+
+@...lrbits_oneliner@
+expression addr;
+expression mask;
+@@
+- writel(readl(addr) & ~mask, addr);
++ clrbits32(addr, mask);
+
+@...lrsetbits_oneliner_a@
+expression addr;
+expression set;
+expression mask;
+@@
+- writel(readl(addr) | set & ~mask, addr);
++ clrsetbits32(addr, mask, set);
+
+@...lrsetbits_oneliner_b@
+expression addr;
+expression set;
+expression mask;
+@@
+- writel(readl(addr) & ~mask | set, addr);
++ clrsetbits32(addr, mask, set);
+
+@...lrsetbits_oneliner_a2@
+expression addr;
+expression set;
+expression mask;
+@@
+- writel((readl(addr) | set) & ~mask, addr);
++ clrsetbits32(addr, mask, set);
+
+@...lrsetbits_oneliner_b2@
+expression addr;
+expression set;
+expression mask;
+@@
+- writel((readl(addr) & ~mask) | set, addr);
++ clrsetbits32(addr, mask, set);
+
+
+
+
+
+
+
+
+
+
+
+// sub optimal way to add header
+@...der1 depends on psetbits32 || pclrbits32 || pclrsetbits32a || pclrsetbits32b || psetbits64 || pclrbits64 || pclrsetbits64a || pclrsetbits64b || ppsetbits32 || ppclrbits32 || ppclrsetbits32a || ppclrsetbits32b || ppsetbits64 || ppclrbits64 || ppclrsetbits64a || ppclrsetbits64b@
+@@
+  #include <linux/io.h>
++ #include <linux/setbits.h>
+
+@...der2 depends on (psetbits32 || pclrbits32 || pclrsetbits32a || pclrsetbits32b || psetbits64 || pclrbits64 || pclrsetbits64a || pclrsetbits64b || ppsetbits32 || ppclrbits32 || ppclrsetbits32a || ppclrsetbits32b || ppsetbits64 || ppclrbits64 || ppclrsetbits64a || ppclrsetbits64b) && !header1@
+@@
+  #include <linux/interrupt.h>
++ #include <linux/setbits.h>
+
+@...der3 depends on (psetbits32 || pclrbits32 || pclrsetbits32a || pclrsetbits32b || psetbits64 || pclrbits64 || pclrsetbits64a || pclrsetbits64b || ppsetbits32 || ppclrbits32 || ppclrsetbits32a || ppclrsetbits32b || ppsetbits64 || ppclrbits64 || ppclrsetbits64a || ppclrsetbits64b) && !header2@
+@@
+  #include <linux/of.h>
++ #include <linux/setbits.h>
+
+@@
+expression base;
+expression offset;
+expression value;
+@@
+
+- mtu3_setbits(base, offset, value);
++ setbits32(base + offset, value);
+
+@@
+expression base;
+expression offset;
+expression mask;
+@@
+
+- mtu3_clrbits(base, offset, mask);
++ clrbits32(base + offset, mask);
+
-- 
2.16.4

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ