cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
* [Cocci] Checking an application of the SmPL construct “<+... … ...+>”
@ 2020-05-07 16:00 Markus Elfring
  2020-05-07 16:19 ` Julia Lawall
  0 siblings, 1 reply; 3+ messages in thread
From: Markus Elfring @ 2020-05-07 16:00 UTC (permalink / raw)
  To: Coccinelle; +Cc: Christophe Jaillet

Hello,

I have tried further script variants out for the semantic patch language
(according to the software combination “Coccinelle 1.0.8-00087-g7cf2c23e”).

Source code example:
// SPDX-License-Identifier: GPL-2.0-only
// deleted part
static int sca3000_read_data(struct sca3000_state *st,
			     u8 reg_address_high,
			     u8 *rx,
			     int len)
{
	int ret;
	struct spi_transfer xfer[2] = {
		{
			.len = 1,
			.tx_buf = st->tx,
		}, {
			.len = len,
			.rx_buf = rx,
		}
	};
// deleted part
	ret = spi_sync_transfer(st->us, xfer, ARRAY_SIZE(xfer));
	if (ret) {
		dev_err(get_device(&st->us->dev), "problem reading register");
		return ret;
	}

	return 0;
}
// deleted part


See also:
https://lore.kernel.org/patchwork/patch/1236743/
https://lore.kernel.org/linux-iio/20200506035206.192173-1-christophe.jaillet@wanadoo.fr/


The following search approach points a questionable source code place out
as expected.

@display@
@@
(dev_err
|dev_info
)       (
*        get_device(...),
         ...
        )


elfring@Sonne:~/Projekte/Coccinelle/janitor> spatch show_get_device_as_message_parameter2.cocci ../Probe/sca3000-excerpt-20200505.c
…
@@ -18,7 +18,6 @@ static int sca3000_read_data(struct sca3
 // deleted part
 	ret = spi_sync_transfer(st->us, xfer, ARRAY_SIZE(xfer));
 	if (ret) {
-		dev_err(get_device(&st->us->dev), "problem reading register");
 		return ret;
 	}


But I do not get the same output for the following SmPL script.

@display@
@@
(dev_err
|dev_info
)       (
*        <+... get_device(...) ...+>
        )


Is such a test result worth for further software development considerations?
Does the application of the SmPL nest construct need any more clarification?
https://github.com/coccinelle/coccinelle/issues/114

Regards,
Markus
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Cocci] Checking an application of the SmPL construct “<+... … ...+>”
  2020-05-07 16:00 [Cocci] Checking an application of the SmPL construct “<+... … ...+>” Markus Elfring
@ 2020-05-07 16:19 ` Julia Lawall
  2020-05-07 16:33   ` Markus Elfring
  0 siblings, 1 reply; 3+ messages in thread
From: Julia Lawall @ 2020-05-07 16:19 UTC (permalink / raw)
  To: Markus Elfring; +Cc: Christophe Jaillet, Coccinelle

[-- Attachment #1: Type: text/plain, Size: 2214 bytes --]



On Thu, 7 May 2020, Markus Elfring wrote:

> Hello,
>
> I have tried further script variants out for the semantic patch language
> (according to the software combination “Coccinelle 1.0.8-00087-g7cf2c23e”).
>
> Source code example:
> // SPDX-License-Identifier: GPL-2.0-only
> // deleted part
> static int sca3000_read_data(struct sca3000_state *st,
> 			     u8 reg_address_high,
> 			     u8 *rx,
> 			     int len)
> {
> 	int ret;
> 	struct spi_transfer xfer[2] = {
> 		{
> 			.len = 1,
> 			.tx_buf = st->tx,
> 		}, {
> 			.len = len,
> 			.rx_buf = rx,
> 		}
> 	};
> // deleted part
> 	ret = spi_sync_transfer(st->us, xfer, ARRAY_SIZE(xfer));
> 	if (ret) {
> 		dev_err(get_device(&st->us->dev), "problem reading register");
> 		return ret;
> 	}
>
> 	return 0;
> }
> // deleted part
>
>
> See also:
> https://lore.kernel.org/patchwork/patch/1236743/
> https://lore.kernel.org/linux-iio/20200506035206.192173-1-christophe.jaillet@wanadoo.fr/
>
>
> The following search approach points a questionable source code place out
> as expected.
>
> @display@
> @@
> (dev_err
> |dev_info
> )       (
> *        get_device(...),
>          ...
>         )
>
>
> elfring@Sonne:~/Projekte/Coccinelle/janitor> spatch show_get_device_as_message_parameter2.cocci ../Probe/sca3000-excerpt-20200505.c
> …
> @@ -18,7 +18,6 @@ static int sca3000_read_data(struct sca3
>  // deleted part
>  	ret = spi_sync_transfer(st->us, xfer, ARRAY_SIZE(xfer));
>  	if (ret) {
> -		dev_err(get_device(&st->us->dev), "problem reading register");
>  		return ret;
>  	}
>
>
> But I do not get the same output for the following SmPL script.
>
> @display@
> @@
> (dev_err
> |dev_info
> )       (
> *        <+... get_device(...) ...+>
>         )
>
>
> Is such a test result worth for further software development considerations?

No.

<+... ...+> as an expression matches a single expression.  The function
has multiple arguments.

julia

> Does the application of the SmPL nest construct need any more clarification?
> https://github.com/coccinelle/coccinelle/issues/114
>
> Regards,
> Markus
> _______________________________________________
> Cocci mailing list
> Cocci@systeme.lip6.fr
> https://systeme.lip6.fr/mailman/listinfo/cocci
>

[-- Attachment #2: Type: text/plain, Size: 136 bytes --]

_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Cocci] Checking an application of the SmPL construct “<+... … ...+>”
  2020-05-07 16:19 ` Julia Lawall
@ 2020-05-07 16:33   ` Markus Elfring
  0 siblings, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2020-05-07 16:33 UTC (permalink / raw)
  To: Julia Lawall, Coccinelle; +Cc: Christophe Jaillet

>> @display@
>> @@
>> (dev_err
>> |dev_info
>> )       (
>> *        <+... get_device(...) ...+>
>>         )
>>
>>
>> Is such a test result worth for further software development considerations?
>
> No.
>
> <+... ...+> as an expression matches a single expression.

How does this information fit to the description from the software documentation?
https://github.com/coccinelle/coccinelle/blob/7cf2c23e64066d5249a64a316cc5347831f7a63f/docs/manual/cocci_syntax.tex#L783

“…, and another (<+... ...+>) indicates that the pattern in between
the ellipses must be matched at least once, on some control-flow path.
…”


> The function has multiple arguments.

Function-like macro calls should be found here.
https://elixir.bootlin.com/linux/v5.7-rc4/source/include/linux/dev_printk.h#L93

How should expression lists be handled for such an use case?

Regards,
Markus
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-05-07 16:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-07 16:00 [Cocci] Checking an application of the SmPL construct “<+... … ...+>” Markus Elfring
2020-05-07 16:19 ` Julia Lawall
2020-05-07 16:33   ` Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).