Commit 79f0345fefaafb7cde301a830471edd21a37989b
Committed by
Michal Marek
1 parent
37e2c2a775
Exists in
master
and in
16 other branches
scripts: Coccinelle script for pm_runtime_* return checks with IS_ERR_VALUE
As indicated by Sekhar in [1], there seems to be a tendency to use IS_ERR_VALUE to check the error result for pm_runtime_* functions which make no sense considering commit c48cd65 (ARM: OMAP: use consistent error checking) - the error values can either be < 0 for error OR 0, 1 in cases where we have success. So, setup a coccinelle script to help identify the same. [1] http://marc.info/?t=138472678100003&r=1&w=2 Cc: Russell King <rmk+kernel@arm.linux.org.uk> Reported-by: Sekhar Nori <nsekhar@ti.com> Signed-off-by: Nishanth Menon <nm@ti.com> Acked-by: Julia Lawall <julia.lawall@lip6.fr> Signed-off-by: Michal Marek <mmarek@suse.cz>
Showing 1 changed file with 109 additions and 0 deletions Side-by-side Diff
scripts/coccinelle/api/pm_runtime.cocci
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 | + | |
9 | +virtual patch | |
10 | +virtual context | |
11 | +virtual org | |
12 | +virtual report | |
13 | + | |
14 | +//---------------------------------------------------------- | |
15 | +// Detection | |
16 | +//---------------------------------------------------------- | |
17 | + | |
18 | +@runtime_bad_err_handle exists@ | |
19 | +expression ret; | |
20 | +@@ | |
21 | +( | |
22 | +ret = \(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 | +... | |
42 | +IS_ERR_VALUE(ret) | |
43 | +... | |
44 | +) | |
45 | + | |
46 | +//---------------------------------------------------------- | |
47 | +// For context mode | |
48 | +//---------------------------------------------------------- | |
49 | + | |
50 | +@depends on runtime_bad_err_handle && context@ | |
51 | +identifier pm_runtime_api; | |
52 | +expression ret; | |
53 | +@@ | |
54 | +( | |
55 | +ret = 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@ | |
66 | +identifier pm_runtime_api; | |
67 | +expression ret; | |
68 | +@@ | |
69 | +( | |
70 | +ret = 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@ | |
82 | +position p1, p2; | |
83 | +identifier pm_runtime_api; | |
84 | +expression ret; | |
85 | +@@ | |
86 | +( | |
87 | +ret = pm_runtime_api@p1(...); | |
88 | +... | |
89 | +IS_ERR_VALUE@p2(ret) | |
90 | +... | |
91 | +) | |
92 | + | |
93 | +@script:python depends on org@ | |
94 | +p1 << r.p1; | |
95 | +p2 << r.p2; | |
96 | +pm_runtime_api << r.pm_runtime_api; | |
97 | +@@ | |
98 | + | |
99 | +cocci.print_main(pm_runtime_api,p1) | |
100 | +cocci.print_secs("IS_ERR_VALUE",p2) | |
101 | + | |
102 | +@script:python depends on report@ | |
103 | +p1 << r.p1; | |
104 | +p2 << r.p2; | |
105 | +pm_runtime_api << r.pm_runtime_api; | |
106 | +@@ | |
107 | + | |
108 | +msg = "%s returns < 0 as error. Unecessary IS_ERR_VALUE at line %s" % (pm_runtime_api, p2[0].line) | |
109 | +coccilib.report.print_report(p1[0],msg) |