Skip to contentSkip to conversation

Checking an application of the SmPL construct “<+... … ...+>”

Cocci Markus Elfring 2 participants 3 messages May 7, 2020

lore
Share & tools
lore
#0 lore raw

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/[email protected]/

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
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#1 lore raw
Quoted 72 lines · Markus Elfring

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/[email protected]/

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 …

(quoted diff) +0 -1
@@ -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(...) ...+>

Quoted 4 lines
        )

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

Quoted 10 lines

Does the application of the SmPL nest construct need any more clarification?
https://github.com/coccinelle/coccinelle/issues/114

Regards,
Markus
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#2 lore raw
Quoted 9 lines
Quoted 9 lines

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

        )
Quoted 5 lines
Quoted 1 line

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. …”

Quoted 1 line

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
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci