From: Vaishali Thakkar <vaishali.thakkar@oracle.com>
To: julia.lawall@lip6.fr
Cc: Gilles.Muller@lip6.fr, nicolas.palix@imag.fr, mmarek@suse.com,
linux-kernel@vger.kernel.org, cocci@systeme.lip6.fr,
Vaishali Thakkar <vaishali.thakkar@oracle.com>
Subject: [PATCH v2] Coccinelle: api: Add offset_in_page.cocci
Date: Fri, 5 May 2017 19:30:50 +0530 [thread overview]
Message-ID: <1493992850-13283-1-git-send-email-vaishali.thakkar@oracle.com> (raw)
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@oracle.com>
---
Changes since v1:
- Add parenthesis around rule for patch mode to avoid
extra parenthesis in end result
---
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..4034864
--- /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
+
+@r_patch depends on patch@
+expression e;
+identifier i;
+@@
+- unsigned long i = (unsigned long)e & ~PAGE_MASK;
+...
+- i
++ offset_in_page(e)
+
+@r1_patch depends on patch@
+expression e1;
+@@
+
+(
+- ((unsigned long)e1 & ~PAGE_MASK)
++ offset_in_page(e1)
+|
+- ((unsigned long)e1 % PAGE_SIZE)
++ offset_in_page(e1)
+)
+
+@r_context depends on !patch@
+expression e;
+identifier i;
+position p;
+@@
+
+* unsigned long i = (unsigned long)e@p & ~PAGE_MASK;
+...
+* i
+
+@r1_context depends on !patch@
+expression e1;
+position p1;
+@@
+
+(
+* (unsigned long)e1@p1 & ~PAGE_MASK
+|
+* (unsigned long)e1@p1 % PAGE_SIZE
+)
+
+@script:python depends on org@
+p << r_context.p;
+@@
+
+coccilib.org.print_todo(p[0], "WARNING opportunity for offset_in_page")
+
+@script:python depends on org@
+p << r1_context.p1;
+@@
+
+coccilib.org.print_todo(p[0], "WARNING opportunity for offset_in_page")
+
+@script:python depends on report@
+p << r_context.p;
+@@
+
+coccilib.report.print_report(p[0], "WARNING opportunity for offset_in_page")
+
+@script:python depends on report@
+p << r1_context.p1;
+@@
+
+coccilib.report.print_report(p[0], "WARNING opportunity for offset_in_page")
--
2.7.4
next reply other threads:[~2017-05-05 14:02 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-05 14:00 Vaishali Thakkar [this message]
2017-05-14 1:13 ` Julia Lawall
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1493992850-13283-1-git-send-email-vaishali.thakkar@oracle.com \
--to=vaishali.thakkar@oracle.com \
--cc=Gilles.Muller@lip6.fr \
--cc=cocci@systeme.lip6.fr \
--cc=julia.lawall@lip6.fr \
--cc=linux-kernel@vger.kernel.org \
--cc=mmarek@suse.com \
--cc=nicolas.palix@imag.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®