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