pm_runtime.cocci 2.3 KB

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