David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2 | /// |
| 3 | /// Use PTR_ERR_OR_ZERO rather than if(IS_ERR(...)) + PTR_ERR |
| 4 | /// |
| 5 | // Confidence: High |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 6 | // Copyright: (C) 2012 Julia Lawall, INRIA/LIP6. |
| 7 | // Copyright: (C) 2012 Gilles Muller, INRIA/LiP6. |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 8 | // URL: http://coccinelle.lip6.fr/ |
| 9 | // Options: --no-includes --include-headers |
| 10 | // |
| 11 | // Keywords: ERR_PTR, PTR_ERR, PTR_ERR_OR_ZERO |
| 12 | // Version min: 2.6.39 |
| 13 | // |
| 14 | |
| 15 | virtual context |
| 16 | virtual patch |
| 17 | virtual org |
| 18 | virtual report |
| 19 | |
| 20 | @depends on patch@ |
| 21 | expression ptr; |
| 22 | @@ |
| 23 | |
| 24 | - if (IS_ERR(ptr)) return PTR_ERR(ptr); else return 0; |
| 25 | + return PTR_ERR_OR_ZERO(ptr); |
| 26 | |
| 27 | @depends on patch@ |
| 28 | expression ptr; |
| 29 | @@ |
| 30 | |
| 31 | - if (IS_ERR(ptr)) return PTR_ERR(ptr); return 0; |
| 32 | + return PTR_ERR_OR_ZERO(ptr); |
| 33 | |
| 34 | @depends on patch@ |
| 35 | expression ptr; |
| 36 | @@ |
| 37 | |
| 38 | - (IS_ERR(ptr) ? PTR_ERR(ptr) : 0) |
| 39 | + PTR_ERR_OR_ZERO(ptr) |
| 40 | |
| 41 | @r1 depends on !patch@ |
| 42 | expression ptr; |
| 43 | position p1; |
| 44 | @@ |
| 45 | |
| 46 | * if@p1 (IS_ERR(ptr)) return PTR_ERR(ptr); else return 0; |
| 47 | |
| 48 | @r2 depends on !patch@ |
| 49 | expression ptr; |
| 50 | position p2; |
| 51 | @@ |
| 52 | |
| 53 | * if@p2 (IS_ERR(ptr)) return PTR_ERR(ptr); return 0; |
| 54 | |
| 55 | @r3 depends on !patch@ |
| 56 | expression ptr; |
| 57 | position p3; |
| 58 | @@ |
| 59 | |
| 60 | * IS_ERR@p3(ptr) ? PTR_ERR(ptr) : 0 |
| 61 | |
| 62 | @script:python depends on org@ |
| 63 | p << r1.p1; |
| 64 | @@ |
| 65 | |
| 66 | coccilib.org.print_todo(p[0], "WARNING: PTR_ERR_OR_ZERO can be used") |
| 67 | |
| 68 | |
| 69 | @script:python depends on org@ |
| 70 | p << r2.p2; |
| 71 | @@ |
| 72 | |
| 73 | coccilib.org.print_todo(p[0], "WARNING: PTR_ERR_OR_ZERO can be used") |
| 74 | |
| 75 | @script:python depends on org@ |
| 76 | p << r3.p3; |
| 77 | @@ |
| 78 | |
| 79 | coccilib.org.print_todo(p[0], "WARNING: PTR_ERR_OR_ZERO can be used") |
| 80 | |
| 81 | @script:python depends on report@ |
| 82 | p << r1.p1; |
| 83 | @@ |
| 84 | |
| 85 | coccilib.report.print_report(p[0], "WARNING: PTR_ERR_OR_ZERO can be used") |
| 86 | |
| 87 | @script:python depends on report@ |
| 88 | p << r2.p2; |
| 89 | @@ |
| 90 | |
| 91 | coccilib.report.print_report(p[0], "WARNING: PTR_ERR_OR_ZERO can be used") |
| 92 | |
| 93 | @script:python depends on report@ |
| 94 | p << r3.p3; |
| 95 | @@ |
| 96 | |
| 97 | coccilib.report.print_report(p[0], "WARNING: PTR_ERR_OR_ZERO can be used") |