All of lore.kernel.org
 help / color / mirror / Atom feed
* [Cocci] [PATCH v2 1/1] scripts/coccinelle: use BIT macro if used
@ 2014-04-27 10:50 ` Javier Martinez Canillas
  0 siblings, 0 replies; 6+ messages in thread
From: Javier Martinez Canillas @ 2014-04-27 10:50 UTC (permalink / raw)
  To: cocci

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

If is more readable is a matter of taste so only replace
if the file is already using this macro.

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

Changes since v1:
 - Add a rule that checks if the file is already using this macro
   as suggested by Julia Lawall

 scripts/coccinelle/api/bit.cocci | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 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..a02cfd3
--- /dev/null
+++ b/scripts/coccinelle/api/bit.cocci
@@ -0,0 +1,30 @@
+// Use the BIT() macro if is already used
+//
+// Confidence: High
+// Copyright (C) 2014 Javier Martinez Canillas.  GPLv2.
+// URL: http://coccinelle.lip6.fr/
+// Options: --include-headers
+
+ at hasbitops@
+@@
+
+#include <linux/bitops.h>
+
+ at usesbit@
+@@
+
+BIT(...)
+
+ at depends on hasbitops && usesbit@
+expression E;
+@@
+
+- 1 << E
++ BIT(E)
+
+@depends on hasbitops && usesbit@
+expression E;
+@@
+
+- BIT((E))
++ BIT(E)
-- 
1.9.1

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

end of thread, other threads:[~2014-04-30 12:05 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-27 10:50 [Cocci] [PATCH v2 1/1] scripts/coccinelle: use BIT macro if used Javier Martinez Canillas
2014-04-27 10:50 ` Javier Martinez Canillas
2014-04-29 16:18 ` [Cocci] " Lars-Peter Clausen
2014-04-29 16:18   ` Lars-Peter Clausen
2014-04-30 12:05   ` Javier Martinez Canillas
2014-04-30 12:05     ` Javier Martinez Canillas

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.