Skip to contentSkip to conversation

coccinelle: put_device: reduce false positives

PATCH In review Wen Yang 5 participants 42 messages Mar 23, 2019 – Jul 6, 2019

Subsystems (2)
lore
Share & tools
lore

Wen Yang

author
#0 lore raw

PATCH 1/1 coccinelle: put_device: reduce false positives

Don't complain about a return when this function returns "&pdev->dev".

Cc Julia Lawall <[email protected]>
Cc Gilles Muller <[email protected]>
Cc Nicolas Palix <[email protected]>
Cc Michal Marek <[email protected]>
Cc Masahiro Yamada <[email protected]>
---
 scripts/coccinelle/free/put_device.cocci | 1 +
 1 file changed, 1 insertion(+)
scripts/coccinelle/free/put_device.cocci +1 -0
index 7395697..c9f071b 100644
@@ -32,6 +32,7 @@ if (id == NULL || ...) { ... return ...; }
 (    id
 |    (T2)dev_get_drvdata(&id->dev)
 |    (T3)platform_get_drvdata(id)
+|    &id->dev
 );
 | return@p2 ...;
 )
Signature · 1 line
2.9.5
Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Wen Yang

Don't complain about a return when this function returns "&pdev->dev".

Cc Julia Lawall <[email protected]>
Cc Gilles Muller <[email protected]>
Cc Nicolas Palix <[email protected]>
Cc Michal Marek <[email protected]>
Cc Masahiro Yamada <[email protected]>
Quoted 20 lines
---
 scripts/coccinelle/free/put_device.cocci | 1 +
 1 file changed, 1 insertion(+)
scripts/coccinelle/free/put_device.cocci +1 -1
index 7395697..c9f071b 100644
@@ -32,6 +32,7 @@ if (id == NULL || ...) { ... return ...; }
 (    id
 |    (T2)dev_get_drvdata(&id->dev)
 |    (T3)platform_get_drvdata(id)
+|    &id->dev
 );
 | return@p2 ...;
 )
--

2.9.5

#2 lore raw
In reply to Wen Yang
Quoted 1 line

Don't complain about a return when this function returns "&pdev->dev".

Would this information qualify to add the tag “Fixes” to the commit message?

Regards,
Markus

#3 lore raw
Quoted 3 lines · Markus Elfring
Quoted 1 line

Don't complain about a return when this function returns "&pdev->dev".

Would this information qualify to add the tag “Fixes” to the commit message?

Fixes tags relate to stable kernels, so that one can see which stable kernels a particular patch should be propagated to. There is no need to propagate patches on semantic patches to stable kernels. People who run stable kernels are interested in their behavior, not the bug finding rules that they contain.

julia

#4 lore raw
Quoted 6 lines · Julia Lawall
Quoted 2 lines · Markus Elfring
Quoted 1 line

Don't complain about a return when this function returns "&pdev->dev".

Quoted 7 lines
Quoted 1 line

Would this information qualify to add the tag “Fixes” to the commit message?

Fixes tags relate to stable kernels, so that one can see which stable kernels a particular patch should be propagated to. There is no need to propagate patches on semantic patches to stable kernels. People who run stable kernels are interested in their behavior, not the bug finding rules that they contain.

The Fixes tag is not just about stable... For example, we use them for statistics to see how quickly bugs get fixed etc.

regards,
dan carpenter

#5 lore raw
Quoted 9 lines · Dan Carpenter
Quoted 8 lines · Julia Lawall
Quoted 3 lines · Markus Elfring
Quoted 1 line

Don't complain about a return when this function returns "&pdev->dev".

Would this information qualify to add the tag “Fixes” to the commit message?

Quoted 8 lines
Quoted 5 lines

Fixes tags relate to stable kernels, so that one can see which stable kernels a particular patch should be propagated to. There is no need to propagate patches on semantic patches to stable kernels. People who run stable kernels are interested in their behavior, not the bug finding rules that they contain.

The Fixes tag is not just about stable... For example, we use them for statistics to see how quickly bugs get fixed etc.

OK. But still do we need fixes tags for bug finding rules? Perhaps if the previous version was really broken, and it would be really undesirable to use it.

thanks,
julia

#6 lore raw
Quoted 19 lines · Julia Lawall
Quoted 15 lines · Dan Carpenter
Quoted 13 lines · Julia Lawall
Quoted 3 lines · Markus Elfring
Quoted 1 line

Don't complain about a return when this function returns "&pdev->dev".

Would this information qualify to add the tag “Fixes” to the commit message?

Fixes tags relate to stable kernels, so that one can see which stable kernels a particular patch should be propagated to. There is no need to propagate patches on semantic patches to stable kernels. People who run stable kernels are interested in their behavior, not the bug finding rules that they contain.

Quoted 6 lines
Quoted 2 lines

The Fixes tag is not just about stable... For example, we use them for statistics to see how quickly bugs get fixed etc.

OK. But still do we need fixes tags for bug finding rules? Perhaps if the previous version was really broken, and it would be really undesirable to use it.

It's not worth resending a patch for that, but I probably would use the fixes tag. It depends on your definition of "bug" really... I tell people not to use Fixes for spelling mistakes and unused variables. But I do use the Fixes tag for things like "an off by one in a sanity check which doesn't affect run time because the index is always correct".

regards,
dan carpenter

#7 lore raw
Quoted 27 lines · Dan Carpenter
Quoted 19 lines · Julia Lawall
Quoted 15 lines · Dan Carpenter
Quoted 13 lines · Julia Lawall
Quoted 3 lines · Markus Elfring
Quoted 1 line

Don't complain about a return when this function returns "&pdev->dev".

Would this information qualify to add the tag “Fixes” to the commit message?

Fixes tags relate to stable kernels, so that one can see which stable kernels a particular patch should be propagated to. There is no need to propagate patches on semantic patches to stable kernels. People who run stable kernels are interested in their behavior, not the bug finding rules that they contain.

Quoted 6 lines
Quoted 2 lines

The Fixes tag is not just about stable... For example, we use them for statistics to see how quickly bugs get fixed etc.

OK. But still do we need fixes tags for bug finding rules? Perhaps if the previous version was really broken, and it would be really undesirable to use it.

Quoted 5 lines

It's not worth resending a patch for that, but I probably would use the fixes tag. It depends on your definition of "bug" really... I tell people not to use Fixes for spelling mistakes and unused variables. But I do use the Fixes tag for things like "an off by one in a sanity check which doesn't affect run time because the index is always correct".

OK, thanks.

julia

#8 lore raw
Quoted 38 lines · Julia Lawall
Quoted 27 lines · Dan Carpenter
Quoted 19 lines · Julia Lawall
Quoted 15 lines · Dan Carpenter
Quoted 13 lines · Julia Lawall
Quoted 3 lines · Markus Elfring
Quoted 1 line

Don't complain about a return when this function returns "&pdev->dev".

Would this information qualify to add the tag “Fixes” to the commit message?

Fixes tags relate to stable kernels, so that one can see which stable kernels a particular patch should be propagated to. There is no need to propagate patches on semantic patches to stable kernels. People who run stable kernels are interested in their behavior, not the bug finding rules that they contain.

Quoted 6 lines
Quoted 2 lines

The Fixes tag is not just about stable... For example, we use them for statistics to see how quickly bugs get fixed etc.

OK. But still do we need fixes tags for bug finding rules? Perhaps if the previous version was really broken, and it would be really undesirable to use it.

Quoted 5 lines

It's not worth resending a patch for that, but I probably would use the fixes tag. It depends on your definition of "bug" really... I tell people not to use Fixes for spelling mistakes and unused variables. But I do use the Fixes tag for things like "an off by one in a sanity check which doesn't affect run time because the index is always correct".

Quoted 3 lines

OK, thanks.

julia

I added Fixes: tag,
and applied to linux-kbuild/fixes.

Thanks.

Signature · 2 lines
Best Regards
Masahiro Yamada
#9 lore raw
Quoted 39 lines · Masahiro Yamada
Quoted 38 lines · Julia Lawall
Quoted 32 lines · Dan Carpenter
Quoted 19 lines · Julia Lawall
Quoted 15 lines · Dan Carpenter
Quoted 13 lines · Julia Lawall
Quoted 3 lines · Markus Elfring
Quoted 1 line

Don't complain about a return when this function returns "&pdev->dev".

Would this information qualify to add the tag “Fixes” to the commit message?

Fixes tags relate to stable kernels, so that one can see which stable kernels a particular patch should be propagated to. There is no need to propagate patches on semantic patches to stable kernels. People who run stable kernels are interested in their behavior, not the bug finding rules that they contain.

Quoted 6 lines
Quoted 2 lines

The Fixes tag is not just about stable... For example, we use them for statistics to see how quickly bugs get fixed etc.

OK. But still do we need fixes tags for bug finding rules? Perhaps if the previous version was really broken, and it would be really undesirable to use it.

It's not worth resending a patch for that, but I probably would use the fixes tag. It depends on your definition of "bug" really... I tell people not to use Fixes for spelling mistakes and unused variables. But I do use the Fixes tag for things like "an off by one in a sanity check which doesn't affect run time because the index is always correct".

Quoted 6 lines
Quoted 3 lines

OK, thanks.

julia

I added Fixes: tag,
and applied to linux-kbuild/fixes.

Thanks!

julia

Quoted 7 lines

Thanks.

--
Best Regards
Masahiro Yamada

#11 lore raw

Re: Coccinelle: put_device: reduce false positives

Quoted 7 lines · Markus Elfring
Quoted 2 lines

I added Fixes: tag,
and applied to linux-kbuild/fixes.

Will this extension trigger further adjustments for similar SmPL scripts?

Example:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/scripts/coccinelle/free/pci_free_consistent.cocci?id÷b167113753e95ae61383e234f8d10142782ace

If there are false positives caused by this or other scripts, feel free to submit a patch.

julia

#12 lore raw

cover Coccinelle: put_device: Adjustments for a SmPL script

In reply to Wen Yang

Some adjustments were discussed also for this script a while ago. The software development attention evolved in a special way in the meantime.

See also for further background information:
https://lore.kernel.org/lkml/CAK7LNATjAsiSeZoTZ57zBHse0j5ZYY_12ZQ0gaF_oCziUWheOQ@mail.gmail.com/
https://systeme.lip6.fr/pipermail/cocci/2019-March/005692.html
https://lkml.org/lkml/2019/3/26/395

I would appreciate if corresponding implementation details will get another look.

Markus Elfring (5):
Adjust a message construction
Add a cast to an expression for an assignment
Merge four SmPL when constraints into one
Extend when constraints for two SmPL ellipses
Merge two SmPL when constraints into one

 scripts/coccinelle/free/put_device.cocci | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)

--
2.21.0

#13 lore raw

PATCH 1/5 Coccinelle: put_device: Adjust a message construction

From: Markus Elfring <[email protected]>
Date: Tue, 7 May 2019 11:20:48 +0200

The Linux coding style tolerates long string literals so that the provided information can be easier found also by search tools like grep.
Thus simplify a message construction in a SmPL rule by concatenating text with two plus operators less.

---
 scripts/coccinelle/free/put_device.cocci | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
scripts/coccinelle/free/put_device.cocci +4 -5
index c9f071b0a0ab..3ebebc064f10 100644
@@ -42,11 +42,10 @@ p1 << search.p1;
 p2 << search.p2;
 @@
 
-coccilib.report.print_report(p2[0], "ERROR: missing put_device; "
-			      + "call of_find_device_by_node on line "
-			      + p1[0].line
-			      + ", but without a corresponding object release "
-			      + "within this function.")
+coccilib.report.print_report(p2[0],
+                             "ERROR: missing put_device; call of_find_device_by_node on line "
+                             + p1[0].line
+                             + ", but without a corresponding object release within this function.")
 
 @script:python depends on org@
 p1 << search.p1;

--
2.21.0

#14 lore raw

Re: [PATCH 1/5] Coccinelle: put_device: Adjust a message construction

Quoted 8 lines · Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 7 May 2019 11:20:48 +0200

The Linux coding style tolerates long string literals so that the provided information can be easier found also by search tools like grep.
Thus simplify a message construction in a SmPL rule by concatenating text with two plus operators less.

I don't know python very well. Is there any way to unindent, so that the string doesn't exceed 80 characters, or at least no so much?

On the other hand, I would have much preferred the original msg = code. I don't understand why it is so offensive.

julia

Quoted 30 lines
---
 scripts/coccinelle/free/put_device.cocci | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
scripts/coccinelle/free/put_device.cocci +4 -6
index c9f071b0a0ab..3ebebc064f10 100644
@@ -42,11 +42,10 @@ p1 << search.p1;
 p2 << search.p2;
 @@
 
-coccilib.report.print_report(p2[0], "ERROR: missing put_device; "
-			      + "call of_find_device_by_node on line "
-			      + p1[0].line
-			      + ", but without a corresponding object release "
-			      + "within this function.")
+coccilib.report.print_report(p2[0],
+                             "ERROR: missing put_device; call of_find_device_by_node on line "
+                             + p1[0].line
+                             + ", but without a corresponding object release within this function.")
 
 @script:python depends on org@
 p1 << search.p1;
--

2.21.0

#15 lore raw

Re: [1/5] Coccinelle: put_device: Adjust a message construction

Quoted 5 lines
Quoted 2 lines

Thus simplify a message construction in a SmPL rule by concatenating text with two plus operators less.

Is there any way to unindent, so that the string doesn't exceed 80 characters, or at least no so much?

How does your concern fit to the string literal tolerance from the Linux coding style?

Quoted 2 lines

On the other hand, I would have much preferred the original msg = code. I don't understand why it is so offensive.

I suggested again to avoid the use of extra variables in such cases (also in the discussed bit of Python source code within a SmPL script).

Regards,
Markus

#16 lore raw

Re: [1/5] Coccinelle: put_device: Adjust a message construction

Quoted 8 lines · Markus Elfring
Quoted 5 lines
Quoted 2 lines

Thus simplify a message construction in a SmPL rule by concatenating text with two plus operators less.

Is there any way to unindent, so that the string doesn't exceed 80 characters, or at least no so much?

How does your concern fit to the string literal tolerance from the Linux coding style?

The point of view of the Linux kernel is that if there is no nicer way to persent the string, exceeding 80 characters is preferable to breaking the string. But here, at least if Python was not indentation sensitive, there are much nicer ways to present the string and not exceed 80 characters.

Quoted 5 lines
Quoted 2 lines

On the other hand, I would have much preferred the original msg = code. I don't understand why it is so offensive.

I suggested again to avoid the use of extra variables in such cases (also in the discussed bit of Python source code within a SmPL script).

I realize that you don't like it, although I have no idea why. Does it make the code slower? Less reliable? Less readable? I doubt any of those things. I think that staying within 80 characters would be a much greater benefit that all of these baseless concerns.

julia

Quoted 4 lines

Regards,
Markus

#17 lore raw

Re: [1/5] Coccinelle: put_device: Adjust a message construction

Quoted 2 lines

I realize that you don't like it, although I have no idea why. Does it make the code slower?

Would you like to compare the run time characteristics from creating and looking up an identifier for a Python variable to direct passing of a concatenated string for the desired function call?

Quoted 2 lines

I think that staying within 80 characters would be a much greater benefit that all of these baseless concerns.

Are you aware of another code formatting option?
https://docs.python.org/3/reference/lexical_analysis.html#string-literal-concatenation

Regards,
Markus

#18 lore raw

Re: [Cocci] [PATCH 1/5] Coccinelle: put_device: Adjust a message construction

In reply to Markus Elfring
Quoted 4 lines · Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 7 May 2019 11:20:48 +0200

Quoted 8 lines

The Linux coding style tolerates long string literals so that the provided information can be easier found also by search tools like grep.
Thus simplify a message construction in a SmPL rule by concatenating text with two plus operators less.

---

Applied to linux-kbuild.

Quoted 30 lines
 scripts/coccinelle/free/put_device.cocci | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
scripts/coccinelle/free/put_device.cocci +4 -6
index c9f071b0a0ab..3ebebc064f10 100644
@@ -42,11 +42,10 @@ p1 << search.p1;
 p2 << search.p2;
 @@
 
-coccilib.report.print_report(p2[0], "ERROR: missing put_device; "
-                             + "call of_find_device_by_node on line "
-                             + p1[0].line
-                             + ", but without a corresponding object release "
-                             + "within this function.")
+coccilib.report.print_report(p2[0],
+                             "ERROR: missing put_device; call of_find_device_by_node on line "
+                             + p1[0].line
+                             + ", but without a corresponding object release within this function.")
 
 @script:python depends on org@
 p1 << search.p1;
--

2.21.0

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

Signature · 6 lines
Best Regards
Masahiro Yamada
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
#19 lore raw

PATCH 2/5 Coccinelle: put_device: Add a cast to an expression for an assignment

In reply to Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 8 May 2019 13:50:49 +0200

Extend a when constraint in a SmPL rule so that an additional cast is optionally excluded from source code searches for an expression in assignments.

---
 scripts/coccinelle/free/put_device.cocci | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/coccinelle/free/put_device.cocci +1 -1
index 3ebebc064f10..120921366e84 100644
@@ -24,7 +24,7 @@ if (id == NULL || ...) { ... return ...; }
     when != of_dev_put(id)
     when != if (id) { ... put_device(&id->dev) ... }
     when != e1 = (T)id
-    when != e1 = &id->dev
+    when != e1 = (T)(&id->dev)
     when != e1 = get_device(&id->dev)
     when != e1 = (T1)platform_get_drvdata(id)
 (

--
2.21.0

Acked-by on v1 2/5
#20 lore raw

Re: [PATCH 2/5] Coccinelle: put_device: Add a cast to an expression for an assignment

Quoted 6 lines · Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 8 May 2019 13:50:49 +0200

Extend a when constraint in a SmPL rule so that an additional cast is optionally excluded from source code searches for an expression in assignments.

Quoted 26 lines
---
 scripts/coccinelle/free/put_device.cocci | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/coccinelle/free/put_device.cocci +1 -2
index 3ebebc064f10..120921366e84 100644
@@ -24,7 +24,7 @@ if (id == NULL || ...) { ... return ...; }
     when != of_dev_put(id)
     when != if (id) { ... put_device(&id->dev) ... }
     when != e1 = (T)id
-    when != e1 = &id->dev
+    when != e1 = (T)(&id->dev)
     when != e1 = get_device(&id->dev)
     when != e1 = (T1)platform_get_drvdata(id)
 (
--

2.21.0

#21 lore raw

Re: [Cocci] [PATCH 2/5] Coccinelle: put_device: Add a cast to an expression for an assignment

In reply to Markus Elfring
Quoted 8 lines · Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 8 May 2019 13:50:49 +0200

Extend a when constraint in a SmPL rule so that an additional cast is optionally excluded from source code searches for an expression in assignments.

Quoted 5 lines

---

Applied to linux-kbuild.

Quoted 23 lines
 scripts/coccinelle/free/put_device.cocci | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/coccinelle/free/put_device.cocci +1 -2
index 3ebebc064f10..120921366e84 100644
@@ -24,7 +24,7 @@ if (id == NULL || ...) { ... return ...; }
     when != of_dev_put(id)
     when != if (id) { ... put_device(&id->dev) ... }
     when != e1 = (T)id
-    when != e1 = &id->dev
+    when != e1 = (T)(&id->dev)
     when != e1 = get_device(&id->dev)
     when != e1 = (T1)platform_get_drvdata(id)
 (
--

2.21.0

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

Signature · 6 lines
Best Regards
Masahiro Yamada
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
#22 lore raw

PATCH 3/5 Coccinelle: put_device: Merge four SmPL when constraints into one

In reply to Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 12 May 2019 18:32:46 +0200

An assignment target was repeated in four SmPL when constraints. Combine the exclusion specifications into disjunctions for the semantic patch language so that this target is referenced only once there.

---
 scripts/coccinelle/free/put_device.cocci | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
scripts/coccinelle/free/put_device.cocci +1 -4
index 120921366e84..aae79c02c1e0 100644
@@ -23,10 +23,7 @@ if (id == NULL || ...) { ... return ...; }
     when != platform_device_put(id)
     when != of_dev_put(id)
     when != if (id) { ... put_device(&id->dev) ... }
-    when != e1 = (T)id
-    when != e1 = (T)(&id->dev)
-    when != e1 = get_device(&id->dev)
-    when != e1 = (T1)platform_get_drvdata(id)
+    when != e1 = \( (T) \( id \| (&id->dev) \) \| get_device(&id->dev) \| (T1)platform_get_drvdata(id) \)
 (
   return
 (    id

--
2.21.0

#23 lore raw

Re: [PATCH 3/5] Coccinelle: put_device: Merge four SmPL when constraints into one

Quoted 6 lines · Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 12 May 2019 18:32:46 +0200

An assignment target was repeated in four SmPL when constraints. Combine the exclusion specifications into disjunctions for the semantic patch language so that this target is referenced only once there.

NACK. This exceeds 80 characters and provides no readability benefit.

julia

Quoted 26 lines
---
 scripts/coccinelle/free/put_device.cocci | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
scripts/coccinelle/free/put_device.cocci +1 -5
index 120921366e84..aae79c02c1e0 100644
@@ -23,10 +23,7 @@ if (id == NULL || ...) { ... return ...; }
     when != platform_device_put(id)
     when != of_dev_put(id)
     when != if (id) { ... put_device(&id->dev) ... }
-    when != e1 = (T)id
-    when != e1 = (T)(&id->dev)
-    when != e1 = get_device(&id->dev)
-    when != e1 = (T1)platform_get_drvdata(id)
+    when != e1 = \( (T) \( id \| (&id->dev) \) \| get_device(&id->dev) \| (T1)platform_get_drvdata(id) \)
 (
   return
 (    id
--

2.21.0

#24 lore raw

Re: [3/5] Coccinelle: put_device: Merge four SmPL when constraints into one

Quoted 5 lines
Quoted 3 lines

An assignment target was repeated in four SmPL when constraints. Combine the exclusion specifications into disjunctions for the semantic patch language so that this target is referenced only once there.

NACK.

I find this rejection questionable.

Quoted 1 line

This exceeds 80 characters

The line became 105 characters long.
14 space characters can eventually be omitted.

Quoted 1 line

and provides no readability benefit.

I try to stress SmPL functionality in this use case.

Quoted 10 lines

scripts/coccinelle/free/put_device.cocci if (id == NULL || ...) { ... return ...; } · line 26

Quoted 10 lines

+++ b/scripts/coccinelle/free/put_device.cocci

scripts/coccinelle/free/put_device.cocci +1 -4
@@ -23,10 +23,7 @@ if (id == NULL || ...) { ... return ...; }
     when != platform_device_put(id)
     when != of_dev_put(id)
     when != if (id) { ... put_device(&id->dev) ... }
-    when != e1 = (T)id
-    when != e1 = (T)(&id->dev)
-    when != e1 = get_device(&id->dev)
-    when != e1 = (T1)platform_get_drvdata(id)
+    when != e1 = \( (T) \( id \| (&id->dev) \) \| get_device(&id->dev) \| (T1)platform_get_drvdata(id) \)

How do you think about to extend the Coccinelle software in the way that such a detailed constraint can be specified on separate lines (without duplicated SmPL code)?

How long will it take to reconsider corresponding software limitations?

Regards,
Markus

#25 lore raw

Re: [3/5] Coccinelle: put_device: Merge four SmPL when constraints into one

In reply to Julia Lawall
Quoted 5 lines
Quoted 3 lines

An assignment target was repeated in four SmPL when constraints. Combine the exclusion specifications into disjunctions for the semantic patch language so that this target is referenced only once there.

NACK.

I find this rejection questionable.

Quoted 1 line

This exceeds 80 characters

The line became 105 characters long.
14 space characters can eventually be omitted.

Quoted 1 line

and provides no readability benefit.

I try to stress SmPL functionality in this use case.

Quoted 10 lines

scripts/coccinelle/free/put_device.cocci if (id == NULL || ...) { ... return ...; } · line 26

Quoted 10 lines

+++ b/scripts/coccinelle/free/put_device.cocci

scripts/coccinelle/free/put_device.cocci +1 -4
@@ -23,10 +23,7 @@ if (id == NULL || ...) { ... return ...; }
     when != platform_device_put(id)
     when != of_dev_put(id)
     when != if (id) { ... put_device(&id->dev) ... }
-    when != e1 = (T)id
-    when != e1 = (T)(&id->dev)
-    when != e1 = get_device(&id->dev)
-    when != e1 = (T1)platform_get_drvdata(id)
+    when != e1 = \( (T) \( id \| (&id->dev) \) \| get_device(&id->dev) \| (T1)platform_get_drvdata(id) \)

How do you think about to extend the Coccinelle software in the way that such a detailed constraint can be specified on separate lines (without duplicated SmPL code)?

How long will it take to reconsider corresponding software limitations?

Regards,
Markus

#26 lore raw

Re: [3/5] Coccinelle: put_device: Merge four SmPL when constraints into one

Quoted 11 lines · Markus Elfring
Quoted 5 lines
Quoted 3 lines

An assignment target was repeated in four SmPL when constraints. Combine the exclusion specifications into disjunctions for the semantic patch language so that this target is referenced only once there.

NACK.

I find this rejection questionable.

Quoted 1 line

This exceeds 80 characters

Quoted 7 lines

The line became 105 characters long.
14 space characters can eventually be omitted.

Quoted 1 line

and provides no readability benefit.

I try to stress SmPL functionality in this use case.

That's not the goal of the semantic patches in the kernel.

The rule is fine as it is.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

+++ b/scripts/coccinelle/free/put_device.cocci

scripts/coccinelle/free/put_device.cocci +0 -1
@@ -23,10 +23,7 @@ if (id == NULL || ...) { ... return ...; }
     when != platform_device_put(id)
     when != of_dev_put(id)
     when != if (id) { ... put_device(&id->dev) ... }
-    when != e1 = (T)id
Quoted 8 lines
Quoted 4 lines

scripts/coccinelle/free/put_device.cocci if (id == NULL || ...) { ... return ...; } · line 26

Quoted 4 lines
scripts/coccinelle/free/put_device.cocci +1 -3
-    when != e1 = (T)(&id->dev)
-    when != e1 = get_device(&id->dev)
-    when != e1 = (T1)platform_get_drvdata(id)
+    when != e1 = \( (T) \( id \| (&id->dev) \) \| get_device(&id->dev) \| (T1)platform_get_drvdata(id) \)

How do you think about to extend the Coccinelle software in the way that such a detailed constraint can be specified on separate lines (without duplicated SmPL code)?

This causes some ambiguities in the parser. No change is likely to occur here.

julia

Quoted 6 lines

How long will it take to reconsider corresponding software limitations?

Regards,
Markus

#27 lore raw

Re: [3/5] Coccinelle: put_device: Merge four SmPL when constraints into one

Quoted 5 lines
Quoted 1 line

I try to stress SmPL functionality in this use case.

That's not the goal of the semantic patches in the kernel.

The rule is fine as it is.

I am curious under which circumstances other software aspects can become more relevant (as suggested).

Regards,
Markus

#28 lore raw

PATCH 4/5 Coccinelle: put_device: Extend when constraints for two SmPL ellipses

In reply to Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 13 May 2019 09:47:17 +0200

A SmPL ellipsis was specified for a search approach so that additional source code would be tolerated between an assignment to a local variable and the corresponding null pointer check.

But such code should be restricted.
* The local variable must not be reassigned there.
* It must also not be forwarded to an other assignment target.

Take additional casts for these code exclusion specifications into account together with optional parentheses.

Fixes da9cfb87a44da61f2403c4312916befcb6b6d7e8 ("coccinelle: semantic code search for missing put_device()")
---
 scripts/coccinelle/free/put_device.cocci | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
scripts/coccinelle/free/put_device.cocci +4 -2
index aae79c02c1e0..28b0be53fb3f 100644
@@ -13,13 +13,15 @@ virtual org
 local idexpression id;
 expression x,e,e1;
 position p1,p2;
-type T,T1,T2,T3;
+type T,T1,T2,T3,T4,T5,T6;
 @@
 
 id = of_find_device_by_node@p1(x)
-... when != e = id
+ ... when != e = (T4)(id)
+     when != id = (T5)(e)
 if (id == NULL || ...) { ... return ...; }
 ... when != put_device(&id->dev)
+    when != id = (T6)(e)
     when != platform_device_put(id)
     when != of_dev_put(id)
     when != if (id) { ... put_device(&id->dev) ... }

--
2.21.0

#29 lore raw

PATCH 4/5 Coccinelle: put_device: Extend when constraints for two SmPL ellipses

In reply to Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 13 May 2019 09:47:17 +0200

A SmPL ellipsis was specified for a search approach so that additional source code would be tolerated between an assignment to a local variable and the corresponding null pointer check.

But such code should be restricted.
* The local variable must not be reassigned there.
* It must also not be forwarded to an other assignment target.

Take additional casts for these code exclusion specifications into account together with optional parentheses.

Fixes da9cfb87a44da61f2403c4312916befcb6b6d7e8 ("coccinelle: semantic code search for missing put_device()")
---
 scripts/coccinelle/free/put_device.cocci | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
scripts/coccinelle/free/put_device.cocci +4 -2
index aae79c02c1e0..28b0be53fb3f 100644
@@ -13,13 +13,15 @@ virtual org
 local idexpression id;
 expression x,e,e1;
 position p1,p2;
-type T,T1,T2,T3;
+type T,T1,T2,T3,T4,T5,T6;
 @@
 
 id = of_find_device_by_node@p1(x)
-... when != e = id
+ ... when != e = (T4)(id)
+     when != id = (T5)(e)
 if (id == NULL || ...) { ... return ...; }
 ... when != put_device(&id->dev)
+    when != id = (T6)(e)
     when != platform_device_put(id)
     when != of_dev_put(id)
     when != if (id) { ... put_device(&id->dev) ... }

--
2.21.0

#30 lore raw

Re: [PATCH 4/5] Coccinelle: put_device: Extend when constraints for two SmPL ellipses

Quoted 7 lines · Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 13 May 2019 09:47:17 +0200

A SmPL ellipsis was specified for a search approach so that additional source code would be tolerated between an assignment to a local variable and the corresponding null pointer check.

Quoted 6 lines

But such code should be restricted.
* The local variable must not be reassigned there.
* It must also not be forwarded to an other assignment target.

Take additional casts for these code exclusion specifications into account together with optional parentheses.

NACK. You don't need so many type metavariables. Type metavariables in the same ... can be the same.

julia

Quoted 35 lines
Fixes da9cfb87a44da61f2403c4312916befcb6b6d7e8 ("coccinelle: semantic code search for missing put_device()")
---
 scripts/coccinelle/free/put_device.cocci | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
scripts/coccinelle/free/put_device.cocci +4 -3
index aae79c02c1e0..28b0be53fb3f 100644
@@ -13,13 +13,15 @@ virtual org
 local idexpression id;
 expression x,e,e1;
 position p1,p2;
-type T,T1,T2,T3;
+type T,T1,T2,T3,T4,T5,T6;
 @@
 
 id = of_find_device_by_node@p1(x)
-... when != e = id
+ ... when != e = (T4)(id)
+     when != id = (T5)(e)
 if (id == NULL || ...) { ... return ...; }
 ... when != put_device(&id->dev)
+    when != id = (T6)(e)
     when != platform_device_put(id)
     when != of_dev_put(id)
     when != if (id) { ... put_device(&id->dev) ... }
--

2.21.0

#31 lore raw

Re: [4/5] Coccinelle: put_device: Extend when constraints for two SmPL ellipses

Quoted 4 lines
Quoted 2 lines

Take additional casts for these code exclusion specifications into account together with optional parentheses.

NACK.

I find this rejection surprising.

Quoted 1 line

You don't need so many type metavariables.

I got an other software development opinion for this aspect.

Yesterday we started to clarify consequences from the isomorphism specification “drop_cast” (for SmPL code).
https://github.com/coccinelle/coccinelle/blob/32d3b89ad909316464344a5f61a8092d8d702321/standard.iso#L52

Information like the following influenced my design decision to add three metavariables here.

elfring@Sonne:~/Projekte/Linux/next-patched> spatch --parse-cocci scripts/coccinelle/free/put_device.cocci …
warning: iso drop_cast does not match the code below on line -1
T (T )id

pure metavariable T is matched against the following nonpure code:
T
…

Quoted 1 line

Type metavariables in the same ... can be the same.

I would find it also occasionally nice when multiple SmPL ellipses can refer to identical type casts.

* The under-documented “type purity” hinders this at the moment.

* But I got the impression that it can be safer to distinguish these code variants better.

Regards,
Markus

#32 lore raw

Re: [4/5] Coccinelle: put_device: Extend when constraints for two SmPL ellipses

In reply to Julia Lawall
Quoted 4 lines
Quoted 4 lines

A SmPL ellipsis was specified for a search approach so that additional source code would be tolerated between an assignment to a local variable and the corresponding null pointer check.

Quoted 8 lines
Quoted 6 lines

But such code should be restricted.
* The local variable must not be reassigned there.
* It must also not be forwarded to an other assignment target.

Take additional casts for these code exclusion specifications into account together with optional parentheses.

NACK.

Can you agree to any information which I presented in the commit message?

Quoted 1 line

You don't need so many type metavariables.

It seems that the Coccinelle software can cope also with my SmPL code addition. You might feel uncomfortable with the suggested changes for a while.

Quoted 1 line

Type metavariables in the same ... can be the same.

Such information is good to know for the proper usage of specifications after a SmPL ellipsis.

* Can it become required to identify involved source code placeholders by extra metavariables?

* Would you like to clarify the probability any more how often the shown type casts will be identical?

Regards,
Markus

#33 lore raw

Re: [4/5] Coccinelle: put_device: Extend when constraints for two SmPL ellipses

Quoted 13 lines · Markus Elfring
Quoted 4 lines
Quoted 4 lines

A SmPL ellipsis was specified for a search approach so that additional source code would be tolerated between an assignment to a local variable and the corresponding null pointer check.

Quoted 8 lines
Quoted 6 lines

But such code should be restricted.
* The local variable must not be reassigned there.
* It must also not be forwarded to an other assignment target.

Take additional casts for these code exclusion specifications into account together with optional parentheses.

NACK.

Quoted 7 lines

Can you agree to any information which I presented in the commit message?

Quoted 1 line

You don't need so many type metavariables.

It seems that the Coccinelle software can cope also with my SmPL code addition. You might feel uncomfortable with the suggested changes for a while.

It's ugly. Much more ugly than msg =

Quoted 9 lines
Quoted 3 lines

Type metavariables in the same ... can be the same.

Such information is good to know for the proper usage of specifications after a SmPL ellipsis.

* Can it become required to identify involved source code placeholders by extra metavariables?

I don't understand the question.

Quoted 2 lines

* Would you like to clarify the probability any more how often the shown type casts will be identical?

No idea about this one either.

Basically, if you have T && T, the two T's have to be the same, and T is not pure. If you have T || T, then only one will be matched and T remains pure. If you have T on two separate ...s then you are in the && case. If you have T in two branches of a disjunction or in two whens on the same ... you are in the || case. Just as you can use the variable e1 over and over on the same when, you can use the same T.

julia

#34 lore raw

Re: [4/5] Coccinelle: put_device: Extend when constraints for two SmPL ellipses

Quoted 1 line
Quoted 1 line

Can you agree to any information which I presented in the commit message?

Do you find this description inappropriate?

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

You don't need so many type metavariables.

It seems that the Coccinelle software can cope also with my SmPL code addition. You might feel uncomfortable with the suggested changes for a while.

It's ugly. Much more ugly than msg =

The clarification of this change reluctance might become more interesting. I got convinced that there is a need for further software updates.

Quoted 4 lines
Quoted 2 lines

* Can it become required to identify involved source code placeholders by extra metavariables?

I don't understand the question.

Wen Yang was planning a corresponding modification since 2019-02-19.
https://lore.kernel.org/cocci/[email protected]/
https://systeme.lip6.fr/pipermail/cocci/2019-February/005620.html

I got into the development mood to contribute another concrete update suggestion for an open issue in affected scripts for the semantic patch language. Do you recognise the need for the extension of exclusion specifications here?

Quoted 4 lines
Quoted 2 lines

* Would you like to clarify the probability any more how often the shown type casts will be identical?

No idea about this one either.

I am curious if helpful ideas will be added also by other contributors.

Quoted 1 line

Basically, if you have T && T, the two T's have to be the same,

Such an expectation might be logical.

Quoted 1 line

and T is not pure.

This information triggers various communication difficulties.

Quoted 1 line

If you have T on two separate ...s then you are in the && case.

I agree to this view also according the application of two ellipses in the SmPL rule “search”.

Quoted 2 lines

If you have T in two branches of a disjunction or in two whens on the same ... you are in the || case.

It is clear that disjunctions will check code alternatives here. The clarification of consequences around the interpretation of “type purity” might distract from the final solution.

How many (optional) type casts would we like to handle by the discussed source code search approach?

Regards,
Markus

#35 lore raw

Re: [Cocci] [4/5] Coccinelle: put_device: Extend when constraints for twoSmPL ellipses

Quoted 17 lines

Subject: Re: [4/5] Coccinelle: put_device: Extend when constraints for twoSmPL ellipses

Quoted 1 line
Quoted 1 line

Can you agree to any information which I presented in the commit message?

Do you find this description inappropriate?

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

You don't need so many type metavariables.

It seems that the Coccinelle software can cope also with my SmPL code addition. You might feel uncomfortable with the suggested changes for a while.

It's ugly. Much more ugly than msg =

The clarification of this change reluctance might become more interesting. I got convinced that there is a need for further software updates.

Quoted 9 lines
Quoted 4 lines
Quoted 2 lines

* Can it become required to identify involved source code placeholders by extra metavariables?

I don't understand the question.

Wen Yang was planning a corresponding modification since 2019-02-19.
https://lore.kernel.org/cocci/[email protected]/
https://systeme.lip6.fr/pipermail/cocci/2019-February/005620.html

Hi Markus,
I did another experiment at that time and found that this modification will reduce the false positive rate, but it may also reduce the recall rate.

Could we use it to find out as many bugs as possible in the current kernel and then modify it?

https://systeme.lip6.fr/pipermail/cocci/2019-February/005626.html

Thanks.

--
Regards,
Wen

Quoted 5 lines

I got into the development mood to contribute another concrete update suggestion for an open issue in affected scripts for the semantic patch language. Do you recognise the need for the extension of exclusion specifications here?

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#36 lore raw

Re: [4/5] Coccinelle: put_device: Extend when constraints for twoSmPL ellipses

Quoted 2 lines

I did another experiment at that time and found that this modification will reduce the false positive rate,

Thanks for such feedback.

Will my update suggestion influence the current (or future) software situation?

Quoted 1 line

but it may also reduce the recall rate.

Would you like to explain this information a bit more?

Quoted 2 lines

Could we use it to find out as many bugs as possible in the current kernel and then modify it?

I hope so.

* Will the false positive rate influence change acceptance considerably?

* Would you like to work with source code analysis approaches based on adjusted confidence settings?

Regards,
Markus

#37 lore raw

Re: [4/5] Coccinelle: put_device: Extend when constraints for two SmPL ellipses

In reply to [email protected]
Quoted 1 line

Could we use it to find out as many bugs as possible in the current kernel

How do you think about to work with any more source code analysis approaches?

Quoted 1 line

and then modify it?

I guess that you do not need to wait for a solution so long.

Variables which get reassigned in unwanted ways (before the desired call of a resource release function in the discussed use case) can be found also with the help of the semantic patch language (Coccinelle software).

Regards,
Markus

#38 lore raw

Re: [4/5] Coccinelle: put_device: Extend when constraints for two SmPL ellipses

In reply to Julia Lawall
Quoted 1 line
Quoted 1 line

Can you agree to any information which I presented in the commit message?

Do you find this description inappropriate?

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

You don't need so many type metavariables.

It seems that the Coccinelle software can cope also with my SmPL code addition. You might feel uncomfortable with the suggested changes for a while.

It's ugly. Much more ugly than msg =

The clarification of this change reluctance might become more interesting. I got convinced that there is a need for further software updates.

Quoted 4 lines
Quoted 2 lines

* Can it become required to identify involved source code placeholders by extra metavariables?

I don't understand the question.

Wen Yang was planning a corresponding modification since 2019-02-19.
https://lore.kernel.org/cocci/[email protected]/
https://systeme.lip6.fr/pipermail/cocci/2019-February/005620.html

I got into the development mood to contribute another concrete update suggestion for an open issue in affected scripts for the semantic patch language. Do you recognise the need for the extension of exclusion specifications here?

Quoted 4 lines
Quoted 2 lines

* Would you like to clarify the probability any more how often the shown type casts will be identical?

No idea about this one either.

I am curious if helpful ideas will be added also by other contributors.

Quoted 1 line

Basically, if you have T && T, the two T's have to be the same,

Such an expectation might be logical.

Quoted 1 line

and T is not pure.

This information triggers various communication difficulties.

Quoted 1 line

If you have T on two separate ...s then you are in the && case.

I agree to this view also according the application of two ellipses in the SmPL rule “search”.

Quoted 2 lines

If you have T in two branches of a disjunction or in two whens on the same ... you are in the || case.

It is clear that disjunctions will check code alternatives here. The clarification of consequences around the interpretation of “type purity” might distract from the final solution.

How many (optional) type casts would we like to handle by the discussed source code search approach?

Regards,
Markus

#39 lore raw

PATCH 5/5 Coccinelle: put_device: Merge two SmPL when constraints into one

In reply to Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 13 May 2019 09:55:22 +0200

A single parameter was repeated for a function call in two SmPL when constraints.
Combine the exclusion specifications into a disjunction for the semantic patch language so that this argument is referenced only once there.

---
 scripts/coccinelle/free/put_device.cocci | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
scripts/coccinelle/free/put_device.cocci +1 -2
index 28b0be53fb3f..975cabb97d01 100644
@@ -22,8 +22,7 @@ id = of_find_device_by_node@p1(x)
 if (id == NULL || ...) { ... return ...; }
 ... when != put_device(&id->dev)
     when != id = (T6)(e)
-    when != platform_device_put(id)
-    when != of_dev_put(id)
+    when != \( platform_device_put \| of_dev_put \) (id)
     when != if (id) { ... put_device(&id->dev) ... }
     when != e1 = \( (T) \( id \| (&id->dev) \) \| get_device(&id->dev) \| (T1)platform_get_drvdata(id) \)
 (

--
2.21.0

#40 lore raw

Re: [PATCH 5/5] Coccinelle: put_device: Merge two SmPL when constraints into one

Quoted 9 lines · Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 13 May 2019 09:55:22 +0200

A single parameter was repeated for a function call in two SmPL when constraints.
Combine the exclusion specifications into a disjunction for the semantic patch language so that this argument is referenced only once there.

NACK. This hurts readability and gives no practical benefit.

julia

Quoted 22 lines
---
 scripts/coccinelle/free/put_device.cocci | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
scripts/coccinelle/free/put_device.cocci +1 -3
index 28b0be53fb3f..975cabb97d01 100644
@@ -22,8 +22,7 @@ id = of_find_device_by_node@p1(x)
 if (id == NULL || ...) { ... return ...; }
 ... when != put_device(&id->dev)
     when != id = (T6)(e)
-    when != platform_device_put(id)
-    when != of_dev_put(id)
+    when != \( platform_device_put \| of_dev_put \) (id)
     when != if (id) { ... put_device(&id->dev) ... }
     when != e1 = \( (T) \( id \| (&id->dev) \) \| get_device(&id->dev) \| (T1)platform_get_drvdata(id) \)
 (
--

2.21.0

#41 lore raw

Re: [5/5] Coccinelle: put_device: Merge two SmPL when constraints into one

Quoted 2 lines
Quoted 2 lines

Combine the exclusion specifications into a disjunction for the semantic patch language so that this argument is referenced only once there.

…

Quoted 1 line

NACK. This hurts readability

I suggest to reconsider such readability concerns once more. Can corresponding software limitations be adjusted any further?

Quoted 1 line

and gives no practical benefit.

I guess that you know better which aspects can matter also here for software fine-tuning.

Quoted 8 lines

scripts/coccinelle/free/put_device.cocci id = of_find_device_by_node@p1(x) · line 25

Quoted 8 lines

+++ b/scripts/coccinelle/free/put_device.cocci

scripts/coccinelle/free/put_device.cocci +1 -2
@@ -22,8 +22,7 @@ id = of_find_device_by_node@p1(x)
 if (id == NULL || ...) { ... return ...; }
 ... when != put_device(&id->dev)
     when != id = (T6)(e)
-    when != platform_device_put(id)
-    when != of_dev_put(id)
+    when != \( platform_device_put \| of_dev_put \) (id)

Can the reduction of a bit of duplicate SmPL code result in nicer run time characteristics?

Regards,
Markus