From patchwork Sun Jun 5 07:42:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 9155121 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7F97360221 for ; Sun, 5 Jun 2016 07:44:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 596E9268AE for ; Sun, 5 Jun 2016 07:44:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3D10B281D2; Sun, 5 Jun 2016 07:44:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C2494268AE for ; Sun, 5 Jun 2016 07:44:15 +0000 (UTC) Received: from localhost ([::1]:35766 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b9SjF-0002yX-PD for patchwork-qemu-devel@patchwork.kernel.org; Sun, 05 Jun 2016 03:44:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58897) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b9Sik-0002xy-83 for qemu-devel@nongnu.org; Sun, 05 Jun 2016 03:43:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b9Sig-0004Oo-2l for qemu-devel@nongnu.org; Sun, 05 Jun 2016 03:43:41 -0400 Received: from isrv.corpit.ru ([86.62.121.231]:38060) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b9Sif-0004OO-ON; Sun, 05 Jun 2016 03:43:38 -0400 Received: from tsrv.tls.msk.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 1863E40910; Sun, 5 Jun 2016 10:43:33 +0300 (MSK) Received: from tls.msk.ru (mjt.vpn.tls.msk.ru [192.168.177.99]) by tsrv.tls.msk.ru (Postfix) with SMTP id 697D4ADA; Sun, 5 Jun 2016 10:43:32 +0300 (MSK) Received: (nullmailer pid 1107 invoked by uid 1000); Sun, 05 Jun 2016 07:43:32 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org Date: Sun, 5 Jun 2016 10:42:46 +0300 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 86.62.121.231 Subject: [Qemu-devel] [PULL 09/52] scripts: add muldiv64() checking coccinelle scripts X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , qemu-trivial@nongnu.org, Michael Tokarev Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Laurent Vivier Signed-off-by: Laurent Vivier Signed-off-by: Michael Tokarev --- scripts/coccinelle/overflow_muldiv64.cocci | 16 ++++++++++++++++ scripts/coccinelle/remove_muldiv64.cocci | 6 ++++++ scripts/coccinelle/simplify_muldiv64.cocci | 11 +++++++++++ scripts/coccinelle/swap_muldiv64.cocci | 13 +++++++++++++ 4 files changed, 46 insertions(+) create mode 100644 scripts/coccinelle/overflow_muldiv64.cocci create mode 100644 scripts/coccinelle/remove_muldiv64.cocci create mode 100644 scripts/coccinelle/simplify_muldiv64.cocci create mode 100644 scripts/coccinelle/swap_muldiv64.cocci diff --git a/scripts/coccinelle/overflow_muldiv64.cocci b/scripts/coccinelle/overflow_muldiv64.cocci new file mode 100644 index 0000000..08ec4a8 --- /dev/null +++ b/scripts/coccinelle/overflow_muldiv64.cocci @@ -0,0 +1,16 @@ +// Find muldiv64(i64, i64, x) for potential overflow +@filter@ +typedef uint64_t; +typedef int64_t; +{ uint64_t, int64_t, long, unsigned long } a, b; +expression c; +position p; +@@ + +muldiv64(a,b,c)@p + +@script:python@ +p << filter.p; +@@ + +cocci.print_main("potential muldiv64() overflow", p) diff --git a/scripts/coccinelle/remove_muldiv64.cocci b/scripts/coccinelle/remove_muldiv64.cocci new file mode 100644 index 0000000..4c10bd5 --- /dev/null +++ b/scripts/coccinelle/remove_muldiv64.cocci @@ -0,0 +1,6 @@ +// replace muldiv64(a, 1, b) by "a / b" +@@ +expression a, b; +@@ +-muldiv64(a, 1, b) ++a / b diff --git a/scripts/coccinelle/simplify_muldiv64.cocci b/scripts/coccinelle/simplify_muldiv64.cocci new file mode 100644 index 0000000..3d7c974 --- /dev/null +++ b/scripts/coccinelle/simplify_muldiv64.cocci @@ -0,0 +1,11 @@ +// replace muldiv64(i32, i32, x) by (uint64_t)i32 * i32 / x +@@ +typedef uint32_t; +typedef int32_t; +{ uint32_t, int32_t, int, unsigned int } a, b; +typedef uint64_t; +expression c; +@@ + +-muldiv64(a,b,c) ++(uint64_t) a * b / c diff --git a/scripts/coccinelle/swap_muldiv64.cocci b/scripts/coccinelle/swap_muldiv64.cocci new file mode 100644 index 0000000..b48b0d0 --- /dev/null +++ b/scripts/coccinelle/swap_muldiv64.cocci @@ -0,0 +1,13 @@ +// replace muldiv64(i32, i64, x) by muldiv64(i64, i32, x) +@@ +typedef uint64_t; +typedef int64_t; +typedef uint32_t; +typedef int32_t; +{ uint32_t, int32_t, int, unsigned int } a; +{ uint64_t, int64_t, long, unsigned long } b; +expression c; +@@ + +-muldiv64(a,b,c) ++muldiv64(b,a,c)