Coccinelle: ptr_err_to_pe: Adjustments for SmPL code
cover Coccinelle: ptr_err_to_pe: Adjustments for SmPL code
From: Markus Elfring <[email protected]>
Date: Tue, 30 Sep 2025 19:19:38 +0200
Refine some implementation details for further development considerations.
Markus Elfring (6):
Omit an URL comment line
Reduce repetition of the key word “virtual”
Restrict the metavariable type “constant” for the usage of string literals Omit a redundant space character
Simplify two SmPL dependency specifications
Distinguish implementation details better for operation mode properties
scripts/coccinelle/misc/ptr_err_to_pe.cocci | 22 ++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-)
Signature · 1 line
2.51.0
PATCH 1/6 Coccinelle: ptr_err_to_pe: Omit an URL comment line
From: Markus Elfring <[email protected]>
Date: Tue, 30 Sep 2025 16:57:47 +0200
The Coccinelle software is documented to some degree by several information sources already. Thus delete the repetition of a known URL in a comment line.
---
See also:
[PATCH net-next 1/2] scripts/coccinelle: Find PTR_ERR() to %pe candidates
https://lore.kernel.org/cocci/[email protected]/
scripts/coccinelle/misc/ptr_err_to_pe.cocci | 1 - 1 file changed, 1 deletion(-)
scripts/coccinelle/misc/ptr_err_to_pe.cocci +0 -1
@@ -8,7 +8,6 @@ /// // Confidence: High // Copyright: (C) 2025 NVIDIA CORPORATION & AFFILIATES. -// URL: https://coccinelle.gitlabpages.inria.fr/website // Options: --no-includes --include-headers virtual context
Signature · 1 line
2.51.0
PATCH 2/6 Coccinelle: ptr_err_to_pe: Reduce repetition of the key word “virtual”
In reply to Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 30 Sep 2025 17:11:48 +0200
This SmPL script is using three input variables. They can be specified in a more succinct way. Thus adjust the corresponding SmPL code layout.
--- scripts/coccinelle/misc/ptr_err_to_pe.cocci | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
scripts/coccinelle/misc/ptr_err_to_pe.cocci +1 -3
@@ -10,9 +10,7 @@ // Copyright: (C) 2025 NVIDIA CORPORATION & AFFILIATES. // Options: --no-includes --include-headers -virtual context -virtual org -virtual report +virtual context, report, org @r@ expression ptr;
Signature · 1 line
2.51.0
PATCH 3/6 Coccinelle: ptr_err_to_pe: Restrict the metavariable type “constant” for the usage of string literals
In reply to Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 30 Sep 2025 17:28:20 +0200
Refine the metavariable type “constant” with “char[]” so that only string literals should be found for the desired source code search.
---
See also:
[PATCH net-next 1/2] scripts/coccinelle: Find PTR_ERR() to %pe candidates
https://lore.kernel.org/cocci/[email protected]/
scripts/coccinelle/misc/ptr_err_to_pe.cocci | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/coccinelle/misc/ptr_err_to_pe.cocci +1 -1
@@ -14,7 +14,7 @@ virtual context, report, org @r@ expression ptr; -constant fmt; +constant char[] fmt; position p; identifier print_func; @@
Signature · 1 line
2.51.0
PATCH 4/6 Coccinelle: ptr_err_to_pe: Omit a redundant space character
In reply to Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 30 Sep 2025 17:33:10 +0200
An extra space character is not required after an SmPL asterisk. Thus omit it.
--- scripts/coccinelle/misc/ptr_err_to_pe.cocci | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/coccinelle/misc/ptr_err_to_pe.cocci +1 -1
@@ -18,7 +18,7 @@ constant char[] fmt; position p; identifier print_func; @@ -* print_func(..., fmt, ..., PTR_ERR@p(ptr), ...) +*print_func(..., fmt, ..., PTR_ERR@p(ptr), ...) @script:python depends on r && report@ p << r.p;
Signature · 1 line
2.51.0
PATCH 5/6 Coccinelle: ptr_err_to_pe: Simplify two SmPL dependency specifications
In reply to Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 30 Sep 2025 17:46:55 +0200
Omit the explicit specification “r &&” from two SmPL rules because the references are sufficient according to data declarations for Python scripts.
---
See also:
[PATCH net-next 1/2] scripts/coccinelle: Find PTR_ERR() to %pe candidates
https://lore.kernel.org/cocci/[email protected]/
scripts/coccinelle/misc/ptr_err_to_pe.cocci | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
scripts/coccinelle/misc/ptr_err_to_pe.cocci +2 -2
@@ -20,12 +20,12 @@ identifier print_func; @@ *print_func(..., fmt, ..., PTR_ERR@p(ptr), ...) -@script:python depends on r && report@ +@script:python depends on report@ p << r.p; @@ coccilib.report.print_report(p[0], "WARNING: Consider using %pe to print PTR_ERR()") -@script:python depends on r && org@ +@script:python depends on org@ p << r.p; @@ coccilib.org.print_todo(p[0], "WARNING: Consider using %pe to print PTR_ERR()")
Signature · 1 line
2.51.0
PATCH 6/6 Coccinelle: ptr_err_to_pe: Distinguish implementation details better for operation mode properties
In reply to Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 30 Sep 2025 18:24:19 +0200
The coccicheck operation modes are connected with data format requirements. Take them better into account in the affected SmPL code.
* The mode “context” works without an extra position variable.
* The other two output modes should not be mixed with data according to “context” information.
---
See also:
[PATCH net-next 1/2] scripts/coccinelle: Find PTR_ERR() to %pe candidates
https://lore.kernel.org/cocci/[email protected]/
scripts/coccinelle/misc/ptr_err_to_pe.cocci | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
scripts/coccinelle/misc/ptr_err_to_pe.cocci +9 -2
@@ -12,13 +12,20 @@ virtual context, report, org -@r@ +@depends on context@ +expression ptr; +constant char[] fmt; +identifier print_func; +@@ +*print_func(..., fmt, ..., PTR_ERR(ptr), ...) + +@r depends on org || report@ expression ptr; constant char[] fmt; position p; identifier print_func; @@ -*print_func(..., fmt, ..., PTR_ERR@p(ptr), ...) + print_func(..., fmt, ..., PTR_ERR@p(ptr), ...) @script:python depends on report@ p << r.p;
Signature · 1 line
2.51.0