blob: d67ccf5f822797928151bf3d659d3e28661e4c3a [file] [log] [blame]
Nishanth Menon79f03452013-12-02 07:39:41 -06001/// Make sure pm_runtime_* calls does not use unnecessary IS_ERR_VALUE
Fabio Estevamf9beafc2015-05-09 17:09:27 -03002///
Nishanth Menon79f03452013-12-02 07:39:41 -06003// Keywords: pm_runtime
4// Confidence: Medium
5// Copyright (C) 2013 Texas Instruments Incorporated - GPLv2.
6// URL: http://coccinelle.lip6.fr/
7// Options: --include-headers
8
9virtual patch
10virtual context
11virtual org
12virtual report
13
14//----------------------------------------------------------
15// Detection
16//----------------------------------------------------------
17
18@runtime_bad_err_handle exists@
19expression ret;
Julia Lawalld97629f2016-09-22 10:28:55 +020020position p;
Nishanth Menon79f03452013-12-02 07:39:41 -060021@@
22(
Julia Lawalld97629f2016-09-22 10:28:55 +020023ret@p = \(pm_runtime_idle\|
Nishanth Menon79f03452013-12-02 07:39:41 -060024 pm_runtime_suspend\|
25 pm_runtime_autosuspend\|
26 pm_runtime_resume\|
27 pm_request_idle\|
28 pm_request_resume\|
29 pm_request_autosuspend\|
30 pm_runtime_get\|
31 pm_runtime_get_sync\|
32 pm_runtime_put\|
33 pm_runtime_put_autosuspend\|
34 pm_runtime_put_sync\|
35 pm_runtime_put_sync_suspend\|
36 pm_runtime_put_sync_autosuspend\|
37 pm_runtime_set_active\|
38 pm_schedule_suspend\|
39 pm_runtime_barrier\|
40 pm_generic_runtime_suspend\|
41 pm_generic_runtime_resume\)(...);
42...
43IS_ERR_VALUE(ret)
44...
45)
46
47//----------------------------------------------------------
48// For context mode
49//----------------------------------------------------------
50
Julia Lawalld97629f2016-09-22 10:28:55 +020051@depends on context@
Nishanth Menon79f03452013-12-02 07:39:41 -060052identifier pm_runtime_api;
53expression ret;
Julia Lawalld97629f2016-09-22 10:28:55 +020054position runtime_bad_err_handle.p;
Nishanth Menon79f03452013-12-02 07:39:41 -060055@@
56(
Julia Lawalld97629f2016-09-22 10:28:55 +020057ret@p = pm_runtime_api(...);
Nishanth Menon79f03452013-12-02 07:39:41 -060058...
59* IS_ERR_VALUE(ret)
60...
61)
62
63//----------------------------------------------------------
64// For patch mode
65//----------------------------------------------------------
66
Julia Lawalld97629f2016-09-22 10:28:55 +020067@depends on patch@
Nishanth Menon79f03452013-12-02 07:39:41 -060068identifier pm_runtime_api;
69expression ret;
Julia Lawalld97629f2016-09-22 10:28:55 +020070position runtime_bad_err_handle.p;
Nishanth Menon79f03452013-12-02 07:39:41 -060071@@
72(
Julia Lawalld97629f2016-09-22 10:28:55 +020073ret@p = pm_runtime_api(...);
Nishanth Menon79f03452013-12-02 07:39:41 -060074...
75- IS_ERR_VALUE(ret)
76+ ret < 0
77...
78)
79
80//----------------------------------------------------------
81// For org and report mode
82//----------------------------------------------------------
83
Julia Lawalld97629f2016-09-22 10:28:55 +020084@r depends on (org || report) exists@
Nishanth Menon79f03452013-12-02 07:39:41 -060085position p1, p2;
86identifier pm_runtime_api;
87expression ret;
Julia Lawalld97629f2016-09-22 10:28:55 +020088position runtime_bad_err_handle.p;
Nishanth Menon79f03452013-12-02 07:39:41 -060089@@
90(
Julia Lawalld97629f2016-09-22 10:28:55 +020091ret@p = pm_runtime_api@p1(...);
Nishanth Menon79f03452013-12-02 07:39:41 -060092...
93IS_ERR_VALUE@p2(ret)
94...
95)
96
97@script:python depends on org@
98p1 << r.p1;
99p2 << r.p2;
100pm_runtime_api << r.pm_runtime_api;
101@@
102
103cocci.print_main(pm_runtime_api,p1)
104cocci.print_secs("IS_ERR_VALUE",p2)
105
106@script:python depends on report@
107p1 << r.p1;
108p2 << r.p2;
109pm_runtime_api << r.pm_runtime_api;
110@@
111
112msg = "%s returns < 0 as error. Unecessary IS_ERR_VALUE at line %s" % (pm_runtime_api, p2[0].line)
113coccilib.report.print_report(p1[0],msg)