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_runtime_barrier\| 41 pm_generic_runtime_suspend\| 42 pm_generic_runtime_resume\)(...); 43 ... 44 IS_ERR_VALUE(ret) 45 ... 46 ) 47 48 //---------------------------------------------------------- 49 // For context mode 50 //---------------------------------------------------------- 51 52 @depends on context@ 53 identifier pm_runtime_api; 54 expression ret; 55 position runtime_bad_err_handle.p; 56 @@ 57 ( 58 ret@p = pm_runtime_api(...); 59 ... 60 * IS_ERR_VALUE(ret) 61 ... 62 ) 63 64 //---------------------------------------------------------- 65 // For patch mode 66 //---------------------------------------------------------- 67 68 @depends on patch@ 69 identifier pm_runtime_api; 70 expression ret; 71 position runtime_bad_err_handle.p; 72 @@ 73 ( 74 ret@p = pm_runtime_api(...); 75 ... 76 - IS_ERR_VALUE(ret) 77 + ret < 0 78 ... 79 ) 80 81 //---------------------------------------------------------- 82 // For org and report mode 83 //---------------------------------------------------------- 84 85 @r depends on (org || report) exists@ 86 position p1, p2; 87 identifier pm_runtime_api; 88 expression ret; 89 position runtime_bad_err_handle.p; 90 @@ 91 ( 92 ret@p = pm_runtime_api@p1(...); 93 ... 94 IS_ERR_VALUE@p2(ret) 95 ... 96 ) 97 98 @script:python depends on org@ 99 p1 << r.p1; 100 p2 << r.p2; 101 pm_runtime_api << r.pm_runtime_api; 102 @@ 103 104 cocci.print_main(pm_runtime_api,p1) 105 cocci.print_secs("IS_ERR_VALUE",p2) 106 107 @script:python depends on report@ 108 p1 << r.p1; 109 p2 << r.p2; 110 pm_runtime_api << r.pm_runtime_api; 111 @@ 112 113 msg = "%s returns < 0 as error. Unecessary IS_ERR_VALUE at line %s" % (pm_runtime_api, p2[0].line) 114 coccilib.report.print_report(p1[0],msg)
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.