All of lore.kernel.org
 help / color / mirror / Atom feed
From: lars@metafoo.de (Lars-Peter Clausen)
To: cocci@systeme.lip6.fr
Subject: [Cocci] isomorphism with unlikely
Date: Mon, 20 May 2013 19:47:20 +0200	[thread overview]
Message-ID: <519A61A8.7010402@metafoo.de> (raw)
In-Reply-To: <20130520173406.GB5890@katana>

On 05/20/2013 07:34 PM, Wolfram Sang wrote:
> Hi,
> 
> using 1.0-rc16 from debian, I use the following semantic patch:
> 
> @@
> expression r, p, n;
> @@
> 	r = platform_get_resource(p, IORESOURCE_MEM, n);
> 	...
> (
> -	if (!r) { ... }
> |
> -	if (unlikely(!r)) { ... }
> |
> -	if (unlikely(r == NULL)) { ... }
> )
> 
> and running against the latest kernel tree (~3.10-rc1):
> 
> spatch --sp-file unlikely_iso.cocci ~/Kernel/linux/drivers/net/ethernet/renesas/sh_eth.c
> 
> gives me a match:
> 
> -	if (unlikely(res == NULL)) {
> ...
> 
> Note that I have two alternations with 'unlikely' because using '!r'
> alone will not give me a match. I guess the isomorphism is skipped for
> some reason when used as an argument of unlikely. If so, is it possible
> to enforce it somehow? Or would it be even better to make 'unlikely' an
> isomorphism itself, so that the semantic patch doesn't need to know
> anything about 'unlikely'?
> 

There is already an isomorphism for unlikely. But it is in one direction
only, so 'unlikely(E)' in your cocci script will also match 'E', but 'E'
wont match 'unlikely(E)'.

So in your case the script could be reduced to:

> @@
> expression r, p, n;
> @@
> 	r = platform_get_resource(p, IORESOURCE_MEM, n);
> 	...
> -	if (unlikely(r == NULL)) { ... }

Btw. if you use 'statement S;' and 'if(...) S' instead of '{ ... }' you'll
also be able to match if there is only a single statement without brackets
after the if.

- Lars

  reply	other threads:[~2013-05-20 17:47 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-20 17:34 [Cocci] isomorphism with unlikely Wolfram Sang
2013-05-20 17:47 ` Lars-Peter Clausen [this message]
2013-05-20 18:24   ` Wolfram Sang
2013-05-20 18:26     ` Lars-Peter Clausen
2013-05-20 18:51       ` Julia Lawall
2013-05-20 19:13         ` Lars-Peter Clausen
2013-05-22 17:36           ` Julia Lawall
2013-05-26 20:01           ` Julia Lawall

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=519A61A8.7010402@metafoo.de \
    --to=lars@metafoo.de \
    --cc=cocci@systeme.lip6.fr \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.