Skip to contentSkip to conversation

Deleting duplicate condition checks (with SmPL)?

cocci Markus Elfring 2 participants 7 messages Jul 13, 2025 – Jul 14, 2025

lore
Share & tools
lore
#0 lore raw

Hello,

I noticed another contribution.

I got into the mood to construct another script for the semantic patch language.

// See also:
// [PATCH net-next] ipv6: mcast: Remove unnecessary null check in mld_del_delrec() // https://lore.kernel.org/lkml/[email protected]/
//
// https://elixir.bootlin.com/linux/v6.16-rc5/source/net/ipv6/mcast.c#L786-L813
@deletions@
expression x;
@@
if (x)
{
<+...
-}
-if (x)
-{
...+>
}

Questionable test result (by the software combination “Coccinelle 1.3.0” for example):
Markus_Elfring@Sonne:…/Projekte/Coccinelle/janitor> /usr/bin/spatch --parse-cocci delete_duplicate_condition_checks2.cocci …
minus: parse error:
File "delete_duplicate_condition_checks2.cocci", line 12, column 1, charpos = 307
around = '}',
whole content = -}

The transformation approach is working as expected if the specification “... when any” would be applied instead of the SmPL nest construct.
Which software improvements will become more desirable for such an use case?

Regards,
Markus

#1 lore raw
Quoted 1 line

Which software improvements will become more desirable for such an use case?

Will another script variant for the semantic patch language become helpful?

// See also:
// [PATCH net-next] ipv6: mcast: Remove unnecessary null check in mld_del_delrec()
// https://lore.kernel.org/netdev/CAAVpQUC-mV=SuNNhKbpy_1Mbh_sOs856+oNqDVJ4KcLjhDh2kw@mail.gmail.com/
// https://lkml.org/lkml/2025/7/12/336
//
// https://elixir.bootlin.com/linux/v6.16-rc5/source/net/ipv6/mcast.c#L786-L813
@adjustment disable braces0@
expression e;
identifier i;
@@
void i(...)
{
... when any
if (
+ !

     e
    )

+ return;
- {
... when any
- }
-if (e)
- {
... when any
- }
... when any
}

Would you be looking for further source code layout refinements then?

Regards,
Markus

#2 lore raw
Quoted 25 lines · Markus Elfring



Quoted 2 lines

Which software improvements will become more desirable for such an use case?

Will another script variant for the semantic patch language become helpful?

// See also:
// [PATCH net-next] ipv6: mcast: Remove unnecessary null check in mld_del_delrec()
// https://lore.kernel.org/netdev/CAAVpQUC-mV=SuNNhKbpy_1Mbh_sOs856+oNqDVJ4KcLjhDh2kw@mail.gmail.com/
// https://lkml.org/lkml/2025/7/12/336
//
// https://elixir.bootlin.com/linux/v6.16-rc5/source/net/ipv6/mcast.c#L786-L813
@adjustment disable braces0@
expression e;
identifier i;
@@
void i(...)
{
... when any
if (

Review

Quoted 6 lines
(quoted diff) +2 -1
+    !
    e
   )
+   return;
-   {
   ... when any

I have no idea what is the question here, but the above when any is useless. Braces always match up properly.

Quoted 13 lines
(quoted diff) +0 -4
-   }
-if (e)
-   {
   ... when any
-   }

... when any
}

Would you be looking for further source code layout refinements then?

Regards,
Markus

#3 lore raw
Quoted 16 lines
Quoted 9 lines

// https://elixir.bootlin.com/linux/v6.16-rc5/source/net/ipv6/mcast.c#L786-L813
@adjustment disable braces0@
expression e;
identifier i;
@@
void i(...)
{
... when any
if (

Review

Quoted 6 lines
(quoted diff) +2 -1
+    !
    e
   )
+   return;
-   {
   ... when any
Quoted 1 line

I have no idea what is the question here,

Would you find any details improvable in the generated diff output?

Markus_Elfring@Sonne:…/Projekte/Linux/next-analyses> time /usr/bin/spatch …/Projekte/Coccinelle/janitor/delete_duplicate_condition_checks4.cocci net/ipv6/mcast.c …
@@ -789,34 +789,31 @@ static void mld_del_delrec(struct inet6_
…

Examples:
* Coding style preferences?
…
+ if (!pmc)
+ return;
+ if (pmc_prev)
…

* Indentation?
…
+ for_each_psf_mclock(im, psf)
+ psf->sf_crcount = idev->mc_qrv;
+} else {

+               im->mca_crcount = idev->mc_qrv;
        }

…

Quoted 1 line

but the above when any is useless. Braces always match up properly.

Will such information become relevant for a better software documentation?

Regards,
Markus

#4 lore raw
Quoted 37 lines · Markus Elfring
Quoted 16 lines
Quoted 9 lines

// https://elixir.bootlin.com/linux/v6.16-rc5/source/net/ipv6/mcast.c#L786-L813
@adjustment disable braces0@
expression e;
identifier i;
@@
void i(...)
{
... when any
if (

Review

Quoted 6 lines
(quoted diff) +2 -1
+    !
    e
   )
+   return;
-   {
   ... when any
Quoted 1 line

I have no idea what is the question here,

Would you find any details improvable in the generated diff output?

Markus_Elfring@Sonne:…/Projekte/Linux/next-analyses> time /usr/bin/spatch …/Projekte/Coccinelle/janitor/delete_duplicate_condition_checks4.cocci net/ipv6/mcast.c …

(quoted diff) +0 -0
@@ -789,34 +789,31 @@ static void mld_del_delrec(struct inet6_
…

Examples:
* Coding style preferences?
…

(quoted diff) +3 -0
+       if (!pmc)
+               return;
+       if (pmc_prev)
…

* Indentation?
…

Review

Quoted 6 lines
(quoted diff) +4 -0
+               for_each_psf_mclock(im, psf)
+                       psf->sf_crcount = idev->mc_qrv;
+} else {
+               im->mca_crcount = idev->mc_qrv;
        }
…

I still have no idea what the question is. Please provide a single email with both the semantic patch and a small C program thta illustrates whatever you are concerned about. This is the rule for all issues that you want to raise. Everything should be in one email and easily reproducible,

julia

Quoted 8 lines
Quoted 2 lines

but the above when any is useless. Braces always match up properly.

Will such information become relevant for a better software documentation?

Regards,
Markus

#5 lore raw
Quoted 1 line

I still have no idea what the question is.

Can you reproduce my observations in your software test environment?

Regards,
Markus

#6 lore raw
In reply to Markus Elfring

Sent from my iPhone

Quoted 23 lines · Markus Elfring

Hello,

I noticed another contribution.

I got into the mood to construct another script for the semantic patch language.

// See also:
// [PATCH net-next] ipv6: mcast: Remove unnecessary null check in mld_del_delrec() // https://lore.kernel.org/lkml/[email protected]/
//
// https://elixir.bootlin.com/linux/v6.16-rc5/source/net/ipv6/mcast.c#L786-L813
@deletions@
expression x;
@@
if (x)
{
<+...

(quoted diff) +0 -3
-}
-if (x)
-{
Quoted 4 lines

...+>
}

It expects a real statement inside <+… …+>

Quoted 15 lines

Questionable test result (by the software combination “Coccinelle 1.3.0” for example):
Markus_Elfring@Sonne:…/Projekte/Coccinelle/janitor> /usr/bin/spatch --parse-cocci delete_duplicate_condition_checks2.cocci …
minus: parse error:
File "delete_duplicate_condition_checks2.cocci", line 12, column 1, charpos = 307
around = '}',
whole content = -}

The transformation approach is working as expected if the specification “... when any” would be applied instead of the SmPL nest construct.
Which software improvements will become more desirable for such an use case?

Regards,
Markus