* [Cocci] Adjusting SmPL script “ptr_ret.cocci”? @ 2019-09-07 14:54 Markus Elfring 2019-09-07 16:05 ` Julia Lawall 0 siblings, 1 reply; 4+ messages in thread From: Markus Elfring @ 2019-09-07 14:54 UTC (permalink / raw) To: Coccinelle, kernel-janitors Cc: Kate Stewart, Michal Marek, Greg Kroah-Hartman, Nicolas Palix, LKML, Allison Randal 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 ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Cocci] Adjusting SmPL script “ptr_ret.cocci”? 2019-09-07 14:54 [Cocci] Adjusting SmPL script “ptr_ret.cocci”? Markus Elfring @ 2019-09-07 16:05 ` Julia Lawall 2019-09-07 16:20 ` Markus Elfring 2019-09-07 16:40 ` [Cocci] [PATCH] Coccinelle: Reduce rules in SmPL script “ptr_ret.cocci” Markus Elfring 0 siblings, 2 replies; 4+ messages in thread From: Julia Lawall @ 2019-09-07 16:05 UTC (permalink / raw) To: Markus Elfring Cc: Kate Stewart, Michal Marek, Greg Kroah-Hartman, Nicolas Palix, kernel-janitors, LKML, Coccinelle, Allison Randal [-- 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 ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Cocci] Adjusting SmPL script “ptr_ret.cocci”? 2019-09-07 16:05 ` Julia Lawall @ 2019-09-07 16:20 ` Markus Elfring 2019-09-07 16:40 ` [Cocci] [PATCH] Coccinelle: Reduce rules in SmPL script “ptr_ret.cocci” Markus Elfring 1 sibling, 0 replies; 4+ messages in thread From: Markus Elfring @ 2019-09-07 16:20 UTC (permalink / raw) To: Julia Lawall, Coccinelle, kernel-janitors Cc: Kate Stewart, Michal Marek, Greg Kroah-Hartman, Nicolas Palix, LKML, Allison Randal >> 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 ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Cocci] [PATCH] Coccinelle: Reduce rules in SmPL script “ptr_ret.cocci” 2019-09-07 16:05 ` Julia Lawall 2019-09-07 16:20 ` Markus Elfring @ 2019-09-07 16:40 ` Markus Elfring 1 sibling, 0 replies; 4+ messages in thread From: Markus Elfring @ 2019-09-07 16:40 UTC (permalink / raw) To: Julia Lawall, Coccinelle, kernel-janitors, Gilles Muller, Masahiro Yamada, Michal Marek, Nicolas Palix Cc: Kate Stewart, Greg Kroah-Hartman, LKML, Thomas Gleixner, Allison Randal 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 ^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-09-07 16:41 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2019-09-07 14:54 [Cocci] Adjusting SmPL script “ptr_ret.cocci”? Markus Elfring 2019-09-07 16:05 ` Julia Lawall 2019-09-07 16:20 ` Markus Elfring 2019-09-07 16:40 ` [Cocci] [PATCH] Coccinelle: Reduce rules in SmPL script “ptr_ret.cocci” Markus Elfring
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).