From: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx> 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@xxxxxxxxxxxxxxxxxxxxx> --- 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