mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Julia Lawall <julia.lawall@lip6.fr>
To: Lars-Peter Clausen <lars@metafoo.de>
Cc: Gilles Muller <Gilles.Muller@lip6.fr>,
	Nicolas Palix <npalix.work@gmail.com>,
	linux-kernel@vger.kernel.org, cocci@diku.dk,
	Michal Marek <mmarek@suse.cz>
Subject: Re: [Cocci] [PATCH 1/2] coccinelle: Add patch for replacing open-coded PTR_RET
Date: Tue, 20 Dec 2011 23:19:12 +0100 (CET)	[thread overview]
Message-ID: <alpine.DEB.2.02.1112202317450.1933@hadrien> (raw)
In-Reply-To: <1324301063-16117-1-git-send-email-lars@metafoo.de>

On Mon, 19 Dec 2011, Lars-Peter Clausen wrote:

> The PTR_RET function returns the error value of its parameter if it is an
> ERR_PTR, otherwise it returns 0. This patch adds a semantic patch which finds
> open-coded instances of this check and replaces them.
>
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>

Acked-by: Julia Lawall <julia.lawall@lip6.fr>

> ---
> scripts/coccinelle/api/ptr_ret.cocci |   55 ++++++++++++++++++++++++++++++++++
> 1 files changed, 55 insertions(+), 0 deletions(-)
> create mode 100644 scripts/coccinelle/api/ptr_ret.cocci
>
> diff --git a/scripts/coccinelle/api/ptr_ret.cocci b/scripts/coccinelle/api/ptr_ret.cocci
> new file mode 100644
> index 0000000..dfd9b1f
> --- /dev/null
> +++ b/scripts/coccinelle/api/ptr_ret.cocci
> @@ -0,0 +1,55 @@
> +///
> +/// Use PTR_RET function instead of open coding it
> +///
> +// Confidence: High
> +// Options:
> +//
> +// Keywords: IS_ERR, PTR_ERR, PTR_RET
> +// Version min: 2.6.39
> +//
> +
> +virtual context
> +virtual patch
> +virtual org
> +virtual report
> +
> +@depends on context@
> +expression x;
> +@@
> +*if (IS_ERR(x))
> +*	return PTR_ERR(x);
> +*return 0;
> +
> +@depends on patch@
> +expression x;
> +@@
> +-if (IS_ERR(x))
> +-	return PTR_ERR(x);
> +-return 0;
> ++return PTR_RET(x);
> +
> +@r depends on org || report@
> +expression x;
> +position p;
> +@@
> +
> + if (IS_ERR@p(x))
> +	return PTR_ERR(x);
> + return 0;
> +
> +@script:python depends on org@
> +p << r.p;
> +x << r.x;
> +@@
> +
> +msg="WARNING PTR_RET can be used with %s" % (x)
> +msg_safe=msg.replace("[","@(").replace("]",")")
> +coccilib.org.print_todo(p[0], msg_safe)
> +
> +@script:python depends on report@
> +p << r.p;
> +x << r.x;
> +@@
> +
> +msg="WARNING: PTR_RET can be used with %s" % (x)
> +coccilib.report.print_report(p[0], msg)
> -- 
> 1.7.7.3
>
>
> _______________________________________________
> Cocci mailing list
> Cocci@diku.dk
> http://lists.diku.dk/mailman/listinfo/cocci
> (Web access from inside DIKUs LAN only)
>

      parent reply	other threads:[~2011-12-20 22:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-19 13:24 Lars-Peter Clausen
2011-12-19 13:24 ` [PATCH 2/2] coccinelle: Add patch for replacing open-coded IS_ERR_OR_NULL Lars-Peter Clausen
2011-12-20 22:24   ` [Cocci] " Julia Lawall
2011-12-21 11:49     ` Lars-Peter Clausen
2011-12-21 12:10       ` Julia Lawall
2011-12-23 12:19         ` Lars-Peter Clausen
2011-12-23 12:26           ` Julia Lawall
2011-12-20 22:19 ` Julia Lawall [this message]

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=alpine.DEB.2.02.1112202317450.1933@hadrien \
    --to=julia.lawall@lip6.fr \
    --cc=Gilles.Muller@lip6.fr \
    --cc=cocci@diku.dk \
    --cc=lars@metafoo.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mmarek@suse.cz \
    --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®