call_kern.cocci 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /// Find functions that refer to GFP_KERNEL but are called with locks held.
  2. //# The proposed change of converting the GFP_KERNEL is not necessarily the
  3. //# correct one. It may be desired to unlock the lock, or to not call the
  4. //# function under the lock in the first place.
  5. ///
  6. // Confidence: Moderate
  7. // Copyright: (C) 2012 Nicolas Palix. GPLv2.
  8. // Copyright: (C) 2012 Julia Lawall, INRIA/LIP6. GPLv2.
  9. // Copyright: (C) 2012 Gilles Muller, INRIA/LiP6. GPLv2.
  10. // URL: http://coccinelle.lip6.fr/
  11. // Comments:
  12. // Options: --no-includes --include-headers
  13. virtual patch
  14. virtual context
  15. virtual org
  16. virtual report
  17. @gfp exists@
  18. identifier fn;
  19. position p;
  20. @@
  21. fn(...) {
  22. ... when != read_unlock_irq(...)
  23. when != write_unlock_irq(...)
  24. when != read_unlock_irqrestore(...)
  25. when != write_unlock_irqrestore(...)
  26. when != spin_unlock(...)
  27. when != spin_unlock_irq(...)
  28. when != spin_unlock_irqrestore(...)
  29. when != local_irq_enable(...)
  30. when any
  31. GFP_KERNEL@p
  32. ... when any
  33. }
  34. @locked exists@
  35. identifier gfp.fn;
  36. position p1,p2;
  37. @@
  38. (
  39. read_lock_irq@p1
  40. |
  41. write_lock_irq@p1
  42. |
  43. read_lock_irqsave@p1
  44. |
  45. write_lock_irqsave@p1
  46. |
  47. spin_lock@p1
  48. |
  49. spin_trylock@p1
  50. |
  51. spin_lock_irq@p1
  52. |
  53. spin_lock_irqsave@p1
  54. |
  55. local_irq_disable@p1
  56. )
  57. (...)
  58. ... when != read_unlock_irq(...)
  59. when != write_unlock_irq(...)
  60. when != read_unlock_irqrestore(...)
  61. when != write_unlock_irqrestore(...)
  62. when != spin_unlock(...)
  63. when != spin_unlock_irq(...)
  64. when != spin_unlock_irqrestore(...)
  65. when != local_irq_enable(...)
  66. fn@p2(...)
  67. @depends on locked && patch@
  68. position gfp.p;
  69. @@
  70. - GFP_KERNEL@p
  71. + GFP_ATOMIC
  72. @depends on locked && !patch@
  73. position gfp.p;
  74. @@
  75. * GFP_KERNEL@p
  76. @script:python depends on !patch && org@
  77. p << gfp.p;
  78. fn << gfp.fn;
  79. p1 << locked.p1;
  80. p2 << locked.p2;
  81. @@
  82. cocci.print_main("lock",p1)
  83. cocci.print_secs("call",p2)
  84. cocci.print_secs("GFP_KERNEL",p)
  85. @script:python depends on !patch && report@
  86. p << gfp.p;
  87. fn << gfp.fn;
  88. p1 << locked.p1;
  89. p2 << locked.p2;
  90. @@
  91. msg = "ERROR: function %s called on line %s inside lock on line %s but uses GFP_KERNEL" % (fn,p2[0].line,p1[0].line)
  92. coccilib.report.print_report(p[0], msg)