Hello, I have taken another look at a known script for the semantic patch language. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/scripts/coccinelle/api/ptr_ret.cocci?id=1e3778cb223e861808ae0daccf353536e7573eed#n3 I got the impression that duplicate SmPL code can be reduced here. So I tried the following approach out. … @depends on patch@ expression ptr; @@ ( ( - if (IS_ERR(ptr)) return PTR_ERR(ptr); else return 0; | - if (IS_ERR(ptr)) return PTR_ERR(ptr); return 0; ) + return PTR_ERR_OR_ZERO(ptr); | - (IS_ERR(ptr) ? PTR_ERR(ptr) : 0) + PTR_ERR_OR_ZERO(ptr) ) … Unfortunately, I got the following information then for a test transformation. elfring@Sonne:~/Projekte/Linux/next-patched> spatch -D patch scripts/coccinelle/api/ptr_ret.cocci drivers/spi/spi-gpio.c … 29: no available token to attach to It seems that the Coccinelle software “1.0.7-00218-gf284bf36” does not like the addition of the shown return statement after a nested SmPL disjunction. But the following SmPL code variant seems to work as expected. … @depends on patch@ expression ptr; @@ ( - if (IS_ERR(ptr)) return PTR_ERR(ptr); else return 0; + return PTR_ERR_OR_ZERO(ptr); | - if (IS_ERR(ptr)) return PTR_ERR(ptr); return 0; + return PTR_ERR_OR_ZERO(ptr); | - (IS_ERR(ptr) ? PTR_ERR(ptr) : 0) + PTR_ERR_OR_ZERO(ptr) ) … How do you think about to reduce subsequent SmPL rules also according to a possible recombination of affected implementation details? Regards, Markus _______________________________________________ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
[-- Attachment #1: Type: text/plain, Size: 1894 bytes --] On Sat, 7 Sep 2019, Markus Elfring wrote: > Hello, > > I have taken another look at a known script for the semantic patch language. > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/scripts/coccinelle/api/ptr_ret.cocci?id=1e3778cb223e861808ae0daccf353536e7573eed#n3 > > I got the impression that duplicate SmPL code can be reduced here. > So I tried the following approach out. > > … > @depends on patch@ > expression ptr; > @@ > ( > ( > - if (IS_ERR(ptr)) return PTR_ERR(ptr); else return 0; > | > - if (IS_ERR(ptr)) return PTR_ERR(ptr); return 0; > ) > + return PTR_ERR_OR_ZERO(ptr); > | > - (IS_ERR(ptr) ? PTR_ERR(ptr) : 0) > + PTR_ERR_OR_ZERO(ptr) > ) > … > > > Unfortunately, I got the following information then for a test transformation. > > elfring@Sonne:~/Projekte/Linux/next-patched> spatch -D patch scripts/coccinelle/api/ptr_ret.cocci drivers/spi/spi-gpio.c > … > 29: no available token to attach to > > > It seems that the Coccinelle software “1.0.7-00218-gf284bf36” does not like > the addition of the shown return statement after a nested SmPL disjunction. > But the following SmPL code variant seems to work as expected. > > > … > @depends on patch@ > expression ptr; > @@ > ( > - if (IS_ERR(ptr)) return PTR_ERR(ptr); else return 0; > + return PTR_ERR_OR_ZERO(ptr); > | > - if (IS_ERR(ptr)) return PTR_ERR(ptr); return 0; > + return PTR_ERR_OR_ZERO(ptr); > | > - (IS_ERR(ptr) ? PTR_ERR(ptr) : 0) > + PTR_ERR_OR_ZERO(ptr) > ) > … > > > How do you think about to reduce subsequent SmPL rules also according to > a possible recombination of affected implementation details? There is not going to be any change with respect to this issue. It's fine when replacing one statement by another, but introduces complexity when removing something more complex. And there's not point to have something that works in only one special case. julia [-- Attachment #2: Type: text/plain, Size: 136 bytes --] _______________________________________________ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
>> How do you think about to reduce subsequent SmPL rules also according to >> a possible recombination of affected implementation details? > > There is not going to be any change with respect to this issue. I am curious if the software situation will be reconsidered any further under other circumstances. > It's fine when replacing one statement by another, but introduces complexity > when removing something more complex. Thanks for such information. > And there's not point to have something that works in only one special case. Will corresponding software development concerns be eventually discussed a bit more? Regards, Markus _______________________________________________ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 7 Sep 2019 18:30:32 +0200 This SmPL script contains duplicate code. Thus reduce it to the required source code search functionality by the means of the semantic patch language. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- scripts/coccinelle/api/ptr_ret.cocci | 61 +++++----------------------- 1 file changed, 10 insertions(+), 51 deletions(-) diff --git a/scripts/coccinelle/api/ptr_ret.cocci b/scripts/coccinelle/api/ptr_ret.cocci index e76cd5d90a8a..f4b1ce4a06d0 100644 --- a/scripts/coccinelle/api/ptr_ret.cocci +++ b/scripts/coccinelle/api/ptr_ret.cocci @@ -20,44 +20,28 @@ virtual report @depends on patch@ expression ptr; @@ - +( - if (IS_ERR(ptr)) return PTR_ERR(ptr); else return 0; + return PTR_ERR_OR_ZERO(ptr); - -@depends on patch@ -expression ptr; -@@ - +| - if (IS_ERR(ptr)) return PTR_ERR(ptr); return 0; + return PTR_ERR_OR_ZERO(ptr); - -@depends on patch@ -expression ptr; -@@ - +| - (IS_ERR(ptr) ? PTR_ERR(ptr) : 0) + PTR_ERR_OR_ZERO(ptr) +) @r1 depends on !patch@ expression ptr; position p1; @@ - +( * if@p1 (IS_ERR(ptr)) return PTR_ERR(ptr); else return 0; - -@r2 depends on !patch@ -expression ptr; -position p2; -@@ - -* if@p2 (IS_ERR(ptr)) return PTR_ERR(ptr); return 0; - -@r3 depends on !patch@ -expression ptr; -position p3; -@@ - -* IS_ERR@p3(ptr) ? PTR_ERR(ptr) : 0 +| +* if@p1 (IS_ERR(ptr)) return PTR_ERR(ptr); return 0; +| +* IS_ERR@p1(ptr) ? PTR_ERR(ptr) : 0 +) @script:python depends on org@ p << r1.p1; @@ -65,33 +49,8 @@ p << r1.p1; coccilib.org.print_todo(p[0], "WARNING: PTR_ERR_OR_ZERO can be used") - -@script:python depends on org@ -p << r2.p2; -@@ - -coccilib.org.print_todo(p[0], "WARNING: PTR_ERR_OR_ZERO can be used") - -@script:python depends on org@ -p << r3.p3; -@@ - -coccilib.org.print_todo(p[0], "WARNING: PTR_ERR_OR_ZERO can be used") - @script:python depends on report@ p << r1.p1; @@ coccilib.report.print_report(p[0], "WARNING: PTR_ERR_OR_ZERO can be used") - -@script:python depends on report@ -p << r2.p2; -@@ - -coccilib.report.print_report(p[0], "WARNING: PTR_ERR_OR_ZERO can be used") - -@script:python depends on report@ -p << r3.p3; -@@ - -coccilib.report.print_report(p[0], "WARNING: PTR_ERR_OR_ZERO can be used") -- 2.23.0 _______________________________________________ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci