All of lore.kernel.org
 help / color / mirror / Atom feed
From: julia.lawall@lip6.fr (Julia Lawall)
To: cocci@systeme.lip6.fr
Subject: [Cocci] false positive match with ternary operator?
Date: Wed, 17 Feb 2016 11:13:01 -0500 (EST)	[thread overview]
Message-ID: <alpine.DEB.2.10.1602171108510.4547@hadrien> (raw)
In-Reply-To: <20160217160637.GA18038@katana>

On Wed, 17 Feb 2016, Wolfram Sang wrote:

> So, I'll try again ;) This spatch:
>
> @@
> identifier match;
> expression table, dev;
> type T;
> @@
> -	T match = of_match_device(table, dev);
> 	... when != match
> -	match->data
> +	of_device_get_match_data(dev)
> 	... when != match
>
> gives a match for:
>
> $ spatch -sp_file /tmp/minimal.cocci drivers/usb/renesas_usbhs/common.c
> ...
> --- drivers/usb/renesas_usbhs/common.c
> +++ /tmp/cocci-output-18078-7b0a6b-common.c
> @@ -498,7 +498,6 @@ static struct renesas_usbhs_platform_inf
>  {
>  	struct renesas_usbhs_platform_info *info;
>  	struct renesas_usbhs_driver_param *dparam;
> -	const struct of_device_id *of_id = of_match_device(usbhs_of_match, dev);
>  	u32 tmp;
>  	int gpio;
>
> @@ -507,7 +506,7 @@ static struct renesas_usbhs_platform_inf
>  		return NULL;
>
>  	dparam = &info->driver_param;
> -	dparam->type = of_id ? (uintptr_t)of_id->data : 0;
> +	dparam->type = of_id ? (uintptr_t)of_device_get_match_data(dev) : 0;
>  	if (!of_property_read_u32(dev->of_node, "renesas,buswait", &tmp))
>  		dparam->buswait_bwait = tmp;
>  	gpio = of_get_named_gpio_flags(dev->of_node, "renesas,enable-gpio", 0,
>
> However, 'of_id' is used as the first argument of the ternary operator. So,
> shouldn't '... when != match' prevent this, since 'match' is used before the
> replacement?

No, Coccinelle doesn't know anything about the order or execution within
expressions, neither ?: nor && and ||

Maybe make a big disjunction around the pattern, and make two cases
starting from the point of T match = of_match_device(table, dev);

julia

      reply	other threads:[~2016-02-17 16:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-17 16:06 [Cocci] false positive match with ternary operator? Wolfram Sang
2016-02-17 16:13 ` 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.10.1602171108510.4547@hadrien \
    --to=julia.lawall@lip6.fr \
    --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.