| 1 |
// SPDX-License-Identifier: GPL-2.0-only |
| 2 |
/// PTR_ERR should access the value just tested by IS_ERR |
| 3 |
//# There can be false positives in the patch case, where it is the call to |
| 4 |
//# IS_ERR that is wrong. |
| 5 |
/// |
| 6 |
// Confidence: High |
| 7 |
// Copyright: (C) 2012, 2015 Julia Lawall, INRIA. |
| 8 |
// Copyright: (C) 2012, 2015 Gilles Muller, INRIA. |
| 9 |
// URL: https://coccinelle.gitlabpages.inria.fr/website |
| 10 |
// Options: --no-includes --include-headers |
| 11 |
|
| 12 |
virtual patch |
| 13 |
virtual context |
| 14 |
virtual org |
| 15 |
virtual report |
| 16 |
|
| 17 |
@ok1 exists@ |
| 18 |
expression x,e; |
| 19 |
position p; |
| 20 |
@@ |
| 21 |
|
| 22 |
if (IS_ERR(x=e) || ...) { |
| 23 |
<... |
| 24 |
PTR_ERR@p(x) |
| 25 |
...> |
| 26 |
} |
| 27 |
|
| 28 |
@ok2 exists@ |
| 29 |
expression x,e1,e2; |
| 30 |
position p; |
| 31 |
@@ |
| 32 |
|
| 33 |
if (IS_ERR(x) || ...) { |
| 34 |
<... |
| 35 |
( |
| 36 |
PTR_ERR@p(\(e1 ? e2 : x\|e1 ? x : e2\)) |
| 37 |
| |
| 38 |
PTR_ERR@p(x) |
| 39 |
) |
| 40 |
...> |
| 41 |
} |
| 42 |
|
| 43 |
@r1 depends on patch && !context && !org && !report exists@ |
| 44 |
expression x,y; |
| 45 |
position p != {ok1.p,ok2.p}; |
| 46 |
@@ |
| 47 |
|
| 48 |
if (IS_ERR(x) || ...) { |
| 49 |
... when any |
| 50 |
when != IS_ERR(...) |
| 51 |
( |
| 52 |
PTR_ERR(x) |
| 53 |
| |
| 54 |
PTR_ERR@p( |
| 55 |
- y |
| 56 |
+ x |
| 57 |
) |
| 58 |
) |
| 59 |
... when any |
| 60 |
} |
| 61 |
|
| 62 |
// ---------------------------------------------------------------------------- |
| 63 |
|
| 64 |
@r1_context depends on !patch && (context || org || report) exists@ |
| 65 |
position p != {ok1.p,ok2.p}; |
| 66 |
expression x, y; |
| 67 |
position j0, j1; |
| 68 |
@@ |
| 69 |
|
| 70 |
if (IS_ERR@j0(x) || ...) { |
| 71 |
... when any |
| 72 |
when != IS_ERR(...) |
| 73 |
( |
| 74 |
PTR_ERR(x) |
| 75 |
| |
| 76 |
PTR_ERR@j1@p( |
| 77 |
y |
| 78 |
) |
| 79 |
) |
| 80 |
... when any |
| 81 |
} |
| 82 |
|
| 83 |
@r1_disj depends on !patch && (context || org || report) exists@ |
| 84 |
position p != {ok1.p,ok2.p}; |
| 85 |
expression x, y; |
| 86 |
position r1_context.j0, r1_context.j1; |
| 87 |
@@ |
| 88 |
|
| 89 |
* if (IS_ERR@j0(x) || ...) { |
| 90 |
... when any |
| 91 |
when != IS_ERR(...) |
| 92 |
* PTR_ERR@j1@p( |
| 93 |
y |
| 94 |
) |
| 95 |
... when any |
| 96 |
} |
| 97 |
|
| 98 |
// ---------------------------------------------------------------------------- |
| 99 |
|
| 100 |
@script:python r1_org depends on org@ |
| 101 |
j0 << r1_context.j0; |
| 102 |
j1 << r1_context.j1; |
| 103 |
@@ |
| 104 |
|
| 105 |
msg = "inconsistent IS_ERR and PTR_ERR" |
| 106 |
coccilib.org.print_todo(j0[0], msg) |
| 107 |
coccilib.org.print_link(j1[0], "") |
| 108 |
|
| 109 |
// ---------------------------------------------------------------------------- |
| 110 |
|
| 111 |
@script:python r1_report depends on report@ |
| 112 |
j0 << r1_context.j0; |
| 113 |
j1 << r1_context.j1; |
| 114 |
@@ |
| 115 |
|
| 116 |
msg = "inconsistent IS_ERR and PTR_ERR on line %s." % (j1[0].line) |
| 117 |
coccilib.report.print_report(j0[0], msg) |
| 118 |
|