Skip to contentSkip to conversation

Coccinelle: ptr_err_to_pe: Adjustments for SmPL code

PATCH New Markus Elfring 1 participant 7 messages Sep 30, 2025

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

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
#1 lore raw

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
index 0494c7709245..1a373c0a8180 100644
@@ -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
#2 lore raw

PATCH 2/6 Coccinelle: ptr_err_to_pe: Reduce repetition of the key word “virtual”

In reply to Markus Elfring

From: 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
index 1a373c0a8180..26888d2c9c83 100644
@@ -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
#3 lore raw

PATCH 3/6 Coccinelle: ptr_err_to_pe: Restrict the metavariable type “constant” for the usage of string literals

In reply to Markus Elfring

From: 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
index 26888d2c9c83..fb4b5bf91081 100644
@@ -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
#4 lore raw

PATCH 4/6 Coccinelle: ptr_err_to_pe: Omit a redundant space character

In reply to Markus Elfring

From: 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
index fb4b5bf91081..b2db0dc3395e 100644
@@ -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
#5 lore raw

PATCH 5/6 Coccinelle: ptr_err_to_pe: Simplify two SmPL dependency specifications

In reply to Markus Elfring

From: 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
index b2db0dc3395e..f0bd658c7edb 100644
@@ -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
#6 lore raw

PATCH 6/6 Coccinelle: ptr_err_to_pe: Distinguish implementation details better for operation mode properties

In reply to Markus Elfring

From: 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
index f0bd658c7edb..fa93a6f2e3d2 100644
@@ -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