Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755120AbbHLOAV (ORCPT ); Wed, 12 Aug 2015 10:00:21 -0400 Received: from mail2-relais-roc.national.inria.fr ([192.134.164.83]:64459 "EHLO mail2-relais-roc.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750949AbbHLOAU (ORCPT ); Wed, 12 Aug 2015 10:00:20 -0400 X-IronPort-AV: E=Sophos;i="5.15,661,1432591200"; d="scan'208";a="173400171" Date: Wed, 12 Aug 2015 16:00:10 +0200 (CEST) From: Julia Lawall X-X-Sender: jll@hadrien To: Kris Borer cc: Julia.Lawall@lip6.fr, Gilles.Muller@lip6.fr, nicolas.palix@imag.fr, mmarek@suse.cz, linux-kernel@vger.kernel.org, cocci@systeme.lip6.fr Subject: Re: [RFC] coccinelle: add style check for assignment in if In-Reply-To: <1439387500-11183-1-git-send-email-kborer@gmail.com> Message-ID: References: <1439387500-11183-1-git-send-email-kborer@gmail.com> User-Agent: Alpine 2.10 (DEB 1266 2009-07-14) 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 Content-Length: 2395 Lines: 116 Thanks for the contribution. Have you checked very carefully that it doesn't eg pull XXX out of if (E && XXX)? (I don't know if it does or it doesn't, but it is a common pitfall with this issue). thanks, julia On Wed, 12 Aug 2015, Kris Borer wrote: > Add a semantic patch for fixing some cases of checkpatch.pl error: > > ERROR: do not use assignment in if condition > > Signed-off-by: Kris Borer > --- > scripts/coccinelle/style/assignment_in_if.cocci | 82 +++++++++++++++++++++++++ > 1 file changed, 82 insertions(+) > create mode 100644 scripts/coccinelle/style/assignment_in_if.cocci > > diff --git a/scripts/coccinelle/style/assignment_in_if.cocci b/scripts/coccinelle/style/assignment_in_if.cocci > new file mode 100644 > index 0000000..d9895e7 > --- /dev/null > +++ b/scripts/coccinelle/style/assignment_in_if.cocci > @@ -0,0 +1,82 @@ > +// find checkpatch.pl errors of the type: > +// ERROR: do not use assignment in if condition > +// > +// Confidence: Moderate > + > + > +// if ( ret = call() ) > +@if1@ > +identifier i; > +expression E; > +statement S1, S2; > +@@ > + > ++ i = E; > + if ( > +- (i = E) > ++ i > + ) S1 else S2 > + > + > +// if ( (ret = call()) < 0 ) > +@if2@ > +identifier i; > +expression E; > +statement S1, S2; > +binary operator b; > +@@ > + > ++ i = E; > + if ( > +- (i = E) > ++ i > + b ... ) S1 else S2 > + > +// if ( ptr->fun && (ret = ptr->fun()) < 0 ) > +@if3@ > +identifier i, i2; > +expression E1, E2; > +constant c; > +binary operator b; > +@@ > + > ++ if( E1->i ) { > ++ i2 = E2; > ++ if (i2 < c) { > +- if( E1->i && ((i2 = E2) b c) ) { > + ... > +- } > ++ } > ++ } > + > +// if ( (ret = call()) < 0 && ret != 0 ) > +@if4@ > +identifier i; > +expression E, E2, E3; > +statement S1, S2; > +binary operator b; > +@@ > + > ++ i = E; > + if ( > +- (i = E) > ++ i > + b > + ... && E2 && E3 ) S1 else S2 > + > +// if ( (ret = call()) < 0 && ret != 0 && ret != 0 ) > +@if5@ > +identifier i; > +expression E, E2, E3; > +statement S1, S2; > +binary operator b; > +@@ > + > ++ i = E; > + if ( > +- (i = E) > ++ i > + b > + ... && E2 && E3 ) S1 else S2 > + > + > -- > 1.9.1 > > -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/