iounmap.cocci 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /// Find missing iounmaps.
  3. ///
  4. //# This only signals a missing iounmap when there is an iounmap later
  5. //# in the same function.
  6. //# False positives can be due to loops.
  7. //
  8. // Confidence: Moderate
  9. // Copyright: (C) 2012 Julia Lawall, INRIA/LIP6.
  10. // Copyright: (C) 2012 Gilles Muller, INRIA/LiP6.
  11. // URL: https://coccinelle.gitlabpages.inria.fr/website
  12. // Comments:
  13. // Options:
  14. virtual context
  15. virtual org
  16. virtual report
  17. @iom@
  18. expression e;
  19. statement S,S1;
  20. int ret;
  21. position p1,p2,p3;
  22. @@
  23. e = \(ioremap@p1\)(...)
  24. ... when != iounmap(e)
  25. if (<+...e...+>) S
  26. ... when any
  27. when != iounmap(e)
  28. when != if (...) { ... iounmap(e); ... }
  29. (
  30. if (ret == 0) S1
  31. |
  32. if (...)
  33. { ...
  34. return 0; }
  35. |
  36. if (...)
  37. { ...
  38. return <+...e...+>; }
  39. |
  40. *if@p2 (...)
  41. { ... when != iounmap(e)
  42. when forall
  43. return@p3 ...; }
  44. )
  45. ... when any
  46. iounmap(e);
  47. @script:python depends on org@
  48. p1 << iom.p1;
  49. p2 << iom.p2;
  50. p3 << iom.p3;
  51. @@
  52. cocci.print_main("ioremap",p1)
  53. cocci.print_secs("if",p2)
  54. cocci.print_secs("needed iounmap",p3)
  55. @script:python depends on report@
  56. p1 << iom.p1;
  57. p2 << iom.p2;
  58. p3 << iom.p3;
  59. @@
  60. msg = "ERROR: missing iounmap; ioremap on line %s and execution via conditional on line %s" % (p1[0].line,p2[0].line)
  61. coccilib.report.print_report(p3[0],msg)