pci_free_consistent.cocci 1.2 KB

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