2019-06-04 01:11:38 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2012-08-25 13:42:45 -07:00
|
|
|
/// PTR_ERR should access the value just tested by IS_ERR
|
2015-08-30 13:18:14 -07:00
|
|
|
//# There can be false positives in the patch case, where it is the call to
|
2012-08-25 13:42:45 -07:00
|
|
|
//# IS_ERR that is wrong.
|
|
|
|
///
|
|
|
|
// Confidence: High
|
2019-06-04 01:11:38 -07:00
|
|
|
// Copyright: (C) 2012, 2015 Julia Lawall, INRIA.
|
|
|
|
// Copyright: (C) 2012, 2015 Gilles Muller, INRIA.
|
2022-08-07 09:19:54 -07:00
|
|
|
// URL: https://coccinelle.gitlabpages.inria.fr/website
|
2013-06-20 04:10:56 -07:00
|
|
|
// Options: --no-includes --include-headers
|
2012-08-25 13:42:45 -07:00
|
|
|
|
|
|
|
virtual patch
|
|
|
|
virtual context
|
|
|
|
virtual org
|
|
|
|
virtual report
|
|
|
|
|
2015-08-30 13:18:14 -07:00
|
|
|
@ok1 exists@
|
|
|
|
expression x,e;
|
|
|
|
position p;
|
2012-08-25 13:42:45 -07:00
|
|
|
@@
|
|
|
|
|
2015-08-30 13:18:14 -07:00
|
|
|
if (IS_ERR(x=e) || ...) {
|
|
|
|
<...
|
|
|
|
PTR_ERR@p(x)
|
|
|
|
...>
|
|
|
|
}
|
|
|
|
|
|
|
|
@ok2 exists@
|
|
|
|
expression x,e1,e2;
|
|
|
|
position p;
|
|
|
|
@@
|
|
|
|
|
|
|
|
if (IS_ERR(x) || ...) {
|
|
|
|
<...
|
2012-08-25 13:42:45 -07:00
|
|
|
(
|
2015-08-30 13:18:14 -07:00
|
|
|
PTR_ERR@p(\(e1 ? e2 : x\|e1 ? x : e2\))
|
2012-08-25 13:42:45 -07:00
|
|
|
|
|
2015-08-30 13:18:14 -07:00
|
|
|
PTR_ERR@p(x)
|
|
|
|
)
|
|
|
|
...>
|
|
|
|
}
|
|
|
|
|
|
|
|
@r1 depends on patch && !context && !org && !report exists@
|
|
|
|
expression x,y;
|
|
|
|
position p != {ok1.p,ok2.p};
|
|
|
|
@@
|
|
|
|
|
|
|
|
if (IS_ERR(x) || ...) {
|
|
|
|
... when any
|
|
|
|
when != IS_ERR(...)
|
|
|
|
(
|
|
|
|
PTR_ERR(x)
|
2012-08-25 13:42:45 -07:00
|
|
|
|
|
2015-08-30 13:18:14 -07:00
|
|
|
PTR_ERR@p(
|
|
|
|
- y
|
|
|
|
+ x
|
2012-08-25 13:42:45 -07:00
|
|
|
)
|
|
|
|
)
|
2015-08-30 13:18:14 -07:00
|
|
|
... when any
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2012-08-25 13:42:45 -07:00
|
|
|
|
2015-08-30 13:18:14 -07:00
|
|
|
@r1_context depends on !patch && (context || org || report) exists@
|
|
|
|
position p != {ok1.p,ok2.p};
|
|
|
|
expression x, y;
|
|
|
|
position j0, j1;
|
2012-08-25 13:42:45 -07:00
|
|
|
@@
|
|
|
|
|
2015-08-30 13:18:14 -07:00
|
|
|
if (IS_ERR@j0(x) || ...) {
|
|
|
|
... when any
|
|
|
|
when != IS_ERR(...)
|
2012-08-25 13:42:45 -07:00
|
|
|
(
|
2015-08-30 13:18:14 -07:00
|
|
|
PTR_ERR(x)
|
2012-08-25 13:42:45 -07:00
|
|
|
|
|
2015-08-30 13:18:14 -07:00
|
|
|
PTR_ERR@j1@p(
|
|
|
|
y
|
|
|
|
)
|
2012-08-25 13:42:45 -07:00
|
|
|
)
|
2015-08-30 13:18:14 -07:00
|
|
|
... when any
|
|
|
|
}
|
2012-08-25 13:42:45 -07:00
|
|
|
|
2015-08-30 13:18:14 -07:00
|
|
|
@r1_disj depends on !patch && (context || org || report) exists@
|
|
|
|
position p != {ok1.p,ok2.p};
|
|
|
|
expression x, y;
|
|
|
|
position r1_context.j0, r1_context.j1;
|
2012-08-25 13:42:45 -07:00
|
|
|
@@
|
|
|
|
|
2015-08-30 13:18:14 -07:00
|
|
|
* if (IS_ERR@j0(x) || ...) {
|
|
|
|
... when any
|
|
|
|
when != IS_ERR(...)
|
|
|
|
* PTR_ERR@j1@p(
|
|
|
|
y
|
|
|
|
)
|
|
|
|
... when any
|
|
|
|
}
|
2012-08-25 13:42:45 -07:00
|
|
|
|
2015-08-30 13:18:14 -07:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
@script:python r1_org depends on org@
|
|
|
|
j0 << r1_context.j0;
|
|
|
|
j1 << r1_context.j1;
|
2012-08-25 13:42:45 -07:00
|
|
|
@@
|
|
|
|
|
2015-08-30 13:18:14 -07:00
|
|
|
msg = "inconsistent IS_ERR and PTR_ERR"
|
|
|
|
coccilib.org.print_todo(j0[0], msg)
|
|
|
|
coccilib.org.print_link(j1[0], "")
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
@script:python r1_report depends on report@
|
|
|
|
j0 << r1_context.j0;
|
|
|
|
j1 << r1_context.j1;
|
|
|
|
@@
|
|
|
|
|
|
|
|
msg = "inconsistent IS_ERR and PTR_ERR on line %s." % (j1[0].line)
|
|
|
|
coccilib.report.print_report(j0[0], msg)
|
|
|
|
|