lkml.org 
[lkml]   [2019]   [Sep]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectAdjusting SmPL script “ptr ret.cocci”?
Date
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

\
 
 \ /
  Last update: 2019-09-07 16:55    [W:1.354 / U:0.160 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site