Skip to contentSkip to conversation

Coccinelle: Add a SmPL script for the reconsideration of redundant dev_err() calls

PATCH Superseded Markus Elfring 3 participants 15 messages Jun 20, 2019 – Jul 1, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Coccinelle: Add a SmPL script for the reconsideration of redundant dev_err() calls

From: Markus Elfring <[email protected]>
Date: Thu, 20 Jun 2019 19:12:53 +0200

The function “devm_ioremap_resource” contains appropriate error reporting. Thus it can be questionable to present another error message at other places.

Provide design options for the adjustment of affected source code by the means of the semantic patch language (Coccinelle software).

---
 .../coccinelle/misc/redundant_dev_err.cocci   | 53 +++++++++++++++++++
 1 file changed, 53 insertions(+)
 create mode 100644 scripts/coccinelle/misc/redundant_dev_err.cocci
scripts/coccinelle/misc/redundant_dev_err.cocci new file +53 -0
new file mode 100644
index 000000000000..aeb228280276
@@ -0,0 +1,53 @@
+// SPDX-License-Identifier: GPL-2.0
+/// Reconsider a function call for redundant error reporting.
+//
+// Keywords: dev_err redundant device error messages
+// Confidence: Medium
+
+virtual patch
+virtual context
+virtual org
+virtual report
+
+@display depends on context@
+expression e;
+@@
+ e = devm_ioremap_resource(...);
+ if (IS_ERR(e))
+ {
+*   dev_err(...);
+    return (...);
+ }
+
+@deletion depends on patch@
+expression e;
+@@
+ e = devm_ioremap_resource(...);
+ if (IS_ERR(e))
+-{
+-   dev_err(...);
+    return (...);
+-}
+
+@or depends on org || report@
+expression e;
+position p;
+@@
+ e = devm_ioremap_resource(...);
+ if (IS_ERR(e))
+ {
+    dev_err@p(...);
+    return (...);
+ }
+
+@script:python to_do depends on org@
+p << or.p;
+@@
+coccilib.org.print_todo(p[0],
+                        "WARNING: An error message is probably not needed here because the previously called function contains appropriate error reporting.")
+
+@script:python reporting depends on report@
+p << or.p;
+@@
+coccilib.report.print_report(p[0],
+                             "WARNING: An error message is probably not needed here because the previously called function contains appropriate error reporting.")

--
2.22.0

#1 lore raw
Quoted 32 lines · Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 20 Jun 2019 19:12:53 +0200

The function “devm_ioremap_resource” contains appropriate error reporting. Thus it can be questionable to present another error message at other places.

Provide design options for the adjustment of affected source code by the means of the semantic patch language (Coccinelle software).

---
 .../coccinelle/misc/redundant_dev_err.cocci   | 53 +++++++++++++++++++
 1 file changed, 53 insertions(+)
 create mode 100644 scripts/coccinelle/misc/redundant_dev_err.cocci
scripts/coccinelle/misc/redundant_dev_err.cocci new file +10 -0
new file mode 100644
index 000000000000..aeb228280276
@@ -0,0 +1,53 @@
+// SPDX-License-Identifier: GPL-2.0
+/// Reconsider a function call for redundant error reporting.
+//
+// Keywords: dev_err redundant device error messages
+// Confidence: Medium
+
+virtual patch
+virtual context
+virtual org
+virtual report

scripts/coccinelle/misc/redundant_dev_err.cocci line 20

Quoted 10 lines
scripts/coccinelle/misc/redundant_dev_err.cocci new file +10 -0
+
+@display depends on context@
+expression e;
+@@
+ e = devm_ioremap_resource(...);
+ if (IS_ERR(e))
+ {
+*   dev_err(...);
+    return (...);
+ }

Why do you assume that there is exactly one dev_err and one return after the test?

Quoted 17 lines
scripts/coccinelle/misc/redundant_dev_err.cocci new file +17 -0
+
+@deletion depends on patch@
+expression e;
+@@
+ e = devm_ioremap_resource(...);
+ if (IS_ERR(e))
+-{
+-   dev_err(...);
+    return (...);
+-}
+
+@or depends on org || report@
+expression e;
+position p;
+@@
+ e = devm_ioremap_resource(...);
+ if (IS_ERR(e))

scripts/coccinelle/misc/redundant_dev_err.cocci line 47

Quoted 10 lines
scripts/coccinelle/misc/redundant_dev_err.cocci new file +10 -0
+ {
+    dev_err@p(...);
+    return (...);
+ }
+
+@script:python to_do depends on org@
+p << or.p;
+@@
+coccilib.org.print_todo(p[0],
+                        "WARNING: An error message is probably not needed here because the previously called function contains appropriate error reporting.")

"the previously called function" would be better as "devm_ioremap_resource".

julia

Quoted 10 lines
scripts/coccinelle/misc/redundant_dev_err.cocci new file +6 -1
+
+@script:python reporting depends on report@
+p << or.p;
+@@
+coccilib.report.print_report(p[0],
+                             "WARNING: An error message is probably not needed here because the previously called function contains appropriate error reporting.")
--

2.22.0

#2 lore raw
Quoted 4 lines
Quoted 4 lines

+@display depends on context@
+expression e;
+@@
+ e = devm_ioremap_resource(...);

Quoted 8 lines

scripts/coccinelle/misc/redundant_dev_err.cocci line 20

Quoted 5 lines

+ if (IS_ERR(e))
+ {

scripts/coccinelle/misc/redundant_dev_err.cocci new file +3 -0
+*   dev_err(...);
+    return (...);
+ }

Why do you assume that there is exactly one dev_err and one return after the test?

I propose to start with the addition of a simple source code search pattern. Would you prefer to clarify a more advanced approach?

Quoted 7 lines

scripts/coccinelle/misc/redundant_dev_err.cocci line 47

Quoted 5 lines

+@script:python to_do depends on org@

scripts/coccinelle/misc/redundant_dev_err.cocci new file +4 -0
+p << or.p;
+@@
+coccilib.org.print_todo(p[0],
+                        "WARNING: An error message is probably not needed here because the previously called function contains appropriate error reporting.")

"the previously called function" would be better as "devm_ioremap_resource".

Would you like to get the relevant function name dynamically determined?

Regards,
Markus

#3 lore raw
Quoted 13 lines · Markus Elfring
Quoted 4 lines
Quoted 4 lines

+@display depends on context@
+expression e;
+@@
+ e = devm_ioremap_resource(...);

Quoted 8 lines

scripts/coccinelle/misc/redundant_dev_err.cocci line 20

Quoted 5 lines

+ if (IS_ERR(e))
+ {

scripts/coccinelle/misc/redundant_dev_err.cocci new file +3 -0
+*   dev_err(...);
+    return (...);
+ }

Why do you assume that there is exactly one dev_err and one return after the test?

Quoted 2 lines

I propose to start with the addition of a simple source code search pattern. Would you prefer to clarify a more advanced approach?

I think that something like

if (IS_ERR(e))
{
<+...
*dev_err(...)
...+>
}

would be more appropriate. Whether there is a return or not doesn't really matter.

Quoted 11 lines
Quoted 9 lines

scripts/coccinelle/misc/redundant_dev_err.cocci line 47

Quoted 7 lines

+@script:python to_do depends on org@

scripts/coccinelle/misc/redundant_dev_err.cocci new file +4 -0
+p << or.p;
+@@
+coccilib.org.print_todo(p[0],
+                        "WARNING: An error message is probably not needed here because the previously called function contains appropriate error reporting.")

"the previously called function" would be better as "devm_ioremap_resource".

Would you like to get the relevant function name dynamically determined?

I have no idea what you consider "the relevant function name" to be. If it is always devm_ioremap_resource then it would seem that it does not need to be dynamically determined.

julia

#4 lore raw
Quoted 4 lines
Quoted 1 line

Would you prefer to clarify a more advanced approach?

I think that something like

Quoted 8 lines

if (IS_ERR(e))
{
<+...
*dev_err(...)
...+>
}

would be more appropriate.

This SmPL construct can be more powerful.

Quoted 1 line

Whether there is a return or not doesn't really matter.

Such an adjustment can be helpful for a few operation modes.

But the number of statements in the if branch will influence the possibility for the deletion of curly braces together with redundant dev_err() calls by the SmPL patch mode.

Quoted 5 lines
Quoted 1 line

Would you like to get the relevant function name dynamically determined?

I have no idea what you consider "the relevant function name" to be. If it is always devm_ioremap_resource then it would seem that it does not need to be dynamically determined.

Do other functions share the same error reporting strategy so that any more collateral software evolution can happen?

Regards,
Markus

#5 lore raw
In reply to Julia Lawall
Quoted 11 lines

I think that something like

if (IS_ERR(e))
{
<+...
*dev_err(...)
...+>
}

would be more appropriate. Whether there is a return or not doesn't really matter.

Do you find the following SmPL change specification useful and acceptable?

@deletion depends on patch@
expression e;
@@
e = devm_ioremap_resource(...);
if (IS_ERR(e))
(
-{

-   dev_err(...);
    return (...);

-}
|{
<+...
- dev_err(...);
...+>
}
)

Would this approach need a version check for the Coccinelle software?

Regards,
Markus

#6 lore raw
Quoted 21 lines · Markus Elfring
Quoted 11 lines

I think that something like

if (IS_ERR(e))
{
<+...
*dev_err(...)
...+>
}

would be more appropriate. Whether there is a return or not doesn't really matter.

Do you find the following SmPL change specification useful and acceptable?

@deletion depends on patch@
expression e;
@@
e = devm_ioremap_resource(...);
if (IS_ERR(e))
(

Review

Quoted 3 lines
(quoted diff) +0 -2
-{
-   dev_err(...);
    return (...);

I still don't see the point of specifying return. Why not just S, where S is a statement metavariable?

julia

Quoted 2 lines

-}
|{

I realize that you confuse conciseness with readability, but it would really look better to have the | on a line by itself.

julia

Quoted 8 lines

<+...
- dev_err(...);
...+>
}
)

Would this approach need a version check for the Coccinelle software?

Why would that be necessary?

#7 lore raw
Quoted 2 lines

I still don't see the point of specifying return. Why not just S, where S is a statement metavariable?

Do you find the following SmPL change specification more appropriate?

@deletion depends on patch@
expression e;
statement s;
@@
e = devm_ioremap_resource(...);
if (IS_ERR(e))
(
-{
- dev_err(...);
s
-}
|
{
<+...
- dev_err(...);
...+>
}
)

Will any additional constraints become relevant?

Quoted 3 lines
Quoted 1 line

Would this approach need a version check for the Coccinelle software?

Why would that be necessary?

I guess that the application of SmPL disjunctions for if statements can trigger development concerns.

Regards,
Markus

#8 lore raw
In reply to Julia Lawall
Quoted 2 lines

I still don't see the point of specifying return. Why not just S, where S is a statement metavariable?

Do you find the following SmPL change specification more appropriate?

@deletion depends on patch@
expression e;
statement s;
@@
e = devm_ioremap_resource(...);
if (IS_ERR(e))
(
-{
- dev_err(...);
s
-}
|
{
<+...
- dev_err(...);
...+>
}
)

Will any additional constraints become relevant?

Quoted 3 lines
Quoted 1 line

Would this approach need a version check for the Coccinelle software?

Why would that be necessary?

I guess that the application of SmPL disjunctions for if statements can trigger development concerns.

Regards,
Markus

#9 lore raw
Quoted 4 lines · Markus Elfring
Quoted 2 lines

I still don't see the point of specifying return. Why not just S, where S is a statement metavariable?

Do you find the following SmPL change specification more appropriate?

It looks better.

Quoted 19 lines

@deletion depends on patch@
expression e;
statement s;
@@
e = devm_ioremap_resource(...);
if (IS_ERR(e))
(

(quoted diff) +0 -3
-{
-   dev_err(...);
    s
-}

|
{
<+...
- dev_err(...);
...+>
}
)

#10 lore raw
In reply to Julia Lawall
Quoted 4 lines
Quoted 4 lines

+@display depends on context@
+expression e;
+@@
+ e = devm_ioremap_resource(...);

Quoted 8 lines

scripts/coccinelle/misc/redundant_dev_err.cocci line 20

Quoted 5 lines

+ if (IS_ERR(e))
+ {

scripts/coccinelle/misc/redundant_dev_err.cocci new file +3 -0
+*   dev_err(...);
+    return (...);
+ }

Why do you assume that there is exactly one dev_err and one return after the test?

I propose to start with the addition of a simple source code search pattern. Would you prefer to clarify a more advanced approach?

Quoted 7 lines

scripts/coccinelle/misc/redundant_dev_err.cocci line 47

Quoted 5 lines

+@script:python to_do depends on org@

scripts/coccinelle/misc/redundant_dev_err.cocci new file +4 -0
+p << or.p;
+@@
+coccilib.org.print_todo(p[0],
+                        "WARNING: An error message is probably not needed here because the previously called function contains appropriate error reporting.")

"the previously called function" would be better as "devm_ioremap_resource".

Would you like to get the relevant function name dynamically determined?

Regards,
Markus

#11 lore raw

PATCH v2 1/1 Coccinelle: Add a SmPL script for the reconsideration of redundant dev_err() calls

In reply to Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 1 Jul 2019 10:00:39 +0200

The function “devm_ioremap_resource” contains appropriate error reporting. Thus it can be questionable to present another error message at other places.

Provide design options for the adjustment of affected source code by the means of the semantic patch language (Coccinelle software).

---

v2:
Suggestions from Julia Lawall were integrated.

* Application of the SmPL construct “<+... … ...+>”
* Replacement of a return specification by a statement metavariable.
* Different coding style for a branch of a SmPL disjunction.
* Usage of a specific function name in two messages.

 .../coccinelle/misc/redundant_dev_err.cocci   | 62 +++++++++++++++++++
 1 file changed, 62 insertions(+)
 create mode 100644 scripts/coccinelle/misc/redundant_dev_err.cocci
scripts/coccinelle/misc/redundant_dev_err.cocci new file +62 -0
new file mode 100644
index 000000000000..7998defb04f3
@@ -0,0 +1,62 @@
+// SPDX-License-Identifier: GPL-2.0
+/// Reconsider a function call for redundant error reporting.
+//
+// Keywords: dev_err redundant device error messages
+// Confidence: Medium
+
+virtual patch
+virtual context
+virtual org
+virtual report
+
+@display depends on context@
+expression e;
+@@
+ e = devm_ioremap_resource(...);
+ if (IS_ERR(e))
+ {
+ <+...
+*   dev_err(...);
+ ...+>
+ }
+
+@deletion depends on patch@
+expression e;
+statement s;
+@@
+ e = devm_ioremap_resource(...);
+ if (IS_ERR(e))
+(
+-{
+-   dev_err(...);
+    s
+-}
+|
+ {
+ <+...
+-   dev_err(...);
+ ...+>
+ }
+)
+
+@or depends on org || report@
+expression e;
+position p;
+@@
+ e = devm_ioremap_resource(...);
+ if (IS_ERR(e))
+ {
+ <+... dev_err@p(...); ...+>
+ }
+
+@script:python to_do depends on org@
+p << or.p;
+@@
+coccilib.org.print_todo(p[0],
+                        "WARNING: An error message is probably not needed here because the devm_ioremap_resource() function contains appropriate error reporting.")
+
+@script:python reporting depends on report@
+p << or.p;
+@@
+coccilib.report.print_report(p[0],
+                             "WARNING: An error message is probably not needed here because the devm_ioremap_resource() function contains appropriate error reporting.")

--
2.22.0

#12 lore raw

On 01.07.19 10:10, Markus Elfring wrote:

Hi folks,

scripts/coccinelle/misc/redundant_dev_err.cocci

Quoted 12 lines

+@script:python to_do depends on org@

scripts/coccinelle/misc/redundant_dev_err.cocci new file +10 -1
+p << or.p;
+@@
+coccilib.org.print_todo(p[0],
+                        "WARNING: An error message is probably not needed here because the devm_ioremap_resource() function contains appropriate error reporting.")
+
+@script:python reporting depends on report@
+p << or.p;
+@@
+coccilib.report.print_report(p[0],
+                             "WARNING: An error message is probably not needed here because the devm_ioremap_resource() function contains appropriate error reporting.")
--

By the way: do we have any mechanism for explicitly suppressing individual warnings (some kind of annotation), when the maintainer is sure that some particular case is a false-positive ?
(I'm thinking of something similar to certain #praga directives for explicitly ignoring invididual warnings in specific lines of code)

I believe such a feature, so we don't get spammed with the same false positives again and again.

--mtx

Signature · 3 lines
Enrico Weigelt, metux IT consult
Free software and Linux embedded engineering
[email protected] -- +49-151-27565287
#13 lore raw

Re: [v2] Coccinelle: Suppression of warnings?

Quoted 2 lines

By the way: do we have any mechanism for explicitly suppressing individual warnings (some kind of annotation),

I do not know such an accepted specification interface (for the handling together with SmPL scripts) so far. How would you identify possibly unwanted messages in a safe way?

Quoted 1 line

when the maintainer is sure that some particular case is a false-positive ?

Do you know any specific source code places already where you would get concerned about the confidence and relevance of the provided information?

Regards,
Markus

#14 lore raw
In reply to Enrico Weigelt, metux IT consult
Quoted 23 lines · metux IT consult

On 01.07.19 10:10, Markus Elfring wrote:

Hi folks,

scripts/coccinelle/misc/redundant_dev_err.cocci

Quoted 12 lines

+@script:python to_do depends on org@

scripts/coccinelle/misc/redundant_dev_err.cocci new file +10 -1
+p << or.p;
+@@
+coccilib.org.print_todo(p[0],
+                        "WARNING: An error message is probably not needed here because the devm_ioremap_resource() function contains appropriate error reporting.")
+
+@script:python reporting depends on report@
+p << or.p;
+@@
+coccilib.report.print_report(p[0],
+                             "WARNING: An error message is probably not needed here because the devm_ioremap_resource() function contains appropriate error reporting.")
--

By the way: do we have any mechanism for explicitly suppressing individual warnings (some kind of annotation), when the maintainer is sure that some particular case is a false-positive ?
(I'm thinking of something similar to certain #praga directives for explicitly ignoring invididual warnings in specific lines of code)

Quoted 2 lines

I believe such a feature, so we don't get spammed with the same false positives again and again.

0-day takes care of it on its own. Probably other such bots do the same. I'm not sure that it is a good idea to clutter the kernel code with such annotations, especially since the whole point of Ccocinelle is that the rules are easy to change. We also made a tool named Herodotos for collecting identical reports over time, but it seems to be not so easy to use.

julia