mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Julia Lawall <julia@diku.dk>
To: Greg Dietsche <Gregory.Dietsche@cuw.edu>
Cc: Gilles.Muller@lip6.fr, npalix.work@gmail.com, cocci@diku.dk,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] coccinelle: if (ret) return ret; return ret; semantic patch
Date: Wed, 15 Jun 2011 07:50:31 +0200 (CEST)	[thread overview]
Message-ID: <Pine.LNX.4.64.1106150748300.27735@ask.diku.dk> (raw)
In-Reply-To: <1308101355-5009-1-git-send-email-Gregory.Dietsche@cuw.edu>

On Tue, 14 Jun 2011, Greg Dietsche wrote:

> Semantic patch to find code that matches this pattern:
> 	if (...) return ret;
> 	return ret;
> 
> Version 2:
> 	Incorporate review comments from Julia Lawall
> 	Add matches for a number of other similar patterns.
> 
> Version 3:
> 	Incorporating more review comments from Julia.
> 
> Signed-off-by: Greg Dietsche <Gregory.Dietsche@cuw.edu>
> ---
>  scripts/coccinelle/misc/doublereturn.cocci |   31 ++++++++++++++++++++++++++++
>  1 files changed, 31 insertions(+), 0 deletions(-)
>  create mode 100644 scripts/coccinelle/misc/doublereturn.cocci
> 
> diff --git a/scripts/coccinelle/misc/doublereturn.cocci b/scripts/coccinelle/misc/doublereturn.cocci
> new file mode 100644
> index 0000000..2de8564
> --- /dev/null
> +++ b/scripts/coccinelle/misc/doublereturn.cocci
> @@ -0,0 +1,31 @@
> +// Removing unecessary code that matches this core pattern:
> +//	-if(...) return ret;
> +//	return ret;
> +//
> +// Confidence: High
> +// Copyright: (C) 2011 Greg Dietsche GPLv2.
> +// URL: http://www.gregd.org
> +// Comments:
> +// Options: -no_includes
> +
> +virtual patch
> +
> +@depends on patch@
> +expression ret;
> +identifier x, y;
> +identifier f;
> +identifier is_ordinal_table ~= "IS_ORDINAL_TABLE_\(ONE\|TWO\)";
> +@@
> +(
> +//via an isomorphism this also covers x and unlikely(x)
> +-if (likely(x)) return ret;
> +|
> +-if (\(IS_ERR\|IS_ZERO\)(x)) return ret;
> +|
> +-if (is_ordinal_table(x,y)) return ret;
> +|
> +if(<+...f(...)...+>) return ret;
> +|
> +-if (...) return ret;
> +)
> +return ret;

It doesn't matter in this case, but in general the use of regular 
expressions should be a last resort.  The problem is that when coccinelle 
is searching for relevant files, it doesn't interpret regular expressions, 
and so it would just take all files.  But in this case it doesn't matter, 
because including eg if (...) return ret; will cause it to consider all 
files anyway.

julia

  reply	other threads:[~2011-06-15  5:50 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-06  0:26 [PATCH] coccinelle: if(ret)return " Greg Dietsche
2011-06-06  4:55 ` Julia Lawall
2011-06-07 15:47   ` Greg Dietsche
2011-06-07 16:56     ` Julia Lawall
2011-06-07 21:54       ` Nicolas Palix
2011-06-07 22:59         ` Greg Dietsche
2011-06-08  7:11           ` Nicolas Palix
2011-06-08  7:24             ` Julia Lawall
2011-06-11 15:37   ` Greg Dietsche
2011-06-11 15:43     ` Julia Lawall
2011-06-06  4:56 ` Julia Lawall
2011-06-13 18:23   ` [PATCH v2] coccinelle: if (ret) return " Greg Dietsche
2011-06-13 18:36     ` Joe Perches
2011-06-13 18:38     ` Julia Lawall
2011-06-13 20:55       ` Greg Dietsche
2011-06-14  5:50         ` Julia Lawall
2011-06-14 21:24           ` Greg Dietsche
2011-06-15  1:15             ` Greg Dietsche
2011-06-15  5:58               ` Julia Lawall
2011-06-15 15:33                 ` [Cocci] " Greg Dietsche
2011-06-15 15:34                   ` Julia Lawall
2011-06-15 15:35                   ` Julia Lawall
2011-06-15 16:05                     ` Greg Dietsche
2011-06-15  1:29       ` [PATCH v3] " Greg Dietsche
2011-06-15  5:50         ` Julia Lawall [this message]
2011-06-15 15:50         ` [PATCH v4] " Greg Dietsche

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.64.1106150748300.27735@ask.diku.dk \
    --to=julia@diku.dk \
    --cc=Gilles.Muller@lip6.fr \
    --cc=Gregory.Dietsche@cuw.edu \
    --cc=cocci@diku.dk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=npalix.work@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®