Skip to contentSkip to conversation

Coccinelle: misc: Improve the script for more accurate results

PATCH Superseded Vaishali Thakkar 2 participants 8 messages Oct 24, 2016 – Nov 18, 2016 Coccinelle/Semantic Patches (SmPL)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover Coccinelle: misc: Improve the script for more accurate results

Few changes to improve the results given by the irqf_oneshot.cocci:

- Change in the matching rules to eliminate false postives in the patch mode
- Change in the context mode to eliminate false postives in the context mode
- Support for the missing devm_request_threaded_irq in context, report and org mode

Changes since v2:
- Add missing initialization of metavariables
Changes since v1:
- Split patch in to the patchset

Vaishali Thakkar (3):
Coccinelle: misc: Improve the matching of rules
Coccinelle: misc: Improve the result given by context mode
Coccinelle: misc: Add support for devm variant in all modes

 scripts/coccinelle/misc/irqf_oneshot.cocci | 45 ++++++++++++++++++++++++------
 1 file changed, 37 insertions(+), 8 deletions(-)
Signature · 1 line
2.1.4
#1 lore raw

PATCH v3 1/3 Coccinelle: misc: Improve the matching of rules

Currently because of the left associativity of the operators, pattern IRQF_ONESHOT | flags does not match with the pattern when we have more than one flag after the disjunction. This eventually results in giving false positives by the script. This patch eliminates these FPs by improving the rule.

---
Changes since v2:
- No change in this patch
Changes since v1:
- Splitted patch in the patchset

---
 scripts/coccinelle/misc/irqf_oneshot.cocci | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)
scripts/coccinelle/misc/irqf_oneshot.cocci +24 -6
index b421150..a8537fb 100644
@@ -18,13 +18,12 @@ virtual report
 expression dev;
 expression irq;
 expression thread_fn;
-expression flags;
 position p;
 @@
 (
 request_threaded_irq at p(irq, NULL, thread_fn,
 (
-flags | IRQF_ONESHOT
+IRQF_ONESHOT | ...
 |
 IRQF_ONESHOT
 )
@@ -32,20 +31,39 @@ IRQF_ONESHOT
 |
 devm_request_threaded_irq at p(dev, irq, NULL, thread_fn,
 (
-flags | IRQF_ONESHOT
+IRQF_ONESHOT | ...
 |
 IRQF_ONESHOT
 )
 , ...)
 )
 
- at depends on patch@
+ at r2@
 expression dev;
 expression irq;
 expression thread_fn;
 expression flags;
+expression ret;
 position p != r1.p;
 @@
+flags = IRQF_ONESHOT | ...;
+(
+ret = request_threaded_irq at p(irq, NULL, thread_fn, flags, ...);
+|
+ret = devm_request_threaded_irq at p(dev, irq, NULL, thread_fn, flags, ...);
+|
+return request_threaded_irq at p(irq, NULL, thread_fn, flags, ...);
+|
+return devm_request_threaded_irq at p(dev, irq, NULL, thread_fn, flags, ...);
+)
+
+ at depends on patch@
+expression dev;
+expression irq;
+expression thread_fn;
+expression flags;
+position p != {r1.p,r2.p};
+@@
 (
 request_threaded_irq at p(irq, NULL, thread_fn,
 (
@@ -69,13 +87,13 @@ devm_request_threaded_irq at p(dev, irq, NULL, thread_fn,
 )
 
 @depends on context@
-position p != r1.p;
+position p != {r1.p,r2.p};
 @@
 *request_threaded_irq at p(...)
 
 @match depends on report || org@
 expression irq;
-position p != r1.p;
+position p != {r1.p,r2.p};
 @@
 request_threaded_irq at p(irq, NULL, ...)
 
Signature · 1 line
2.1.4
#2 lore raw

Re: [PATCH v3 1/3] Coccinelle: misc: Improve the matching of rules

Quoted 56 lines · Vaishali Thakkar

Currently because of the left associativity of the operators, pattern IRQF_ONESHOT | flags does not match with the pattern when we have more than one flag after the disjunction. This eventually results in giving false positives by the script. This patch eliminates these FPs by improving the rule.

---
Changes since v2:
- No change in this patch
Changes since v1:
- Splitted patch in the patchset

---
 scripts/coccinelle/misc/irqf_oneshot.cocci | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)
scripts/coccinelle/misc/irqf_oneshot.cocci +4 -4
index b421150..a8537fb 100644
@@ -18,13 +18,12 @@ virtual report
 expression dev;
 expression irq;
 expression thread_fn;
-expression flags;
 position p;
 @@
 (
 request_threaded_irq at p(irq, NULL, thread_fn,
 (
-flags | IRQF_ONESHOT
+IRQF_ONESHOT | ...
 |
 IRQF_ONESHOT
 )
@@ -32,20 +31,39 @@ IRQF_ONESHOT
 |
 devm_request_threaded_irq at p(dev, irq, NULL, thread_fn,
 (
-flags | IRQF_ONESHOT
+IRQF_ONESHOT | ...
 |
 IRQF_ONESHOT
 )
 , ...)
 )
 
- at depends on patch@
+ at r2@
 expression dev;
 expression irq;
 expression thread_fn;
 expression flags;
+expression ret;
 position p != r1.p;
 @@

scripts/coccinelle/misc/irqf_oneshot.cocci IRQF_ONESHOT · line 58

Quoted 10 lines
scripts/coccinelle/misc/irqf_oneshot.cocci +10 -0
+flags = IRQF_ONESHOT | ...;
+(
+ret = request_threaded_irq at p(irq, NULL, thread_fn, flags, ...);
+|
+ret = devm_request_threaded_irq at p(dev, irq, NULL, thread_fn, flags, ...);
+|
+return request_threaded_irq at p(irq, NULL, thread_fn, flags, ...);
+|
+return devm_request_threaded_irq at p(dev, irq, NULL, thread_fn, flags, ...);
+)

This rule needs some improvement.

flags = IRQF_ONESHOT | ...;

should be replaced by:

(
flags = IRQF_ONESHOT | ...
|
flags |= IRQF_ONESHOT | ...
)
... when != flags = e

where e should be a new expression metavariable. This effects a number of changes. 1) Dropping the ; after the assignment allows an isomorphism to trigger that allows it to match a variable declaration as well, 2) IRQF_ONESHOT can be added after the original initialization by a |=, 3) there can be some instructions between the initialization of flags and the use.

Afterwards, the big disjunction with the irq calls is too specific. In particular, these calls can also occur in an if test. The disjunction should be replaced by the following:

(
request_threaded_irq at p(irq, NULL, thread_fn, flags, ...) |
devm_request_threaded_irq at p(dev, irq, NULL, thread_fn, flags, ...) )

julia

Quoted 31 lines
scripts/coccinelle/misc/irqf_oneshot.cocci +10 -3
+
+ at depends on patch@
+expression dev;
+expression irq;
+expression thread_fn;
+expression flags;
+position p != {r1.p,r2.p};
+@@
 (
 request_threaded_irq at p(irq, NULL, thread_fn,
 (
@@ -69,13 +87,13 @@ devm_request_threaded_irq at p(dev, irq, NULL, thread_fn,
 )
 
 @depends on context@
-position p != r1.p;
+position p != {r1.p,r2.p};
 @@
 *request_threaded_irq at p(...)
 
 @match depends on report || org@
 expression irq;
-position p != r1.p;
+position p != {r1.p,r2.p};
 @@
 request_threaded_irq at p(irq, NULL, ...)
 
--

2.1.4

#3 lore raw

Re: [PATCH v3 1/3] Coccinelle: misc: Improve the matching of rules

Quoted 84 lines · Julia Lawall
Quoted 56 lines · Vaishali Thakkar

Currently because of the left associativity of the operators, pattern IRQF_ONESHOT | flags does not match with the pattern when we have more than one flag after the disjunction. This eventually results in giving false positives by the script. This patch eliminates these FPs by improving the rule.

---
Changes since v2:
- No change in this patch
Changes since v1:
- Splitted patch in the patchset

---
 scripts/coccinelle/misc/irqf_oneshot.cocci | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)
scripts/coccinelle/misc/irqf_oneshot.cocci +4 -4
index b421150..a8537fb 100644
@@ -18,13 +18,12 @@ virtual report
 expression dev;
 expression irq;
 expression thread_fn;
-expression flags;
 position p;
 @@
 (
 request_threaded_irq at p(irq, NULL, thread_fn,
 (
-flags | IRQF_ONESHOT
+IRQF_ONESHOT | ...
 |
 IRQF_ONESHOT
 )
@@ -32,20 +31,39 @@ IRQF_ONESHOT
 |
 devm_request_threaded_irq at p(dev, irq, NULL, thread_fn,
 (
-flags | IRQF_ONESHOT
+IRQF_ONESHOT | ...
 |
 IRQF_ONESHOT
 )
 , ...)
 )
 
- at depends on patch@
+ at r2@
 expression dev;
 expression irq;
 expression thread_fn;
 expression flags;
+expression ret;
 position p != r1.p;
 @@

scripts/coccinelle/misc/irqf_oneshot.cocci IRQF_ONESHOT · line 58

Quoted 10 lines
scripts/coccinelle/misc/irqf_oneshot.cocci +10 -0
+flags = IRQF_ONESHOT | ...;
+(
+ret = request_threaded_irq at p(irq, NULL, thread_fn, flags, ...);
+|
+ret = devm_request_threaded_irq at p(dev, irq, NULL, thread_fn, flags, ...);
+|
+return request_threaded_irq at p(irq, NULL, thread_fn, flags, ...);
+|
+return devm_request_threaded_irq at p(dev, irq, NULL, thread_fn, flags, ...);
+)

This rule needs some improvement.

flags = IRQF_ONESHOT | ...;

should be replaced by:

(
flags = IRQF_ONESHOT | ...
|
flags |= IRQF_ONESHOT | ...
)
... when != flags = e

Quoted 6 lines

where e should be a new expression metavariable. This effects a number of changes. 1) Dropping the ; after the assignment allows an isomorphism to trigger that allows it to match a variable declaration as well, 2) IRQF_ONESHOT can be added after the original initialization by a |=, 3) there can be some instructions between the initialization of flags and the use.

Ok, this makes sense.

Quoted 9 lines

Afterwards, the big disjunction with the irq calls is too specific. In particular, these calls can also occur in an if test. The disjunction should be replaced by the following:

(
request_threaded_irq at p(irq, NULL, thread_fn, flags, ...) |
devm_request_threaded_irq at p(dev, irq, NULL, thread_fn, flags, ...) )

Ok, primary motivation with having specified pattern was to have less running time. But as discussed, it doesn't make much difference. So, going with the more general way sounds good.

Thanks for the suggestions. I'll send the the revised version with these changes.

Quoted 34 lines

julia

Quoted 31 lines
scripts/coccinelle/misc/irqf_oneshot.cocci +10 -3
+
+ at depends on patch@
+expression dev;
+expression irq;
+expression thread_fn;
+expression flags;
+position p != {r1.p,r2.p};
+@@
 (
 request_threaded_irq at p(irq, NULL, thread_fn,
 (
@@ -69,13 +87,13 @@ devm_request_threaded_irq at p(dev, irq, NULL, thread_fn,
 )
 
 @depends on context@
-position p != r1.p;
+position p != {r1.p,r2.p};
 @@
 *request_threaded_irq at p(...)
 
 @match depends on report || org@
 expression irq;
-position p != r1.p;
+position p != {r1.p,r2.p};
 @@
 request_threaded_irq at p(irq, NULL, ...)
 
--

2.1.4

Signature · 1 line
Vaishali
#4 lore raw

PATCH v3 2/3 Coccinelle: misc: Improve the result given by context mode

In reply to Vaishali Thakkar

To eliminate false positives given by the context mode, add necessary arguments for the function request_threaded_irq.

---
Changes since v2:
- Add missing declaration of metavariable irq
Changes since v1:
- Split patch in to the patch set

---
 scripts/coccinelle/misc/irqf_oneshot.cocci | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/coccinelle/misc/irqf_oneshot.cocci +2 -1
index a8537fb..e53372e 100644
@@ -87,9 +87,10 @@ devm_request_threaded_irq at p(dev, irq, NULL, thread_fn,
 )
 
 @depends on context@
+expression irq;
 position p != {r1.p,r2.p};
 @@
-*request_threaded_irq at p(...)
+*request_threaded_irq at p(irq, NULL, ...)
 
 @match depends on report || org@
 expression irq;
Signature · 1 line
2.1.4
Acked-by on v3 2/3
#5 lore raw

Re: [PATCH v3 2/3] Coccinelle: misc: Improve the result given by context mode

Quoted 4 lines · Vaishali Thakkar

To eliminate false positives given by the context mode, add necessary arguments for the function request_threaded_irq.

Quoted 29 lines

---
Changes since v2:
- Add missing declaration of metavariable irq
Changes since v1:
- Split patch in to the patch set

---
 scripts/coccinelle/misc/irqf_oneshot.cocci | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/coccinelle/misc/irqf_oneshot.cocci +2 -2
index a8537fb..e53372e 100644
@@ -87,9 +87,10 @@ devm_request_threaded_irq at p(dev, irq, NULL, thread_fn,
 )
 
 @depends on context@
+expression irq;
 position p != {r1.p,r2.p};
 @@
-*request_threaded_irq at p(...)
+*request_threaded_irq at p(irq, NULL, ...)
 
 @match depends on report || org@
 expression irq;
--

2.1.4

#6 lore raw

PATCH v3 3/3 Coccinelle: misc: Add support for devm variant in all modes

In reply to Vaishali Thakkar

Add missing support for the devm_request_threaded_irq in the rules of context, report and org modes.

Misc:
----
To be consistent with other scripts, change confidence level of the script to 'Moderate'.

---
Changes since v2:
- Add missing initialization of metavariables
Changes since v1:
- Split patch in to the patchset

---
 scripts/coccinelle/misc/irqf_oneshot.cocci | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
scripts/coccinelle/misc/irqf_oneshot.cocci +11 -1
index e53372e..ca78125 100644
@@ -5,7 +5,7 @@
 /// So pass the IRQF_ONESHOT flag in this case.
 ///
 //
-// Confidence: Good
+// Confidence: Moderate
 // Comments:
 // Options: --no-includes
 
@@ -87,16 +87,26 @@ devm_request_threaded_irq at p(dev, irq, NULL, thread_fn,
 )
 
 @depends on context@
+expression dev;
 expression irq;
 position p != {r1.p,r2.p};
 @@
+(
 *request_threaded_irq at p(irq, NULL, ...)
+|
+*devm_request_threaded_irq at p(dev, irq, NULL, ...)
+)
 
 @match depends on report || org@
+expression dev;
 expression irq;
 position p != {r1.p,r2.p};
 @@
+(
 request_threaded_irq at p(irq, NULL, ...)
+|
+devm_request_threaded_irq at p(dev, irq, NULL, ...)
+)
 
 @script:python depends on org@
 p << match.p;
Signature · 1 line
2.1.4
Acked-by on v3 3/3
#7 lore raw

Re: [PATCH v3 3/3] Coccinelle: misc: Add support for devm variant in all modes

Quoted 9 lines · Vaishali Thakkar

Add missing support for the devm_request_threaded_irq in the rules of context, report and org modes.

Misc:
----
To be consistent with other scripts, change confidence level of the script to 'Moderate'.

Quoted 53 lines

---
Changes since v2:
- Add missing initialization of metavariables
Changes since v1:
- Split patch in to the patchset

---
 scripts/coccinelle/misc/irqf_oneshot.cocci | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
scripts/coccinelle/misc/irqf_oneshot.cocci +11 -2
index e53372e..ca78125 100644
@@ -5,7 +5,7 @@
 /// So pass the IRQF_ONESHOT flag in this case.
 ///
 //
-// Confidence: Good
+// Confidence: Moderate
 // Comments:
 // Options: --no-includes
 
@@ -87,16 +87,26 @@ devm_request_threaded_irq at p(dev, irq, NULL, thread_fn,
 )
 
 @depends on context@
+expression dev;
 expression irq;
 position p != {r1.p,r2.p};
 @@
+(
 *request_threaded_irq at p(irq, NULL, ...)
+|
+*devm_request_threaded_irq at p(dev, irq, NULL, ...)
+)
 
 @match depends on report || org@
+expression dev;
 expression irq;
 position p != {r1.p,r2.p};
 @@
+(
 request_threaded_irq at p(irq, NULL, ...)
+|
+devm_request_threaded_irq at p(dev, irq, NULL, ...)
+)
 
 @script:python depends on org@
 p << match.p;
--

2.1.4