Skip to contentSkip to conversation

scripts/coccinelle: Symbolic error names script

PATCH Applied Tariq Toukan 7 participants 16 messages Sep 18, 2025 – Sep 28, 2025

Subsystems (7)
lore
Share & tools
lore

Tariq Toukan

author maintainer
#0 lore raw

cover scripts/coccinelle: Symbolic error names script

Hi,

This small series by Gal adds a new coccinelle script that spots potential transitions to symbolic error names in print functions, and then uses it in mlx5 driver.

Regards,
Tariq

Gal Pressman (2):
scripts/coccinelle: Find PTR_ERR() to %pe candidates net/mlx5: Use %pe format specifier for error pointers

 .../mellanox/mlx5/core/diag/reporter_vnic.c   |  4 +-
 .../mellanox/mlx5/core/en/hv_vhca_stats.c     |  4 +-
 .../mellanox/mlx5/core/en/rep/bridge.c        |  7 +--
 .../mellanox/mlx5/core/en/reporter_rx.c       |  4 +-
 .../mellanox/mlx5/core/en/reporter_tx.c       |  4 +-
 .../mellanox/mlx5/core/en/tc/ct_fs_hmfs.c     |  4 +-
 .../mellanox/mlx5/core/en/tc/ct_fs_smfs.c     |  4 +-
 .../mellanox/mlx5/core/en/tc/int_port.c       |  8 ++--
 .../mellanox/mlx5/core/en/tc_tun_encap.c      |  8 ++--
 .../mellanox/mlx5/core/en_accel/fs_tcp.c      |  2 +-
 .../mellanox/mlx5/core/en_accel/ipsec_fs.c    |  4 +-
 .../ethernet/mellanox/mlx5/core/en_common.c   |  4 +-
 .../net/ethernet/mellanox/mlx5/core/en_rep.c  |  4 +-
 .../mellanox/mlx5/core/esw/acl/egress_lgcy.c  |  4 +-
 .../ethernet/mellanox/mlx5/core/esw/bridge.c  | 47 ++++++++++---------
 .../mellanox/mlx5/core/esw/vporttbl.c         |  4 +-
 .../net/ethernet/mellanox/mlx5/core/eswitch.c |  4 +-
 .../mellanox/mlx5/core/eswitch_offloads.c     | 16 ++++---
 .../net/ethernet/mellanox/mlx5/core/health.c  |  8 ++--
 .../mellanox/mlx5/core/irq_affinity.c         |  4 +-
 .../ethernet/mellanox/mlx5/core/lib/clock.c   |  4 +-
 .../net/ethernet/mellanox/mlx5/core/main.c    |  4 +-
 scripts/coccinelle/misc/ptr_err_to_pe.cocci   | 34 ++++++++++++++
 23 files changed, 114 insertions(+), 76 deletions(-)
 create mode 100644 scripts/coccinelle/misc/ptr_err_to_pe.cocci

base-commit: 152ba35c04ade1a164c774d6fccbf8e8cf4652cf

Signature · 1 line
2.31.1
author maintainer
#1 lore raw

PATCH 1/2 scripts/coccinelle: Find PTR_ERR() to %pe candidates

From: Gal Pressman <[email protected]>

Add a new Coccinelle script to identify places where PTR_ERR() is used in print functions and suggest using the %pe format specifier instead.

For printing error pointers (i.e., a pointer for which IS_ERR() is true) %pe will print a symbolic error name (e.g,. -EINVAL), opposed to the raw errno (e.g,. -22) produced by PTR_ERR().
It also makes the code cleaner by saving a redundant call to PTR_ERR().

The script supports context, report, and org modes.

Example transformation:
printk("Error: %ld\n", PTR_ERR(ptr)); // Before
printk("Error: %pe\n", ptr); // After

---
 scripts/coccinelle/misc/ptr_err_to_pe.cocci | 34 +++++++++++++++++++++
 1 file changed, 34 insertions(+)
 create mode 100644 scripts/coccinelle/misc/ptr_err_to_pe.cocci
scripts/coccinelle/misc/ptr_err_to_pe.cocci new file +34 -0
new file mode 100644
index 000000000000..0494c7709245
@@ -0,0 +1,34 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/// Use %pe format specifier instead of PTR_ERR() for printing error pointers.
+///
+/// For printing error pointers (i.e., a pointer for which IS_ERR() is true)
+/// %pe will print a symbolic error name (e.g., -EINVAL), opposed to the raw
+/// errno (e.g., -22) produced by PTR_ERR().
+/// It also makes the code cleaner by saving a redundant call to PTR_ERR().
+///
+// Confidence: High
+// Copyright: (C) 2025 NVIDIA CORPORATION & AFFILIATES.
+// URL: https://coccinelle.gitlabpages.inria.fr/website
+// Options: --no-includes --include-headers
+
+virtual context
+virtual org
+virtual report
+
+@r@
+expression ptr;
+constant fmt;
+position p;
+identifier print_func;
+@@
+* print_func(..., fmt, ..., PTR_ERR@p(ptr), ...)
+
+@script:python depends on r && report@
+p << r.p;
+@@
+coccilib.report.print_report(p[0], "WARNING: Consider using %pe to print PTR_ERR()")
+
+@script:python depends on r && org@
+p << r.p;
+@@
+coccilib.org.print_todo(p[0], "WARNING: Consider using %pe to print PTR_ERR()")
Signature · 1 line
2.31.1
reviewer Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH net-next 1/2] scripts/coccinelle: Find PTR_ERR() to %pe candidates

Quoted 12 lines · Tariq Toukan

From: Gal Pressman <[email protected]>

Add a new Coccinelle script to identify places where PTR_ERR() is used in print functions and suggest using the %pe format specifier instead.

For printing error pointers (i.e., a pointer for which IS_ERR() is true) %pe will print a symbolic error name (e.g,. -EINVAL), opposed to the raw errno (e.g,. -22) produced by PTR_ERR().
It also makes the code cleaner by saving a redundant call to PTR_ERR().

The script supports context, report, and org modes.

Quoted 7 lines

Example transformation:
printk("Error: %ld\n", PTR_ERR(ptr)); // Before
printk("Error: %pe\n", ptr); // After

Thanks, having this check seems very nice to me.

maintainer
#3 lore raw

Re: [PATCH net-next 1/2] scripts/coccinelle: Find PTR_ERR() to %pe candidates

In reply to Tariq Toukan
Quoted 8 lines · On Thu, 18 Sep 2025 13:43:46 +0300 Tariq Toukan wrote:

Add a new Coccinelle script to identify places where PTR_ERR() is used in print functions and suggest using the %pe format specifier instead.

For printing error pointers (i.e., a pointer for which IS_ERR() is true) %pe will print a symbolic error name (e.g,. -EINVAL), opposed to the raw errno (e.g,. -22) produced by PTR_ERR().
It also makes the code cleaner by saving a redundant call to PTR_ERR().

Quoted 5 lines

The script supports context, report, and org modes.

Example transformation:
printk("Error: %ld\n", PTR_ERR(ptr)); // Before
printk("Error: %pe\n", ptr); // After

Hi Julia, Nicolas,

would you be willing to give us a review tag for this script? Would you prefer to take the script via your tree?

https://lore.kernel.org/all/[email protected]/

#4 lore raw

Re: [cocci] [PATCH net-next 1/2] scripts/coccinelle: Find PTR_ERR() to %pe candidates

In reply to Tariq Toukan

…> The script supports context, report, and org modes.

I suggest to omit this sentence from the description.

Will the hint “scripts/” be omitted from the patch prefix?

…> +++ b/scripts/coccinelle/misc/ptr_err_to_pe.cocci …> +// URL: https://coccinelle.gitlabpages.inria.fr/website

I suggest to omit this comment line.

…> +virtual context

scripts/coccinelle/misc/ptr_err_to_pe.cocci line 16

Quoted 2 lines
scripts/coccinelle/misc/ptr_err_to_pe.cocci new file +2 -0
+virtual org
+virtual report

The restriction on the support for three operation modes will need further development considerations.

scripts/coccinelle/misc/ptr_err_to_pe.cocci line 24

Quoted 7 lines

+@r@

scripts/coccinelle/misc/ptr_err_to_pe.cocci new file +6 -0
+expression ptr;
+constant fmt;
+position p;
+identifier print_func;
+@@
+* print_func(..., fmt, ..., PTR_ERR@p(ptr), ...)

How do you think about to use the metavariable type “format list”?

Would it matter to restrict expressions to pointer expressions?

Quoted 1 line

+@script:python depends on r && org@

I guess that such an SmPL dependency specification can be simplified a bit.

scripts/coccinelle/misc/ptr_err_to_pe.cocci line 34

Quoted 3 lines
scripts/coccinelle/misc/ptr_err_to_pe.cocci new file +3 -0
+p << r.p;
+@@
+coccilib.org.print_todo(p[0], "WARNING: Consider using %pe to print PTR_ERR()")

I suggest to reconsider the implementation detail once more
if the SmPL asterisk functionality fits really to the operation modes “org” and “report”.

The operation mode “context” can usually work also without an extra position variable, can't it?

Regards,
Markus

#5 lore raw

Re: [cocci] [PATCH net-next 1/2] scripts/coccinelle: Find PTR_ERR() to %pe candidates

Hi Markus!

Thanks for the review, forgive for being a total noob at coccinelle, hence the many questions.

Quoted 6 lines · Markus Elfring

…> The script supports context, report, and org modes.

I suggest to omit this sentence from the description.

Will the hint “scripts/” be omitted from the patch prefix?

The patch was merged already, so I'm skipping to comments that can be fixed in a followup patch.

Quoted 6 lines

…> +++ b/scripts/coccinelle/misc/ptr_err_to_pe.cocci …> +// URL: https://coccinelle.gitlabpages.inria.fr/website

I suggest to omit this comment line.

Sure.

Quoted 7 lines

…> +virtual context

scripts/coccinelle/misc/ptr_err_to_pe.cocci line 16

Quoted 2 lines
scripts/coccinelle/misc/ptr_err_to_pe.cocci new file +2 -0
+virtual org
+virtual report

The restriction on the support for three operation modes will need further development considerations.

I don't understand what you mean?

Quoted 11 lines

scripts/coccinelle/misc/ptr_err_to_pe.cocci line 24

Quoted 9 lines

+@r@

scripts/coccinelle/misc/ptr_err_to_pe.cocci new file +6 -0
+expression ptr;
+constant fmt;
+position p;
+identifier print_func;
+@@
+* print_func(..., fmt, ..., PTR_ERR@p(ptr), ...)

How do you think about to use the metavariable type “format list”?

I did find "format list" in the documentation, but spatch fails when I try to use it.

Quoted 2 lines

Would it matter to restrict expressions to pointer expressions?

I tried changing 'expression ptr;' -> 'expression *ptr;', but then it didn't find anything. Am I doing it wrong?

Quoted 5 lines
Quoted 3 lines

+@script:python depends on r && org@

I guess that such an SmPL dependency specification can be simplified a bit.

You mean drop the depends on r?

Quoted 11 lines

scripts/coccinelle/misc/ptr_err_to_pe.cocci line 34

Quoted 5 lines
scripts/coccinelle/misc/ptr_err_to_pe.cocci new file +3 -0
+p << r.p;
+@@
+coccilib.org.print_todo(p[0], "WARNING: Consider using %pe to print PTR_ERR()")

I suggest to reconsider the implementation detail once more
if the SmPL asterisk functionality fits really to the operation modes “org” and “report”.

The operation mode “context” can usually work also without an extra position variable, can't it?

Can you please explain?

#6 lore raw

Re: [cocci] [PATCH net-next 1/2] scripts/coccinelle: Find PTR_ERR() to %pe candidates

Quoted 7 lines
Quoted 5 lines

scripts/coccinelle/misc/ptr_err_to_pe.cocci line 16

Quoted 3 lines
scripts/coccinelle/misc/ptr_err_to_pe.cocci new file +3 -0
+virtual context
+virtual org
+virtual report

The restriction on the support for three operation modes will need further development considerations.

I don't understand what you mean?

The development status might be unclear for the handling of a varying number of operation modes by coccicheck rules, isn't it?

Quoted 2 lines

I did find "format list" in the documentation, but spatch fails when I try to use it.

Which SmPL code variations did you try out?

Quoted 4 lines
Quoted 1 line

Would it matter to restrict expressions to pointer expressions?

I tried changing 'expression ptr;' -> 'expression *ptr;', but then it didn't find anything. Am I doing it wrong?

Further software improvements can be reconsidered accordingly.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

+@script:python depends on r && org@

I guess that such an SmPL dependency specification can be simplified a bit.

You mean drop the depends on r?

You may omit “r &&” (because the rule is referenced by an SmPL variable declaration), can't you?

Quoted 11 lines
Quoted 9 lines

scripts/coccinelle/misc/ptr_err_to_pe.cocci line 34

Quoted 3 lines
scripts/coccinelle/misc/ptr_err_to_pe.cocci new file +3 -0
+p << r.p;
+@@
+coccilib.org.print_todo(p[0], "WARNING: Consider using %pe to print PTR_ERR()")

I suggest to reconsider the implementation detail once more
if the SmPL asterisk functionality fits really to the operation modes “org” and “report”.

The operation mode “context” can usually work also without an extra position variable, can't it?

Can you please explain?

Are you aware of data format requirements here?

Regards,
Markus

#7 lore raw

Re: [cocci] [PATCH net-next 1/2] scripts/coccinelle: Find PTR_ERR() to %pe candidates

Quoted 10 lines · Markus Elfring
Quoted 7 lines
Quoted 5 lines

scripts/coccinelle/misc/ptr_err_to_pe.cocci line 16

Quoted 3 lines
scripts/coccinelle/misc/ptr_err_to_pe.cocci new file +3 -0
+virtual context
+virtual org
+virtual report

The restriction on the support for three operation modes will need further development considerations.

I don't understand what you mean?

The development status might be unclear for the handling of a varying number of operation modes by coccicheck rules, isn't it?

I'm sorry, I still don't understand what you mean (the problem is likely on my side).
Do you want me to change anything?

Quoted 6 lines
Quoted 4 lines

I did find "format list" in the documentation, but spatch fails when I try to use it.

Which SmPL code variations did you try out?

Ended up with Julia's suggestion.

Quoted 10 lines
Quoted 6 lines
Quoted 3 lines

Would it matter to restrict expressions to pointer expressions?

I tried changing 'expression ptr;' -> 'expression *ptr;', but then it didn't find anything. Am I doing it wrong?

Further software improvements can be reconsidered accordingly.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

+@script:python depends on r && org@

I guess that such an SmPL dependency specification can be simplified a bit.

You mean drop the depends on r?

You may omit “r &&” (because the rule is referenced by an SmPL variable declaration), can't you?

Yes, thanks.

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

scripts/coccinelle/misc/ptr_err_to_pe.cocci line 34

Quoted 5 lines
scripts/coccinelle/misc/ptr_err_to_pe.cocci new file +3 -0
+p << r.p;
+@@
+coccilib.org.print_todo(p[0], "WARNING: Consider using %pe to print PTR_ERR()")

I suggest to reconsider the implementation detail once more
if the SmPL asterisk functionality fits really to the operation modes “org” and “report”.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

The operation mode “context” can usually work also without an extra position variable, can't it?

Can you please explain?

Are you aware of data format requirements here?

Apparently not, I'll be glad to learn.

#8 lore raw

Re: [cocci] [PATCH net-next 1/2] scripts/coccinelle: Find PTR_ERR() to %pe candidates

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

scripts/coccinelle/misc/ptr_err_to_pe.cocci line 16

Quoted 3 lines
scripts/coccinelle/misc/ptr_err_to_pe.cocci new file +3 -0
+virtual context
+virtual org
+virtual report

The restriction on the support for three operation modes will need further development considerations.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

I don't understand what you mean?

The development status might be unclear for the handling of a varying number of operation modes by coccicheck rules, isn't it?

I'm sorry, I still don't understand what you mean (the problem is likely on my side).

The development status is evolving somehow.

Quoted 1 line

Do you want me to change anything?

You would like to achieve further software refinements. Did you notice remaining open issues from public information sources?

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

scripts/coccinelle/misc/ptr_err_to_pe.cocci line 34

Quoted 3 lines
scripts/coccinelle/misc/ptr_err_to_pe.cocci new file +3 -0
+p << r.p;
+@@
+coccilib.org.print_todo(p[0], "WARNING: Consider using %pe to print PTR_ERR()")

I suggest to reconsider the implementation detail once more
if the SmPL asterisk functionality fits really to the operation modes “org” and “report”.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

The operation mode “context” can usually work also without an extra position variable, can't it?

Can you please explain?

Are you aware of data format requirements here?

Apparently not, I'll be glad to learn.

Each “operation mode” is connected with a known data format.
The corresponding software documentation is probably still improvable. Can you determine data format distinctions from published coccicheck scripts (and related development discussions)?

Regards,
Markus

#9 lore raw

Re: [cocci] [PATCH net-next 1/2] scripts/coccinelle: Find PTR_ERR() to %pe candidates

Quoted 39 lines · Markus Elfring
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

scripts/coccinelle/misc/ptr_err_to_pe.cocci line 16

Quoted 3 lines
scripts/coccinelle/misc/ptr_err_to_pe.cocci new file +3 -0
+virtual context
+virtual org
+virtual report

The restriction on the support for three operation modes will need further development considerations.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

I don't understand what you mean?

The development status might be unclear for the handling of a varying number of operation modes by coccicheck rules, isn't it?

I'm sorry, I still don't understand what you mean (the problem is likely on my side).

The development status is evolving somehow.

Quoted 1 line

Do you want me to change anything?

You would like to achieve further software refinements. Did you notice remaining open issues from public information sources?

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

scripts/coccinelle/misc/ptr_err_to_pe.cocci line 34

Quoted 3 lines
scripts/coccinelle/misc/ptr_err_to_pe.cocci new file +3 -0
+p << r.p;
+@@
+coccilib.org.print_todo(p[0], "WARNING: Consider using %pe to print PTR_ERR()")

I suggest to reconsider the implementation detail once more
if the SmPL asterisk functionality fits really to the operation modes “org” and “report”.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

The operation mode “context” can usually work also without an extra position variable, can't it?

Can you please explain?

Are you aware of data format requirements here?

Apparently not, I'll be glad to learn.

Quoted 7 lines

Each “operation mode” is connected with a known data format.
The corresponding software documentation is probably still improvable. Can you determine data format distinctions from published coccicheck scripts (and related development discussions)?

Regards,
Markus

I'm not really sure if I'm speaking to a real person or some kind of weird AI, so I'm going to respectfully ignore these comments..

#10 lore raw

Re: [cocci] [1/2] scripts/coccinelle: Find PTR_ERR() to %pe candidates

Quoted 2 lines

I'm not really sure if I'm speaking to a real person or some kind of weird AI, so I'm going to respectfully ignore these comments..

Can you get more development ideas from another information source than from hints by known contributors (like me)?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/dev-tools/coccinelle.rst?h=v6.17-rc7#n71

I hope that the clarification can become more constructive again.

Regards,
Markus

maintainer
#11 lore raw

Re: [cocci] [PATCH net-next 1/2] scripts/coccinelle: Find PTR_ERR() to %pe candidates

In reply to Gal Pressman
Quoted 10 lines
Quoted 9 lines

scripts/coccinelle/misc/ptr_err_to_pe.cocci line 24

Quoted 7 lines

+@r@

scripts/coccinelle/misc/ptr_err_to_pe.cocci new file +6 -0
+expression ptr;
+constant fmt;
+position p;
+identifier print_func;
+@@
+* print_func(..., fmt, ..., PTR_ERR@p(ptr), ...)

How do you think about to use the metavariable type “format list”?

Quoted 2 lines

I did find "format list" in the documentation, but spatch fails when I try to use it.

I would suggest constant char[] fmt.

format is for the case where you want to specify something about the %d %s, etc in the string.

Quoted 4 lines
Quoted 1 line

Would it matter to restrict expressions to pointer expressions?

I tried changing 'expression ptr;' -> 'expression *ptr;', but then it didn't find anything. Am I doing it wrong?

expression *ptr should be a valid metavariable declaration. But Coccinelle needs to have enough information to know that something is a pointer. If you have code like a->b and you don't have the definition of the structure type of a, then it won't know the type of a->b. More information about types is available if you use options like --recursive-includes, but then treatment of every C file will entail parsing lots of header files, which could make things very slow. So you have to consider whether the information that the thing is a pointer is really necessary to what you are trying to do.

Quoted 9 lines
Quoted 3 lines
Quoted 1 line

+@script:python depends on r && org@

I guess that such an SmPL dependency specification can be simplified a bit.

You mean drop the depends on r?

Quoted 3 lines
Quoted 3 lines

+p << r.p;

Since you have r.p, the rule will only be applied if r has succeeded and furthermore if p has a value. So depends on r is not necessary.

julia

Quoted 11 lines
Quoted 8 lines
Quoted 2 lines

+@@
+coccilib.org.print_todo(p[0], "WARNING: Consider using %pe to print PTR_ERR()")

I suggest to reconsider the implementation detail once more
if the SmPL asterisk functionality fits really to the operation modes “org” and “report”.

The operation mode “context” can usually work also without an extra position variable, can't it?

Can you please explain?

#12 lore raw

Re: [cocci] [PATCH net-next 1/2] scripts/coccinelle: Find PTR_ERR() to %pe candidates

Thanks for the review Julia!

Quoted 10 lines · Julia Lawall
Quoted 10 lines
Quoted 9 lines

scripts/coccinelle/misc/ptr_err_to_pe.cocci line 24

Quoted 7 lines

+@r@

scripts/coccinelle/misc/ptr_err_to_pe.cocci new file +6 -0
+expression ptr;
+constant fmt;
+position p;
+identifier print_func;
+@@
+* print_func(..., fmt, ..., PTR_ERR@p(ptr), ...)

How do you think about to use the metavariable type “format list”?

Quoted 4 lines
Quoted 2 lines

I did find "format list" in the documentation, but spatch fails when I try to use it.

I would suggest constant char[] fmt.

That works, thanks!

Quoted 9 lines

format is for the case where you want to specify something about the %d %s, etc in the string.

Quoted 4 lines
Quoted 1 line

Would it matter to restrict expressions to pointer expressions?

I tried changing 'expression ptr;' -> 'expression *ptr;', but then it didn't find anything. Am I doing it wrong?

Quoted 9 lines

expression *ptr should be a valid metavariable declaration. But Coccinelle needs to have enough information to know that something is a pointer. If you have code like a->b and you don't have the definition of the structure type of a, then it won't know the type of a->b. More information about types is available if you use options like --recursive-includes, but then treatment of every C file will entail parsing lots of header files, which could make things very slow. So you have to consider whether the information that the thing is a pointer is really necessary to what you are trying to do.

Makes sense, indeed the pointer is embedded in another struct.

I'll keep it as is, if the code calls PTR_ERR() on something that is not a pointer it has bigger problems than using %pe.

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 2 lines

+@script:python depends on r && org@

I guess that such an SmPL dependency specification can be simplified a bit.

Quoted 8 lines
Quoted 5 lines

You mean drop the depends on r?

Quoted 3 lines
Quoted 3 lines

+p << r.p;

Since you have r.p, the rule will only be applied if r has succeeded and furthermore if p has a value. So depends on r is not necessary.

Got it.

author maintainer
#13 lore raw

PATCH 2/2 net/mlx5: Use %pe format specifier for error pointers

In reply to Tariq Toukan

From: Gal Pressman <[email protected]>

Using the coccinelle test introduced in previous commit (scripts/coccinelle/misc/ptr_err_to_pe.cocci), convert error logging throughout the mlx5 driver to use the %pe format specifier instead of PTR_ERR() with integer format specifiers.

---
 .../mellanox/mlx5/core/diag/reporter_vnic.c   |  4 +-
 .../mellanox/mlx5/core/en/hv_vhca_stats.c     |  4 +-
 .../mellanox/mlx5/core/en/rep/bridge.c        |  7 +--
 .../mellanox/mlx5/core/en/reporter_rx.c       |  4 +-
 .../mellanox/mlx5/core/en/reporter_tx.c       |  4 +-
 .../mellanox/mlx5/core/en/tc/ct_fs_hmfs.c     |  4 +-
 .../mellanox/mlx5/core/en/tc/ct_fs_smfs.c     |  4 +-
 .../mellanox/mlx5/core/en/tc/int_port.c       |  8 ++--
 .../mellanox/mlx5/core/en/tc_tun_encap.c      |  8 ++--
 .../mellanox/mlx5/core/en_accel/fs_tcp.c      |  2 +-
 .../mellanox/mlx5/core/en_accel/ipsec_fs.c    |  4 +-
 .../ethernet/mellanox/mlx5/core/en_common.c   |  4 +-
 .../net/ethernet/mellanox/mlx5/core/en_rep.c  |  4 +-
 .../mellanox/mlx5/core/esw/acl/egress_lgcy.c  |  4 +-
 .../ethernet/mellanox/mlx5/core/esw/bridge.c  | 47 ++++++++++---------
 .../mellanox/mlx5/core/esw/vporttbl.c         |  4 +-
 .../net/ethernet/mellanox/mlx5/core/eswitch.c |  4 +-
 .../mellanox/mlx5/core/eswitch_offloads.c     | 16 ++++---
 .../net/ethernet/mellanox/mlx5/core/health.c  |  8 ++--
 .../mellanox/mlx5/core/irq_affinity.c         |  4 +-
 .../ethernet/mellanox/mlx5/core/lib/clock.c   |  4 +-
 .../net/ethernet/mellanox/mlx5/core/main.c    |  4 +-
 22 files changed, 80 insertions(+), 76 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/diag/reporter_vnic.c +2 -2
index 73f5b62b8c7f..a17f82321c25 100644
@@ -138,8 +138,8 @@ void mlx5_reporter_vnic_create(struct mlx5_core_dev *dev)
 					       dev);
 	if (IS_ERR(health->vnic_reporter))
 		mlx5_core_warn(dev,
-			       "Failed to create vnic reporter, err = %ld\n",
-			       PTR_ERR(health->vnic_reporter));
+			       "Failed to create vnic reporter, err = %pe\n",
+			       health->vnic_reporter);
 }
 
 void mlx5_reporter_vnic_destroy(struct mlx5_core_dev *dev)
drivers/net/ethernet/mellanox/mlx5/core/en/hv_vhca_stats.c +2 -2
index b4f3bd7d346e..195863b2c013 100644
@@ -138,8 +138,8 @@ void mlx5e_hv_vhca_stats_create(struct mlx5e_priv *priv)
 	if (IS_ERR_OR_NULL(agent)) {
 		if (IS_ERR(agent))
 			netdev_warn(priv->netdev,
-				    "Failed to create hv vhca stats agent, err = %ld\n",
-				    PTR_ERR(agent));
+				    "Failed to create hv vhca stats agent, err = %pe\n",
+				    agent);
 
 		kvfree(priv->stats_agent.buf);
 		return;
drivers/net/ethernet/mellanox/mlx5/core/en/rep/bridge.c +4 -3
index 0f5d7ea8956f..9d1c677814e0 100644
@@ -488,8 +488,8 @@ static int mlx5_esw_bridge_switchdev_event(struct notifier_block *nb,
 							       fdb_info,
 							       br_offloads);
 		if (IS_ERR(work)) {
-			WARN_ONCE(1, "Failed to init switchdev work, err=%ld",
-				  PTR_ERR(work));
+			WARN_ONCE(1, "Failed to init switchdev work, err=%pe",
+				  work);
 			return notifier_from_errno(PTR_ERR(work));
 		}
 
@@ -527,7 +527,8 @@ void mlx5e_rep_bridge_init(struct mlx5e_priv *priv)
 	br_offloads = mlx5_esw_bridge_init(esw);
 	rtnl_unlock();
 	if (IS_ERR(br_offloads)) {
-		esw_warn(mdev, "Failed to init esw bridge (err=%ld)\n", PTR_ERR(br_offloads));
+		esw_warn(mdev, "Failed to init esw bridge (err=%pe)\n",
+			 br_offloads);
 		return;
 	}
 
drivers/net/ethernet/mellanox/mlx5/core/en/reporter_rx.c +2 -2
index eb1cace5910c..b1415992ffa2 100644
@@ -672,8 +672,8 @@ void mlx5e_reporter_rx_create(struct mlx5e_priv *priv)
 						       &mlx5_rx_reporter_ops,
 						       priv);
 	if (IS_ERR(reporter)) {
-		netdev_warn(priv->netdev, "Failed to create rx reporter, err = %ld\n",
-			    PTR_ERR(reporter));
+		netdev_warn(priv->netdev, "Failed to create rx reporter, err = %pe\n",
+			    reporter);
 		return;
 	}
 	priv->rx_reporter = reporter;
drivers/net/ethernet/mellanox/mlx5/core/en/reporter_tx.c +2 -2
index 5a4fe8403a21..9e2cf191ed30 100644
@@ -561,8 +561,8 @@ void mlx5e_reporter_tx_create(struct mlx5e_priv *priv)
 						       priv);
 	if (IS_ERR(reporter)) {
 		netdev_warn(priv->netdev,
-			    "Failed to create tx reporter, err = %ld\n",
-			    PTR_ERR(reporter));
+			    "Failed to create tx reporter, err = %pe\n",
+			    reporter);
 		return;
 	}
 	priv->tx_reporter = reporter;
drivers/net/ethernet/mellanox/mlx5/core/en/tc/ct_fs_hmfs.c +2 -2
index 01d522b02947..d3db6146fcad 100644
@@ -136,8 +136,8 @@ mlx5_ct_fs_hmfs_matcher_get(struct mlx5_ct_fs *fs, struct mlx5_flow_spec *spec,
 	hws_bwc_matcher = mlx5_ct_fs_hmfs_matcher_create(fs, tbl, spec, ipv4, tcp, gre);
 	if (IS_ERR(hws_bwc_matcher)) {
 		netdev_warn(fs->netdev,
-			    "ct_fs_hmfs: failed to create bwc matcher (nat %d, ipv4 %d, tcp %d, gre %d), err: %ld\n",
-			    nat, ipv4, tcp, gre, PTR_ERR(hws_bwc_matcher));
+			    "ct_fs_hmfs: failed to create bwc matcher (nat %d, ipv4 %d, tcp %d, gre %d), err: %pe\n",
+			    nat, ipv4, tcp, gre, hws_bwc_matcher);
 
 		hmfs_matcher = ERR_CAST(hws_bwc_matcher);
 		goto out_unlock;
drivers/net/ethernet/mellanox/mlx5/core/en/tc/ct_fs_smfs.c +2 -2
index 0c97c5899904..4d6924b644c9 100644
@@ -148,8 +148,8 @@ mlx5_ct_fs_smfs_matcher_get(struct mlx5_ct_fs *fs, bool nat, bool ipv4, bool tcp
 	dr_matcher = mlx5_ct_fs_smfs_matcher_create(fs, tbl, ipv4, tcp, gre, prio);
 	if (IS_ERR(dr_matcher)) {
 		netdev_warn(fs->netdev,
-			    "ct_fs_smfs: failed to create matcher (nat %d, ipv4 %d, tcp %d, gre %d), err: %ld\n",
-			    nat, ipv4, tcp, gre, PTR_ERR(dr_matcher));
+			    "ct_fs_smfs: failed to create matcher (nat %d, ipv4 %d, tcp %d, gre %d), err: %pe\n",
+			    nat, ipv4, tcp, gre, dr_matcher);
 
 		smfs_matcher = ERR_CAST(dr_matcher);
 		goto out_unlock;
drivers/net/ethernet/mellanox/mlx5/core/en/tc/int_port.c +4 -4
index 8afcec0c5d3c..896f718483c3 100644
@@ -93,8 +93,8 @@ mlx5e_int_port_create_rx_rule(struct mlx5_eswitch *esw,
 	flow_rule = mlx5_add_flow_rules(esw->offloads.ft_offloads, spec,
 					&flow_act, dest, 1);
 	if (IS_ERR(flow_rule))
-		mlx5_core_warn(esw->dev, "ft offloads: Failed to add internal vport rx rule err %ld\n",
-			       PTR_ERR(flow_rule));
+		mlx5_core_warn(esw->dev, "ft offloads: Failed to add internal vport rx rule err %pe\n",
+			       flow_rule);
 
 	kvfree(spec);
 
@@ -322,8 +322,8 @@ mlx5e_tc_int_port_init(struct mlx5e_priv *priv)
 								sizeof(u32) * 2,
 								(1 << ESW_VPORT_BITS) - 1, true);
 	if (IS_ERR(int_port_priv->metadata_mapping)) {
-		mlx5_core_warn(priv->mdev, "Can't allocate metadata mapping of int port offload, err=%ld\n",
-			       PTR_ERR(int_port_priv->metadata_mapping));
+		mlx5_core_warn(priv->mdev, "Can't allocate metadata mapping of int port offload, err=%pe\n",
+			       int_port_priv->metadata_mapping);
 		goto err_mapping;
 	}
 
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c +4 -4
index a0fc76a1bc08..0735d10f2bac 100644
@@ -172,8 +172,8 @@ void mlx5e_tc_encap_flows_add(struct mlx5e_priv *priv,
 						     &reformat_params,
 						     MLX5_FLOW_NAMESPACE_FDB);
 	if (IS_ERR(e->pkt_reformat)) {
-		mlx5_core_warn(priv->mdev, "Failed to offload cached encapsulation header, %lu\n",
-			       PTR_ERR(e->pkt_reformat));
+		mlx5_core_warn(priv->mdev, "Failed to offload cached encapsulation header, %pe\n",
+			       e->pkt_reformat);
 		return;
 	}
 	e->flags |= MLX5_ENCAP_ENTRY_VALID;
@@ -1845,8 +1845,8 @@ static int mlx5e_tc_tun_fib_event(struct notifier_block *nb, unsigned long event
 			queue_work(priv->wq, &fib_work->work);
 		} else if (IS_ERR(fib_work)) {
 			NL_SET_ERR_MSG_MOD(info->extack, "Failed to init fib work");
-			mlx5_core_warn(priv->mdev, "Failed to init fib work, %ld\n",
-				       PTR_ERR(fib_work));
+			mlx5_core_warn(priv->mdev, "Failed to init fib work, %pe\n",
+				       fib_work);
 		}
 
 		break;
drivers/net/ethernet/mellanox/mlx5/core/en_accel/fs_tcp.c +1 -1
index 4f83e3172767..1febdc5b81f9 100644
@@ -138,7 +138,7 @@ struct mlx5_flow_handle *mlx5e_accel_fs_add_sk(struct mlx5e_flow_steering *fs,
 	flow = mlx5_add_flow_rules(ft->t, spec, &flow_act, &dest, 1);
 
 	if (IS_ERR(flow))
-		fs_err(fs, "mlx5_add_flow_rules() failed, flow is %ld\n", PTR_ERR(flow));
+		fs_err(fs, "mlx5_add_flow_rules() failed, flow is %pe\n", flow);
 
 out:
 	kvfree(spec);
drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_fs.c +2 -2
index 98b6a3a623f9..cc067a0a3151 100644
@@ -1704,8 +1704,8 @@ static int setup_modify_header(struct mlx5e_ipsec *ipsec, int type, u32 val, u8
 
 	modify_hdr = mlx5_modify_header_alloc(mdev, ns_type, num_of_actions, action);
 	if (IS_ERR(modify_hdr)) {
-		mlx5_core_err(mdev, "Failed to allocate modify_header %ld\n",
-			      PTR_ERR(modify_hdr));
+		mlx5_core_err(mdev, "Failed to allocate modify_header %pe\n",
+			      modify_hdr);
 		return PTR_ERR(modify_hdr);
 	}
 
drivers/net/ethernet/mellanox/mlx5/core/en_common.c +2 -2
index 96b744ceaf13..30424ccad584 100644
@@ -210,8 +210,8 @@ int mlx5e_create_mdev_resources(struct mlx5_core_dev *mdev, bool create_tises)
 
 	mdev->mlx5e_res.dek_priv = mlx5_crypto_dek_init(mdev);
 	if (IS_ERR(mdev->mlx5e_res.dek_priv)) {
-		mlx5_core_err(mdev, "crypto dek init failed, %ld\n",
-			      PTR_ERR(mdev->mlx5e_res.dek_priv));
+		mlx5_core_err(mdev, "crypto dek init failed, %pe\n",
+			      mdev->mlx5e_res.dek_priv);
 		mdev->mlx5e_res.dek_priv = NULL;
 	}
 
drivers/net/ethernet/mellanox/mlx5/core/en_rep.c +2 -2
index b231e7855bca..d91db3c8c1b7 100644
@@ -1450,8 +1450,8 @@ static void mlx5e_rep_vnic_reporter_create(struct mlx5e_priv *priv,
 						    rpriv);
 	if (IS_ERR(reporter)) {
 		mlx5_core_err(priv->mdev,
-			      "Failed to create representor vnic reporter, err = %ld\n",
-			      PTR_ERR(reporter));
+			      "Failed to create representor vnic reporter, err = %pe\n",
+			      reporter);
 		return;
 	}
 
drivers/net/ethernet/mellanox/mlx5/core/esw/acl/egress_lgcy.c +2 -2
index 7dd1dc3f77c7..c9a1654d83a2 100644
@@ -87,8 +87,8 @@ int esw_acl_egress_lgcy_setup(struct mlx5_eswitch *esw,
 		drop_counter = mlx5_fc_create(esw->dev, false);
 		if (IS_ERR(drop_counter)) {
 			esw_warn(esw->dev,
-				 "vport[%d] configure egress drop rule counter err(%ld)\n",
-				 vport->vport, PTR_ERR(drop_counter));
+				 "vport[%d] configure egress drop rule counter err(%pe)\n",
+				 vport->vport, drop_counter);
 			drop_counter = NULL;
 		}
 		vport->egress.legacy.drop_counter = drop_counter;
drivers/net/ethernet/mellanox/mlx5/core/esw/bridge.c +24 -23

119 lines not on this page · raw message

drivers/net/ethernet/mellanox/mlx5/core/esw/vporttbl.c +2 -2
index 749c3957a128..407062096a82 100644
@@ -45,8 +45,8 @@ esw_vport_tbl_create(struct mlx5_eswitch *esw, struct mlx5_flow_namespace *ns,
 	ft_attr.flags = vport_ns->flags;
 	fdb = mlx5_create_auto_grouped_flow_table(ns, &ft_attr);
 	if (IS_ERR(fdb)) {
-		esw_warn(esw->dev, "Failed to create per vport FDB Table err %ld\n",
-			 PTR_ERR(fdb));
+		esw_warn(esw->dev, "Failed to create per vport FDB Table err %pe\n",
+			 fdb);
 	}
 
 	return fdb;
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +2 -2
index 10eca910a2db..e2ffb87b94cb 100644
@@ -257,8 +257,8 @@ __esw_fdb_set_vport_rule(struct mlx5_eswitch *esw, u16 vport, bool rx_rule,
 				    &flow_act, &dest, 1);
 	if (IS_ERR(flow_rule)) {
 		esw_warn(esw->dev,
-			 "FDB: Failed to add flow rule: dmac_v(%pM) dmac_c(%pM) -> vport(%d), err(%ld)\n",
-			 dmac_v, dmac_c, vport, PTR_ERR(flow_rule));
+			 "FDB: Failed to add flow rule: dmac_v(%pM) dmac_c(%pM) -> vport(%d), err(%pe)\n",
+			 dmac_v, dmac_c, vport, flow_rule);
 		flow_rule = NULL;
 	}
 
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +9 -7
index bc9838dc5bf8..b8ec55929ab1 100644
@@ -1016,8 +1016,8 @@ mlx5_eswitch_add_send_to_vport_rule(struct mlx5_eswitch *on_esw,
 	flow_rule = mlx5_add_flow_rules(mlx5_eswitch_get_slow_fdb(on_esw),
 					spec, &flow_act, &dest, 1);
 	if (IS_ERR(flow_rule))
-		esw_warn(on_esw->dev, "FDB: Failed to add send to vport rule err %ld\n",
-			 PTR_ERR(flow_rule));
+		esw_warn(on_esw->dev, "FDB: Failed to add send to vport rule err %pe\n",
+			 flow_rule);
 out:
 	kvfree(spec);
 	return flow_rule;
@@ -1065,8 +1065,8 @@ mlx5_eswitch_add_send_to_vport_meta_rule(struct mlx5_eswitch *esw, u16 vport_num
 	flow_rule = mlx5_add_flow_rules(mlx5_eswitch_get_slow_fdb(esw),
 					spec, &flow_act, &dest, 1);
 	if (IS_ERR(flow_rule))
-		esw_warn(esw->dev, "FDB: Failed to add send to vport meta rule vport %d, err %ld\n",
-			 vport_num, PTR_ERR(flow_rule));
+		esw_warn(esw->dev, "FDB: Failed to add send to vport meta rule vport %d, err %pe\n",
+			 vport_num, flow_rule);
 
 	kvfree(spec);
 	return flow_rule;
@@ -2159,7 +2159,9 @@ mlx5_eswitch_create_vport_rx_rule(struct mlx5_eswitch *esw, u16 vport,
 	flow_rule = mlx5_add_flow_rules(esw->offloads.ft_offloads, spec,
 					&flow_act, dest, 1);
 	if (IS_ERR(flow_rule)) {
-		esw_warn(esw->dev, "fs offloads: Failed to add vport rx rule err %ld\n", PTR_ERR(flow_rule));
+		esw_warn(esw->dev,
+			 "fs offloads: Failed to add vport rx rule err %pe\n",
+			 flow_rule);
 		goto out;
 	}
 
@@ -2178,8 +2180,8 @@ static int esw_create_vport_rx_drop_rule(struct mlx5_eswitch *esw)
 					&flow_act, NULL, 0);
 	if (IS_ERR(flow_rule)) {
 		esw_warn(esw->dev,
-			 "fs offloads: Failed to add vport rx drop rule err %ld\n",
-			 PTR_ERR(flow_rule));
+			 "fs offloads: Failed to add vport rx drop rule err %pe\n",
+			 flow_rule);
 		return PTR_ERR(flow_rule);
 	}
 
drivers/net/ethernet/mellanox/mlx5/core/health.c +4 -4
index b63c5a221eb9..aeeb136f5ebc 100644
@@ -718,15 +718,15 @@ void mlx5_fw_reporters_create(struct mlx5_core_dev *dev)
 
 	health->fw_reporter = devl_health_reporter_create(devlink, fw_ops, dev);
 	if (IS_ERR(health->fw_reporter))
-		mlx5_core_warn(dev, "Failed to create fw reporter, err = %ld\n",
-			       PTR_ERR(health->fw_reporter));
+		mlx5_core_warn(dev, "Failed to create fw reporter, err = %pe\n",
+			       health->fw_reporter);
 
 	health->fw_fatal_reporter = devl_health_reporter_create(devlink,
 								fw_fatal_ops,
 								dev);
 	if (IS_ERR(health->fw_fatal_reporter))
-		mlx5_core_warn(dev, "Failed to create fw fatal reporter, err = %ld\n",
-			       PTR_ERR(health->fw_fatal_reporter));
+		mlx5_core_warn(dev, "Failed to create fw fatal reporter, err = %pe\n",
+			       health->fw_fatal_reporter);
 }
 
 static void mlx5_fw_reporters_destroy(struct mlx5_core_dev *dev)
drivers/net/ethernet/mellanox/mlx5/core/irq_affinity.c +2 -2
index 82d3c2568244..14d339eceb92 100644
@@ -150,8 +150,8 @@ mlx5_irq_affinity_request(struct mlx5_core_dev *dev, struct mlx5_irq_pool *pool,
 	if (IS_ERR(new_irq)) {
 		if (!least_loaded_irq) {
 			/* We failed to create an IRQ and we didn't find an IRQ */
-			mlx5_core_err(pool->dev, "Didn't find a matching IRQ. err = %ld\n",
-				      PTR_ERR(new_irq));
+			mlx5_core_err(pool->dev, "Didn't find a matching IRQ. err = %pe\n",
+				      new_irq);
 			mutex_unlock(&pool->lock);
 			return new_irq;
 		}
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +2 -2
index 8f2ad45bec9f..d0ba83d77cd1 100644
@@ -1365,9 +1365,9 @@ static void mlx5_init_clock_dev(struct mlx5_core_dev *mdev)
 	clock->ptp = ptp_clock_register(&clock->ptp_info,
 					clock->shared ? NULL : &mdev->pdev->dev);
 	if (IS_ERR(clock->ptp)) {
-		mlx5_core_warn(mdev, "%sptp_clock_register failed %ld\n",
+		mlx5_core_warn(mdev, "%sptp_clock_register failed %pe\n",
 			       clock->shared ? "shared clock " : "",
-			       PTR_ERR(clock->ptp));
+			       clock->ptp);
 		clock->ptp = NULL;
 	}
 
drivers/net/ethernet/mellanox/mlx5/core/main.c +2 -2
index 6b6d6b05b893..df93625c9dfa 100644
@@ -979,8 +979,8 @@ static int mlx5_init_once(struct mlx5_core_dev *dev)
 
 	dev->priv.devc = mlx5_devcom_register_device(dev);
 	if (IS_ERR(dev->priv.devc))
-		mlx5_core_warn(dev, "failed to register devcom device %ld\n",
-			       PTR_ERR(dev->priv.devc));
+		mlx5_core_warn(dev, "failed to register devcom device %pe\n",
+			       dev->priv.devc);
 
 	err = mlx5_query_board_id(dev);
 	if (err) {
Signature · 1 line
2.31.1
reviewer Reviewed-by on v1 2/2
#14 lore raw

Re: [PATCH net-next 2/2] net/mlx5: Use %pe format specifier for error pointers

Quoted 10 lines · Tariq Toukan

From: Gal Pressman <[email protected]>

Using the coccinelle test introduced in previous commit (scripts/coccinelle/misc/ptr_err_to_pe.cocci), convert error logging throughout the mlx5 driver to use the %pe format specifier instead of PTR_ERR() with integer format specifiers.

Simple, mechanical change that improves readability. Looks good to me.

#15 lore raw
In reply to Tariq Toukan
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 10 lines · On Thu, 18 Sep 2025 13:43:45 +0300 you wrote:

Hi,

This small series by Gal adds a new coccinelle script that spots potential transitions to symbolic error names in print functions, and then uses it in mlx5 driver.

Regards,
Tariq

[...]

Here is the summary with links:
- [net-next,1/2] scripts/coccinelle: Find PTR_ERR() to %pe candidates

    https://git.kernel.org/netdev/net-next/c/57c49d235572
  - [net-next,2/2] net/mlx5: Use %pe format specifier for error pointers
    https://git.kernel.org/netdev/net-next/c/b89cd87b77d4

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html