Debian Codegraph @

scripts/coccinelle/misc/ptr_err_to_pe.cocci

raw
1 // SPDX-License-Identifier: GPL-2.0-only
2 /// Use %pe format specifier instead of PTR_ERR() for printing error pointers.
3 ///
4 /// For printing error pointers (i.e., a pointer for which IS_ERR() is true)
5 /// %pe will print a symbolic error name (e.g., -EINVAL), opposed to the raw
6 /// errno (e.g., -22) produced by PTR_ERR().
7 /// It also makes the code cleaner by saving a redundant call to PTR_ERR().
8 ///
9 // Confidence: High
10 // Copyright: (C) 2025 NVIDIA CORPORATION & AFFILIATES.
11 // URL: https://coccinelle.gitlabpages.inria.fr/website
12 // Options: --no-includes --include-headers
13
14 virtual context
15 virtual org
16 virtual report
17
18 @r@
19 expression ptr;
20 constant fmt;
21 position p;
22 identifier print_func;
23 @@
24 * print_func(..., fmt, ..., PTR_ERR@p(ptr), ...)
25
26 @script:python depends on r && report@
27 p << r.p;
28 @@
29 coccilib.report.print_report(p[0], "WARNING: Consider using %pe to print PTR_ERR()")
30
31 @script:python depends on r && org@
32 p << r.p;
33 @@
34 coccilib.org.print_todo(p[0], "WARNING: Consider using %pe to print PTR_ERR()")