From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9888AC04EB9 for ; Wed, 5 Dec 2018 14:23:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5FAFD2083F for ; Wed, 5 Dec 2018 14:23:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5FAFD2083F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-btrfs-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727604AbeLEOXQ (ORCPT ); Wed, 5 Dec 2018 09:23:16 -0500 Received: from mx2.suse.de ([195.135.220.15]:46010 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727339AbeLEOXO (ORCPT ); Wed, 5 Dec 2018 09:23:14 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id EF748ADD4; Wed, 5 Dec 2018 14:23:12 +0000 (UTC) From: Johannes Thumshirn To: David Sterba Cc: Linux BTRFS Mailinglist , Johannes Thumshirn , Julia Lawall Subject: [RFC PATCH 3/3] coccinelle: api: add offset_in_page.cocci Date: Wed, 5 Dec 2018 15:23:05 +0100 Message-Id: <20181205142305.15361-4-jthumshirn@suse.de> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20181205142305.15361-1-jthumshirn@suse.de> References: <20181205142305.15361-1-jthumshirn@suse.de> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Constructs like 'var & (PAGE_SIZE - 1)' or 'var & ~PAGE_MASK' can be replaced by the offset_in_page() macro instead of open-coding it. Add a coccinelle semantic patch to ease detection and conversion of these. This unfortunately doesn't account for the case when we want PAGE_ALIGNED() instead of offset_in_page() yet. Cc: Julia Lawall Signed-off-by: Johannes Thumshirn --- scripts/coccinelle/api/offset_in_page.cocci | 81 +++++++++++++++++++++++++++++ 1 file changed, 81 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 000000000000..ea5b3a8e0390 --- /dev/null +++ b/scripts/coccinelle/api/offset_in_page.cocci @@ -0,0 +1,81 @@ +// SPDX-License-Identifier: GPL-2.0 +/// +/// Use offset_in_page macro on address instead of explicit computation. +/// +// Confidence: High +// Keywords: offset_in_page +// Comment: Based on vma_pages.cocci + +virtual context +virtual patch +virtual org +virtual report + + +//---------------------------------------------------------- +// For context mode +//---------------------------------------------------------- + +@r_context depends on context && !patch && !org && !report@ +expression E; +@@ + +( +* E & ~PAGE_MASK +| +* E & (PAGE_SIZE - 1) +) + + +//---------------------------------------------------------- +// For patch mode +//---------------------------------------------------------- + +@r_patch depends on !context && patch && !org && !report@ +expression E; +type T; +@@ + +( +- E & ~PAGE_MASK ++ offset_in_page(E) +| +- E & (PAGE_SIZE - 1) ++ offset_in_page(E) +| +- E & ((T)PAGE_SIZE - 1) ++ offset_in_page(E) +) + +//---------------------------------------------------------- +// For org mode +//---------------------------------------------------------- + +@r_org depends on !context && !patch && (org || report)@ +expression E; +position p; +@@ + + ( + * E@p & ~PAGE_MASK + | + * E@p & (PAGE_SIZE - 1) + ) + +@script:python depends on report@ +p << r_org.p; +x << r_org.E; +@@ + +msg="WARNING: Consider using offset_in_page helper on %s" % (x) +coccilib.report.print_report(p[0], msg) + +@script:python depends on org@ +p << r_org.p; +x << r_org.E; +@@ + +msg="WARNING: Consider using offset_in_page helper on %s" % (x) +msg_safe=msg.replace("[","@(").replace("]",")") +coccilib.org.print_todo(p[0], msg_safe) + -- 2.16.4