platform_no_drv_owner.cocci 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /// Remove .owner field if calls are used which set it automatically
  3. ///
  4. // Confidence: High
  5. // Copyright: (C) 2014 Wolfram Sang.
  6. virtual patch
  7. virtual context
  8. virtual org
  9. virtual report
  10. @match1@
  11. declarer name builtin_i2c_driver;
  12. declarer name builtin_platform_driver;
  13. declarer name builtin_platform_driver_probe;
  14. declarer name module_i2c_driver;
  15. declarer name module_platform_driver;
  16. declarer name module_platform_driver_probe;
  17. identifier __driver;
  18. @@
  19. (
  20. builtin_i2c_driver(__driver);
  21. |
  22. builtin_platform_driver(__driver);
  23. |
  24. builtin_platform_driver_probe(__driver, ...);
  25. |
  26. module_i2c_driver(__driver);
  27. |
  28. module_platform_driver(__driver);
  29. |
  30. module_platform_driver_probe(__driver, ...);
  31. )
  32. @fix1 depends on match1 && patch && !context && !org && !report@
  33. identifier match1.__driver;
  34. @@
  35. static struct platform_driver __driver = {
  36. .driver = {
  37. - .owner = THIS_MODULE,
  38. }
  39. };
  40. @fix1_i2c depends on match1 && patch && !context && !org && !report@
  41. identifier match1.__driver;
  42. @@
  43. static struct i2c_driver __driver = {
  44. .driver = {
  45. - .owner = THIS_MODULE,
  46. }
  47. };
  48. @match2@
  49. identifier __driver;
  50. @@
  51. (
  52. platform_driver_register(&__driver)
  53. |
  54. platform_driver_probe(&__driver, ...)
  55. |
  56. platform_create_bundle(&__driver, ...)
  57. |
  58. i2c_add_driver(&__driver)
  59. )
  60. @fix2 depends on match2 && patch && !context && !org && !report@
  61. identifier match2.__driver;
  62. @@
  63. static struct platform_driver __driver = {
  64. .driver = {
  65. - .owner = THIS_MODULE,
  66. }
  67. };
  68. @fix2_i2c depends on match2 && patch && !context && !org && !report@
  69. identifier match2.__driver;
  70. @@
  71. static struct i2c_driver __driver = {
  72. .driver = {
  73. - .owner = THIS_MODULE,
  74. }
  75. };
  76. // ----------------------------------------------------------------------------
  77. @fix1_context depends on match1 && !patch && (context || org || report)@
  78. identifier match1.__driver;
  79. position j0;
  80. @@
  81. static struct platform_driver __driver = {
  82. .driver = {
  83. * .owner@j0 = THIS_MODULE,
  84. }
  85. };
  86. @fix1_i2c_context depends on match1 && !patch && (context || org || report)@
  87. identifier match1.__driver;
  88. position j0;
  89. @@
  90. static struct i2c_driver __driver = {
  91. .driver = {
  92. * .owner@j0 = THIS_MODULE,
  93. }
  94. };
  95. @fix2_context depends on match2 && !patch && (context || org || report)@
  96. identifier match2.__driver;
  97. position j0;
  98. @@
  99. static struct platform_driver __driver = {
  100. .driver = {
  101. * .owner@j0 = THIS_MODULE,
  102. }
  103. };
  104. @fix2_i2c_context depends on match2 && !patch && (context || org || report)@
  105. identifier match2.__driver;
  106. position j0;
  107. @@
  108. static struct i2c_driver __driver = {
  109. .driver = {
  110. * .owner@j0 = THIS_MODULE,
  111. }
  112. };
  113. // ----------------------------------------------------------------------------
  114. @script:python fix1_org depends on org@
  115. j0 << fix1_context.j0;
  116. @@
  117. msg = "No need to set .owner here. The core will do it."
  118. coccilib.org.print_todo(j0[0], msg)
  119. @script:python fix1_i2c_org depends on org@
  120. j0 << fix1_i2c_context.j0;
  121. @@
  122. msg = "No need to set .owner here. The core will do it."
  123. coccilib.org.print_todo(j0[0], msg)
  124. @script:python fix2_org depends on org@
  125. j0 << fix2_context.j0;
  126. @@
  127. msg = "No need to set .owner here. The core will do it."
  128. coccilib.org.print_todo(j0[0], msg)
  129. @script:python fix2_i2c_org depends on org@
  130. j0 << fix2_i2c_context.j0;
  131. @@
  132. msg = "No need to set .owner here. The core will do it."
  133. coccilib.org.print_todo(j0[0], msg)
  134. // ----------------------------------------------------------------------------
  135. @script:python fix1_report depends on report@
  136. j0 << fix1_context.j0;
  137. @@
  138. msg = "No need to set .owner here. The core will do it."
  139. coccilib.report.print_report(j0[0], msg)
  140. @script:python fix1_i2c_report depends on report@
  141. j0 << fix1_i2c_context.j0;
  142. @@
  143. msg = "No need to set .owner here. The core will do it."
  144. coccilib.report.print_report(j0[0], msg)
  145. @script:python fix2_report depends on report@
  146. j0 << fix2_context.j0;
  147. @@
  148. msg = "No need to set .owner here. The core will do it."
  149. coccilib.report.print_report(j0[0], msg)
  150. @script:python fix2_i2c_report depends on report@
  151. j0 << fix2_i2c_context.j0;
  152. @@
  153. msg = "No need to set .owner here. The core will do it."
  154. coccilib.report.print_report(j0[0], msg)