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