Coccinelle archive on lore.kernel.org
 help / color / 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, back to index

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

Coccinelle archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/cocci/0 cocci/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 cocci cocci/ https://lore.kernel.org/cocci \
		cocci@systeme.lip6.fr
	public-inbox-index cocci

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/fr.lip6.systeme.cocci


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git