From patchwork Fri Aug 3 16:32:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julia Lawall X-Patchwork-Id: 10555331 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CB74D174A for ; Fri, 3 Aug 2018 17:05:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ADEA22BF52 for ; Fri, 3 Aug 2018 17:05:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9FEF92BF6C; Fri, 3 Aug 2018 17:05:39 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9185F2BF52 for ; Fri, 3 Aug 2018 17:05:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727792AbeHCTCl (ORCPT ); Fri, 3 Aug 2018 15:02:41 -0400 Received: from mail2-relais-roc.national.inria.fr ([192.134.164.83]:1577 "EHLO mail2-relais-roc.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727171AbeHCTCl (ORCPT ); Fri, 3 Aug 2018 15:02:41 -0400 X-IronPort-AV: E=Sophos;i="5.51,439,1526335200"; d="scan'208";a="341340983" Received: from palace.lip6.fr (HELO localhost.localdomain) ([132.227.105.202]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/AES128-SHA256; 03 Aug 2018 19:05:30 +0200 From: Julia Lawall To: Masahiro Yamada Cc: kernel-janitors@vger.kernel.org, Gilles Muller , Nicolas Palix , Michal Marek , cocci@systeme.lip6.fr, linux-kernel@vger.kernel.org, Andy Shevchenko , Finn Thain , zhong jiang , Michael Schmitz , "James E . J . Bottomley" , "Martin K . Petersen" , John Garry , linux-scsi Subject: [PATCH] Coccinelle: doubletest: reduce side effect false positives Date: Fri, 3 Aug 2018 18:32:11 +0200 Message-Id: <1533313931-3639-1-git-send-email-Julia.Lawall@lip6.fr> X-Mailer: git-send-email 1.9.1 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Ensure that the cited expression is not a function call or an assignment to reduce the chance of false positives. Slightly modify the warning message to indicate another source of false positves. Signed-off-by: Julia Lawall --- scripts/coccinelle/tests/doubletest.cocci | 34 ++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/scripts/coccinelle/tests/doubletest.cocci b/scripts/coccinelle/tests/doubletest.cocci index 78d74c2..7af2ce7 100644 --- a/scripts/coccinelle/tests/doubletest.cocci +++ b/scripts/coccinelle/tests/doubletest.cocci @@ -1,6 +1,7 @@ /// Find &&/|| operations that include the same argument more than once -//# A common source of false positives is when the argument performs a side -//# effect. +//# A common source of false positives is when the expression, or +//# another expresssion in the same && or || operation, performs a +//# side effect. /// // Confidence: Moderate // Copyright: (C) 2010 Nicolas Palix, DIKU. GPLv2. @@ -20,20 +21,37 @@ position p; @@ ( -* E@p - || ... || E + E@p || ... || E | -* E@p - && ... && E + E@p && ... && E ) -@script:python depends on org@ +@bad@ +expression r.E,e1,e2,fn; +position r.p; +assignment operator op; +@@ + +( +E@p +& + <+... \(fn(...)\|e1 op e2\|e1++\|e1--\|++e1\|--e1\) ...+> +) + +@depends on context && !bad@ +expression r.E; +position r.p; +@@ + +*E@p + +@script:python depends on org && !bad@ p << r.p; @@ cocci.print_main("duplicated argument to && or ||",p) -@script:python depends on report@ +@script:python depends on report && !bad@ p << r.p; @@