xref: /linux/scripts/coccinelle/api/pm_runtime.cocci (revision e5c86679d5e864947a52fb31e45a425dea3e7fa9)
1/// Make sure pm_runtime_* calls does not use unnecessary IS_ERR_VALUE
2///
3// 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;
20position p;
21@@
22(
23ret@p = \(pm_runtime_idle\|
24	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
51@depends on context@
52identifier pm_runtime_api;
53expression ret;
54position runtime_bad_err_handle.p;
55@@
56(
57ret@p = pm_runtime_api(...);
58...
59* IS_ERR_VALUE(ret)
60...
61)
62
63//----------------------------------------------------------
64//  For patch mode
65//----------------------------------------------------------
66
67@depends on patch@
68identifier pm_runtime_api;
69expression ret;
70position runtime_bad_err_handle.p;
71@@
72(
73ret@p = pm_runtime_api(...);
74...
75- IS_ERR_VALUE(ret)
76+ ret < 0
77...
78)
79
80//----------------------------------------------------------
81//  For org and report mode
82//----------------------------------------------------------
83
84@r depends on (org || report) exists@
85position p1, p2;
86identifier pm_runtime_api;
87expression ret;
88position runtime_bad_err_handle.p;
89@@
90(
91ret@p = pm_runtime_api@p1(...);
92...
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)
114