call_kern.cocci 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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) 2010 Nicolas Palix, DIKU. GPLv2.
  8. // Copyright: (C) 2010 Julia Lawall, DIKU. GPLv2.
  9. // Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2.
  10. // URL: http://coccinelle.lip6.fr/
  11. // Comments:
  12. // Options: -no_includes -include_headers
  13. virtual patch
  14. @gfp exists@
  15. identifier fn;
  16. position p;
  17. @@
  18. fn(...) {
  19. ... when != read_unlock_irq(...)
  20. when != write_unlock_irq(...)
  21. when != read_unlock_irqrestore(...)
  22. when != write_unlock_irqrestore(...)
  23. when != spin_unlock(...)
  24. when != spin_unlock_irq(...)
  25. when != spin_unlock_irqrestore(...)
  26. when != local_irq_enable(...)
  27. when any
  28. GFP_KERNEL@p
  29. ... when any
  30. }
  31. @locked@
  32. identifier gfp.fn;
  33. @@
  34. (
  35. read_lock_irq
  36. |
  37. write_lock_irq
  38. |
  39. read_lock_irqsave
  40. |
  41. write_lock_irqsave
  42. |
  43. spin_lock
  44. |
  45. spin_trylock
  46. |
  47. spin_lock_irq
  48. |
  49. spin_lock_irqsave
  50. |
  51. local_irq_disable
  52. )
  53. (...)
  54. ... when != read_unlock_irq(...)
  55. when != write_unlock_irq(...)
  56. when != read_unlock_irqrestore(...)
  57. when != write_unlock_irqrestore(...)
  58. when != spin_unlock(...)
  59. when != spin_unlock_irq(...)
  60. when != spin_unlock_irqrestore(...)
  61. when != local_irq_enable(...)
  62. fn(...)
  63. @depends on locked@
  64. position gfp.p;
  65. @@
  66. - GFP_KERNEL@p
  67. + GFP_ATOMIC