From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758446AbdENBOK (ORCPT ); Sat, 13 May 2017 21:14:10 -0400 Received: from mail3-relais-sop.national.inria.fr ([192.134.164.104]:9017 "EHLO mail3-relais-sop.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752948AbdENBOJ (ORCPT ); Sat, 13 May 2017 21:14:09 -0400 X-IronPort-AV: E=Sophos;i="5.38,337,1491256800"; d="scan'208";a="223534168" Date: Sun, 14 May 2017 09:13:49 +0800 (SGT) From: Julia Lawall X-X-Sender: jll@hadrien To: Vaishali Thakkar cc: Gilles Muller , nicolas.palix@imag.fr, mmarek@suse.com, linux-kernel@vger.kernel.org, cocci@systeme.lip6.fr Subject: Re: [PATCH v2] Coccinelle: api: Add offset_in_page.cocci In-Reply-To: <1493992850-13283-1-git-send-email-vaishali.thakkar@oracle.com> Message-ID: References: <1493992850-13283-1-git-send-email-vaishali.thakkar@oracle.com> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 5 May 2017, Vaishali Thakkar wrote: > 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 > --- > 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) This doesn't take into account the possibility that i occurs more than once. It should be: - 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) > +) & ~ and % are equivalent? I did find both definitions in the kernel, but I didn't think about whether they do the same thing. julia > + > +@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 > >