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