From: Markus Elfring <Markus.Elfring@web.de>
To: Coccinelle <cocci@systeme.lip6.fr>, kernel-janitors@vger.kernel.org
Cc: Kate Stewart <kstewart@linuxfoundation.org>,
Michal Marek <michal.lkml@markovi.net>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Nicolas Palix <nicolas.palix@imag.fr>,
LKML <linux-kernel@vger.kernel.org>,
Allison Randal <allison@lohutok.net>
Subject: [Cocci] Adjusting SmPL script “ptr_ret.cocci”?
Date: Sat, 7 Sep 2019 16:54:26 +0200 [thread overview]
Message-ID: <c8e0db8a-1f96-dac0-791c-43e2d1e1cf05@web.de> (raw)
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
next reply other threads:[~2019-09-07 14:55 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-07 14:54 Markus Elfring [this message]
2019-09-07 16:05 ` [Cocci] Adjusting SmPL script “ptr_ret.cocci”? 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c8e0db8a-1f96-dac0-791c-43e2d1e1cf05@web.de \
--to=markus.elfring@web.de \
--cc=allison@lohutok.net \
--cc=cocci@systeme.lip6.fr \
--cc=gregkh@linuxfoundation.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=kstewart@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=michal.lkml@markovi.net \
--cc=nicolas.palix@imag.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).