| 1 |
// SPDX-License-Identifier: GPL-2.0-only |
| 2 |
/// Make sure pm_runtime_* calls do not unnecessarily use IS_ERR_VALUE |
| 3 |
/// |
| 4 |
// Keywords: pm_runtime |
| 5 |
// Confidence: Medium |
| 6 |
// Copyright (C) 2013 Texas Instruments Incorporated - |
| 7 |
// URL: https://coccinelle.gitlabpages.inria.fr/website |
| 8 |
// Options: --include-headers |
| 9 |
|
| 10 |
virtual patch |
| 11 |
virtual context |
| 12 |
virtual org |
| 13 |
virtual report |
| 14 |
|
| 15 |
//---------------------------------------------------------- |
| 16 |
// Detection |
| 17 |
//---------------------------------------------------------- |
| 18 |
|
| 19 |
@runtime_bad_err_handle exists@ |
| 20 |
expression ret; |
| 21 |
position p; |
| 22 |
@@ |
| 23 |
( |
| 24 |
ret@p = \(pm_runtime_idle\| |
| 25 |
pm_runtime_suspend\| |
| 26 |
pm_runtime_autosuspend\| |
| 27 |
pm_runtime_resume\| |
| 28 |
pm_request_idle\| |
| 29 |
pm_request_resume\| |
| 30 |
pm_request_autosuspend\| |
| 31 |
pm_runtime_get\| |
| 32 |
pm_runtime_get_sync\| |
| 33 |
pm_runtime_put\| |
| 34 |
pm_runtime_put_autosuspend\| |
| 35 |
pm_runtime_put_sync\| |
| 36 |
pm_runtime_put_sync_suspend\| |
| 37 |
pm_runtime_put_sync_autosuspend\| |
| 38 |
pm_runtime_set_active\| |
| 39 |
pm_schedule_suspend\| |
| 40 |
pm_generic_runtime_suspend\| |
| 41 |
pm_generic_runtime_resume\)(...); |
| 42 |
... |
| 43 |
IS_ERR_VALUE(ret) |
| 44 |
... |
| 45 |
) |
| 46 |
|
| 47 |
//---------------------------------------------------------- |
| 48 |
// For context mode |
| 49 |
//---------------------------------------------------------- |
| 50 |
|
| 51 |
@depends on context@ |
| 52 |
identifier pm_runtime_api; |
| 53 |
expression ret; |
| 54 |
position runtime_bad_err_handle.p; |
| 55 |
@@ |
| 56 |
( |
| 57 |
ret@p = pm_runtime_api(...); |
| 58 |
... |
| 59 |
* IS_ERR_VALUE(ret) |
| 60 |
... |
| 61 |
) |
| 62 |
|
| 63 |
//---------------------------------------------------------- |
| 64 |
// For patch mode |
| 65 |
//---------------------------------------------------------- |
| 66 |
|
| 67 |
@depends on patch@ |
| 68 |
identifier pm_runtime_api; |
| 69 |
expression ret; |
| 70 |
position runtime_bad_err_handle.p; |
| 71 |
@@ |
| 72 |
( |
| 73 |
ret@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@ |
| 85 |
position p1, p2; |
| 86 |
identifier pm_runtime_api; |
| 87 |
expression ret; |
| 88 |
position runtime_bad_err_handle.p; |
| 89 |
@@ |
| 90 |
( |
| 91 |
ret@p = pm_runtime_api@p1(...); |
| 92 |
... |
| 93 |
IS_ERR_VALUE@p2(ret) |
| 94 |
... |
| 95 |
) |
| 96 |
|
| 97 |
@script:python depends on org@ |
| 98 |
p1 << r.p1; |
| 99 |
p2 << r.p2; |
| 100 |
pm_runtime_api << r.pm_runtime_api; |
| 101 |
@@ |
| 102 |
|
| 103 |
cocci.print_main(pm_runtime_api,p1) |
| 104 |
cocci.print_secs("IS_ERR_VALUE",p2) |
| 105 |
|
| 106 |
@script:python depends on report@ |
| 107 |
p1 << r.p1; |
| 108 |
p2 << r.p2; |
| 109 |
pm_runtime_api << r.pm_runtime_api; |
| 110 |
@@ |
| 111 |
|
| 112 |
msg = "%s returns < 0 as error. Unnecessary IS_ERR_VALUE at line %s" % (pm_runtime_api, p2[0].line) |
| 113 |
coccilib.report.print_report(p1[0],msg) |