Re: [cocci] [PATCH 01/36] coccinelle: misc: add cond_return_no_effect.cocci
Sang-Heon Jeon <[email protected]> Fri, 24 Jul 2026 23:42:51 +0900
| Newsgroups | fr.inria.cocci,org.kernel.vger.kernel-janitors,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <CABFDxMFYvuAZSGcPmhAj4H43dwYBG01P2-UQPGa=-M=yRE8YKg@mail.gmail.com> |
Hello,
On Fri, Jul 24, 2026 at 8:19=E2=80=AFPM Markus Elfring <Markus.Elfring@web.=
de> wrote:
>
> =E2=80=A6
> > +++ b/scripts/coccinelle/misc/cond_return_no_effect.cocci
> > @@ -0,0 +1,121 @@
> =E2=80=A6
> > +@depends on patch@
> > +local idexpression ret;
> > +expression E;
> > +binary operator cmp =3D {<, <=3D, >, >=3D, =3D=3D, !=3D};
> > +constant C;
> > +@@
> > +- ret =3D E;
> > +- if (\(ret \| !ret \| ret cmp C\))
> > +- return ret;
> > +- return ret;
> > ++ return E;
> > +
> > +@depends on patch@
> > +idexpression ret;
> > +binary operator cmp =3D {<, <=3D, >, >=3D, =3D=3D, !=3D};
> > +constant C;
> > +@@
> > +- if (\(ret \| !ret \| ret cmp C\))
> > +- return ret;
> > + return ret;
> =E2=80=A6
>
> How do you think about to combine such transformation rules
> by using an SmPL disjunction?
The two rules look similar, but the metavariable kinds are different
for a reason.
- If both rules used `local idexpression`, the second rule could miss
global or static variable cases, even though such patterns are not
common.
- If both rules used `idexpression`, the first rule could remove an
assignment to a global or static variable, which would be a false
positive.
Combining them with two separate metavariables would be okay, but I
don't see much benefit in that change. So I'd prefer to stay existing
form.
> Regards,
> Markus
Thanks for reviewing :)
Best Regards,
Sang-Heon Jeon