1// SPDX-License-Identifier: GPL-2.0-only 2/// 3/// Use PTR_ERR_OR_ZERO rather than if(IS_ERR(...)) + PTR_ERR 4/// 5// Confidence: High 6// Copyright: (C) 2012 Julia Lawall, INRIA/LIP6. 7// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6. 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 15virtual context 16virtual patch 17virtual org 18virtual report 19 20@depends on patch@ 21expression 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@ 28expression 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@ 35expression ptr; 36@@ 37 38- (IS_ERR(ptr) ? PTR_ERR(ptr) : 0) 39+ PTR_ERR_OR_ZERO(ptr) 40 41@r1 depends on !patch@ 42expression ptr; 43position p1; 44@@ 45 46* if@p1 (IS_ERR(ptr)) return PTR_ERR(ptr); else return 0; 47 48@r2 depends on !patch@ 49expression ptr; 50position p2; 51@@ 52 53* if@p2 (IS_ERR(ptr)) return PTR_ERR(ptr); return 0; 54 55@r3 depends on !patch@ 56expression ptr; 57position p3; 58@@ 59 60* IS_ERR@p3(ptr) ? PTR_ERR(ptr) : 0 61 62@script:python depends on org@ 63p << r1.p1; 64@@ 65 66coccilib.org.print_todo(p[0], "WARNING: PTR_ERR_OR_ZERO can be used") 67 68 69@script:python depends on org@ 70p << r2.p2; 71@@ 72 73coccilib.org.print_todo(p[0], "WARNING: PTR_ERR_OR_ZERO can be used") 74 75@script:python depends on org@ 76p << r3.p3; 77@@ 78 79coccilib.org.print_todo(p[0], "WARNING: PTR_ERR_OR_ZERO can be used") 80 81@script:python depends on report@ 82p << r1.p1; 83@@ 84 85coccilib.report.print_report(p[0], "WARNING: PTR_ERR_OR_ZERO can be used") 86 87@script:python depends on report@ 88p << r2.p2; 89@@ 90 91coccilib.report.print_report(p[0], "WARNING: PTR_ERR_OR_ZERO can be used") 92 93@script:python depends on report@ 94p << r3.p3; 95@@ 96 97coccilib.report.print_report(p[0], "WARNING: PTR_ERR_OR_ZERO can be used") 98