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;
20@@
21(
22ret = \(pm_runtime_idle\|
23	pm_runtime_suspend\|
24	pm_runtime_autosuspend\|
25	pm_runtime_resume\|
26	pm_request_idle\|
27	pm_request_resume\|
28	pm_request_autosuspend\|
29	pm_runtime_get\|
30	pm_runtime_get_sync\|
31	pm_runtime_put\|
32	pm_runtime_put_autosuspend\|
33	pm_runtime_put_sync\|
34	pm_runtime_put_sync_suspend\|
35	pm_runtime_put_sync_autosuspend\|
36	pm_runtime_set_active\|
37	pm_schedule_suspend\|
38	pm_runtime_barrier\|
39	pm_generic_runtime_suspend\|
40	pm_generic_runtime_resume\)(...);
41...
42IS_ERR_VALUE(ret)
43...
44)
45
46//----------------------------------------------------------
47//  For context mode
48//----------------------------------------------------------
49
50@depends on runtime_bad_err_handle && context@
51identifier pm_runtime_api;
52expression ret;
53@@
54(
55ret = pm_runtime_api(...);
56...
57* IS_ERR_VALUE(ret)
58...
59)
60
61//----------------------------------------------------------
62//  For patch mode
63//----------------------------------------------------------
64
65@depends on runtime_bad_err_handle && patch@
66identifier pm_runtime_api;
67expression ret;
68@@
69(
70ret = pm_runtime_api(...);
71...
72- IS_ERR_VALUE(ret)
73+ ret < 0
74...
75)
76
77//----------------------------------------------------------
78//  For org and report mode
79//----------------------------------------------------------
80
81@r depends on runtime_bad_err_handle exists@
82position p1, p2;
83identifier pm_runtime_api;
84expression ret;
85@@
86(
87ret = pm_runtime_api@p1(...);
88...
89IS_ERR_VALUE@p2(ret)
90...
91)
92
93@script:python depends on org@
94p1 << r.p1;
95p2 << r.p2;
96pm_runtime_api << r.pm_runtime_api;
97@@
98
99cocci.print_main(pm_runtime_api,p1)
100cocci.print_secs("IS_ERR_VALUE",p2)
101
102@script:python depends on report@
103p1 << r.p1;
104p2 << r.p2;
105pm_runtime_api << r.pm_runtime_api;
106@@
107
108msg = "%s returns < 0 as error. Unecessary IS_ERR_VALUE at line %s" % (pm_runtime_api, p2[0].line)
109coccilib.report.print_report(p1[0],msg)
110