public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] scripts/coccinelle: use BIT() macro if possible
@ 2014-04-27  0:29 Javier Martinez Canillas
  2014-04-27  5:14 ` [Cocci] " Wolfram Sang
  2014-04-27 10:29 ` Julia Lawall
  0 siblings, 2 replies; 7+ messages in thread
From: Javier Martinez Canillas @ 2014-04-27  0:29 UTC (permalink / raw)
  To: Julia Lawall
  Cc: Gilles Muller, Nicolas Palix, Michal Marek, cocci, linux-kernel,
	Javier Martinez Canillas

Using the BIT() macro instead of manually shifting bits
makes the code less error prone and also more readable.

Signed-off-by: Javier Martinez Canillas <javier@dowhile0.org>
---

An example of the patches that can be obtained with this spatch:

http://www.mail-archive.com/linux-gpio@vger.kernel.org/msg02722.html

 scripts/coccinelle/api/bit.cocci | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
 create mode 100644 scripts/coccinelle/api/bit.cocci

diff --git a/scripts/coccinelle/api/bit.cocci b/scripts/coccinelle/api/bit.cocci
new file mode 100644
index 0000000..a5df73a
--- /dev/null
+++ b/scripts/coccinelle/api/bit.cocci
@@ -0,0 +1,25 @@
+// Use the macro BIT() macro if possible
+//
+// Confidence: High
+// Copyright (C) 2014 Javier Martinez Canillas.  GPLv2.
+// URL: http://coccinelle.lip6.fr/
+// Options: --include-headers
+
+@hasbitops@
+@@
+
+#include <linux/bitops.h>
+
+@depends on hasbitops@
+expression E;
+@@
+
+- 1 << E
++ BIT(E)
+
+@depends on hasbitops@
+expression E;
+@@
+
+- BIT((E))
++ BIT(E)
-- 
1.9.1


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

end of thread, other threads:[~2014-04-27 10:41 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-27  0:29 [PATCH 1/1] scripts/coccinelle: use BIT() macro if possible Javier Martinez Canillas
2014-04-27  5:14 ` [Cocci] " Wolfram Sang
2014-04-27  8:58   ` Javier Martinez Canillas
2014-04-27  9:36     ` Julia Lawall
2014-04-27 10:24       ` Javier Martinez Canillas
2014-04-27 10:29 ` Julia Lawall
2014-04-27 10:41   ` Javier Martinez Canillas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox