~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/scripts/coccinelle/tests/odd_ptr_err.cocci

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  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 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php