[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1493175288-5279-1-git-send-email-vaishali.thakkar@oracle.com>
Date: Wed, 26 Apr 2017 08:24:48 +0530
From: Vaishali Thakkar <vaishali.thakkar@...cle.com>
To: Julia.Lawall@...6.fr
Cc: Gilles.Muller@...6.fr, nicolas.palix@...g.fr, mmarek@...e.com,
linux-kernel@...r.kernel.org, cocci@...teme.lip6.fr,
Vaishali Thakkar <vaishali.thakkar@...cle.com>
Subject: [PATCH] Coccinelle: api: Add offset_in_page.cocci
Use of offset_in_page is preferable instead of open coding.
This patch adds coccinelle script for suggesting the use of
macro offset_in_page.
Signed-off-by: Vaishali Thakkar <vaishali.thakkar@...cle.com>
---
scripts/coccinelle/api/offset_in_page.cocci | 77 +++++++++++++++++++++++++++++
1 file changed, 77 insertions(+)
create mode 100644 scripts/coccinelle/api/offset_in_page.cocci
diff --git a/scripts/coccinelle/api/offset_in_page.cocci b/scripts/coccinelle/api/offset_in_page.cocci
new file mode 100644
index 0000000..d083109
--- /dev/null
+++ b/scripts/coccinelle/api/offset_in_page.cocci
@@ -0,0 +1,77 @@
+/// Use offset_in_page instead of duplicating its implementation
+///
+// Confidence: High
+// Copyright: (C) 2017 Vaishali Thakkar, Oracle. GPLv2.
+// Options: --no-includes --include-headers
+// Keywords: offset_in_page
+
+virtual patch
+virtual context
+virtual org
+virtual report
+
+@...atch depends on patch@
+expression e;
+identifier i;
+@@
+- unsigned long i = (unsigned long)e & ~PAGE_MASK;
+...
+- i
++ offset_in_page(e)
+
+@...patch depends on patch@
+expression e1;
+@@
+
+(
+- (unsigned long)e1 & ~PAGE_MASK
++ offset_in_page(e1)
+|
+- (unsigned long)e1 % PAGE_SIZE
++ offset_in_page(e1)
+)
+
+@...ontext depends on !patch@
+expression e;
+identifier i;
+position p;
+@@
+
+* unsigned long i = (unsigned long)e@p & ~PAGE_MASK;
+...
+* i
+
+@...context depends on !patch@
+expression e1;
+position p1;
+@@
+
+(
+* (unsigned long)e1@p1 & ~PAGE_MASK
+|
+* (unsigned long)e1@p1 % PAGE_SIZE
+)
+
+@...ipt:python depends on org@
+p << r_context.p;
+@@
+
+coccilib.org.print_todo(p[0], "WARNING opportunity for offset_in_page")
+
+@...ipt:python depends on org@
+p << r1_context.p1;
+@@
+
+coccilib.org.print_todo(p[0], "WARNING opportunity for offset_in_page")
+
+@...ipt:python depends on report@
+p << r_context.p;
+@@
+
+coccilib.report.print_report(p[0], "WARNING opportunity for offset_in_page")
+
+@...ipt:python depends on report@
+p << r1_context.p1;
+@@
+
+coccilib.report.print_report(p[0], "WARNING opportunity for offset_in_page")
--
2.7.4
Powered by blists - more mailing lists