Skip to contentSkip to conversation

Improving support for deleting selected macro calls with SmPL

DISCUSSION Markus Elfring 2 participants 6 messages Aug 28 Kernel janitors

lore
Share & tools
lore
#0 lore raw

Hello,

The data processing is still improvable also according to the software combination “Coccinelle 1.3.2”.

Another SmPL script example:
@deletion@
@@
-READ_ONCE(dev->mtu)

Questionable test result:
Markus_Elfring@Sonne:…/Projekte/Coccinelle/janitor> spatch --parse-cocci delete_READ_ONCE_for_mtu.cocci …
invalid minus starting on line 3

Would you like to improve any software components accordingly?
https://gitlab.inria.fr/coccinelle/coccinelle/-/blob/78ac4072c68190fc929f2e3c7534350a5ef6496a/parsing_cocci/context_neg.ml#L1419-1434

Regards,
Markus

#1 lore raw
Quoted 11 lines · Markus Elfring

Hello,

The data processing is still improvable also according to the software combination “Coccinelle 1.3.2”.

Another SmPL script example:
@deletion@
@@
-READ_ONCE(dev->mtu)

Quoted 4 lines

Questionable test result:
Markus_Elfring@Sonne:…/Projekte/Coccinelle/janitor> spatch --parse-cocci delete_READ_ONCE_for_mtu.cocci …
invalid minus starting on line 3

You can't simply delete an expression. The resulting code would not be valid. For example if the code was 10 + READ_ONCE(x), you would end up with 10 +, which is not valid C code.

The problemn has nothing to do with READ_ONCE being a macro. It occurs for any expression.

julia

Quoted 9 lines

Would you like to improve any software components accordingly?
https://gitlab.inria.fr/coccinelle/coccinelle/-/blob/78ac4072c68190fc929f2e3c7534350a5ef6496a/parsing_cocci/context_neg.ml#L1419-1434

Regards,
Markus

#2 lore raw
Quoted 6 lines
Quoted 6 lines

Another SmPL script example:
@deletion@
@@
-READ_ONCE(dev->mtu)

Quoted 7 lines
Quoted 4 lines

Questionable test result:
Markus_Elfring@Sonne:…/Projekte/Coccinelle/janitor> spatch --parse-cocci delete_READ_ONCE_for_mtu.cocci …
invalid minus starting on line 3

You can't simply delete an expression. The resulting code would not be valid. …

How do you think about to improve the error message anyhow?

Quoted 2 lines

The problemn has nothing to do with READ_ONCE being a macro. It occurs for any expression.

I got the impression that some expression parts would be replaceable.

Regards,
Markus

#3 lore raw
Quoted 13 lines · Markus Elfring
Quoted 6 lines
Quoted 6 lines

Another SmPL script example:
@deletion@
@@
-READ_ONCE(dev->mtu)

Quoted 7 lines
Quoted 4 lines

Questionable test result:
Markus_Elfring@Sonne:…/Projekte/Coccinelle/janitor> spatch --parse-cocci delete_READ_ONCE_for_mtu.cocci …
invalid minus starting on line 3

You can't simply delete an expression. The resulting code would not be valid. …

Quoted 7 lines

How do you think about to improve the error message anyhow?

Quoted 2 lines

The problemn has nothing to do with READ_ONCE being a macro. It occurs for any expression.

I got the impression that some expression parts would be replaceable.

If you expected it to be replaced, you have to specify with what.

julia

#4 lore raw

Re: Improving support for replacing expression parts by SmPL

Quoted 2 lines
Quoted 1 line

I got the impression that some expression parts would be replaceable.

If you expected it to be replaced, you have to specify with what.

I would like to achieve something also for another more detailed SmPL script.

See also:
https://elixir.bootlin.com/linux/v7.2/source/include/net/pkt_sched.h#L128-L134

SmPL code sketch:
@replacements@
expression …, dev, …;
@@
(
-container_of ( link , struct tcx_link , link ) +tcx_link(link)
|
- READ_ONCE ( dev -> mtu ) + dev -> hard_header_len +psched_mtu(dev)
|
…
|
-refcount_inc_not_zero ( & r -> refcount ) +p9_req_try_get(r)
)

Markus_Elfring@Sonne:~> spatch --parse-cocci /home/altes_Heim2/elfring/Projekte/Bau/Linux/scripts/Coccinelle/list_inline_non-void_functions5-net-20251114-adjusted.cocci …
minus: parse error:
File "/home/altes_Heim2/elfring/Projekte/Bau/Linux/scripts/Coccinelle/list_inline_non-void_functions5-net-20251114-adjusted.cocci", line 8, column 21, charpos = 2685 around = 'mtu',
whole content = - READ_ONCE ( dev -> mtu ) + dev -> hard_header_len

Regards,
Markus

#5 lore raw

Re: [cocci] Improving support for replacing expression parts by SmPL

Quoted 27 lines · Markus Elfring
Quoted 2 lines
Quoted 1 line

I got the impression that some expression parts would be replaceable.

If you expected it to be replaced, you have to specify with what.

I would like to achieve something also for another more detailed SmPL script.

See also:
https://elixir.bootlin.com/linux/v7.2/source/include/net/pkt_sched.h#L128-L134

SmPL code sketch:
@replacements@
expression …, dev, …;
@@
(

(quoted diff) +1 -1
-container_of ( link , struct tcx_link , link )
+tcx_link(link)

|
- READ_ONCE ( dev -> mtu ) + dev -> hard_header_len +psched_mtu(dev)
|
…
|

(quoted diff) +1 -1
-refcount_inc_not_zero ( & r -> refcount )
+p9_req_try_get(r)

)

Quoted 6 lines

Markus_Elfring@Sonne:~> spatch --parse-cocci /home/altes_Heim2/elfring/Projekte/Bau/Linux/scripts/Coccinelle/list_inline_non-void_functions5-net-20251114-adjusted.cocci …
minus: parse error:
File "/home/altes_Heim2/elfring/Projekte/Bau/Linux/scripts/Coccinelle/list_inline_non-void_functions5-net-20251114-adjusted.cocci", line 8, column 21, charpos = 2685 around = 'mtu',
whole content = - READ_ONCE ( dev -> mtu ) + dev -> hard_header_len

Well, it seems that you have not provided a complete semantic patch, since there are ...s in the list of metavariables, so I can't answer the question.

julia

Quoted 5 lines

Regards,
Markus