pm_runtime.cocci 2.3 KB

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