Coccinelle archive on lore.kernel.org
 help / color / Atom feed
* [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

end of thread, back to index

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

Coccinelle archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/cocci/0 cocci/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 cocci cocci/ https://lore.kernel.org/cocci \
		cocci@systeme.lip6.fr cocci@archiver.kernel.org
	public-inbox-index cocci

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/fr.lip6.systeme.cocci


AGPL code for this site: git clone https://public-inbox.org/ public-inbox