pci_free_consistent.cocci 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /// Find missing pci_free_consistent for every pci_alloc_consistent.
  3. ///
  4. // Confidence: Moderate
  5. // Copyright: (C) 2013 Petr Strnad.
  6. // URL: https://coccinelle.gitlabpages.inria.fr/website
  7. // Keywords: pci_free_consistent, pci_alloc_consistent
  8. // Options: --no-includes --include-headers
  9. virtual report
  10. virtual org
  11. @search@
  12. local idexpression id;
  13. expression x,y,z,e;
  14. position p1,p2;
  15. type T;
  16. @@
  17. id = pci_alloc_consistent@p1(x,y,&z)
  18. ... when != e = id
  19. if (id == NULL || ...) { ... return ...; }
  20. ... when != pci_free_consistent(x,y,id,z)
  21. when != if (id) { ... pci_free_consistent(x,y,id,z) ... }
  22. when != if (y) { ... pci_free_consistent(x,y,id,z) ... }
  23. when != e = (T)id
  24. when exists
  25. (
  26. return 0;
  27. |
  28. return 1;
  29. |
  30. return id;
  31. |
  32. return@p2 ...;
  33. )
  34. @script:python depends on report@
  35. p1 << search.p1;
  36. p2 << search.p2;
  37. @@
  38. msg = "ERROR: missing pci_free_consistent; pci_alloc_consistent on line %s and return without freeing on line %s" % (p1[0].line,p2[0].line)
  39. coccilib.report.print_report(p2[0],msg)
  40. @script:python depends on org@
  41. p1 << search.p1;
  42. p2 << search.p2;
  43. @@
  44. msg = "ERROR: missing pci_free_consistent; pci_alloc_consistent on line %s and return without freeing on line %s" % (p1[0].line,p2[0].line)
  45. cocci.print_main(msg,p1)
  46. cocci.print_secs("",p2)