pool_zalloc-simple.cocci 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. ///
  2. /// Use *_pool_zalloc rather than *_pool_alloc followed by memset with 0
  3. ///
  4. // Copyright: (C) 2015 Intel Corp. GPLv2.
  5. // Options: --no-includes --include-headers
  6. //
  7. // Keywords: dma_pool_zalloc, pci_pool_zalloc
  8. //
  9. virtual context
  10. virtual patch
  11. virtual org
  12. virtual report
  13. //----------------------------------------------------------
  14. // For context mode
  15. //----------------------------------------------------------
  16. @depends on context@
  17. expression x;
  18. statement S;
  19. @@
  20. * x = \(dma_pool_alloc\|pci_pool_alloc\)(...);
  21. if ((x==NULL) || ...) S
  22. * memset(x,0, ...);
  23. //----------------------------------------------------------
  24. // For patch mode
  25. //----------------------------------------------------------
  26. @depends on patch@
  27. expression x;
  28. expression a,b,c;
  29. statement S;
  30. @@
  31. - x = dma_pool_alloc(a,b,c);
  32. + x = dma_pool_zalloc(a,b,c);
  33. if ((x==NULL) || ...) S
  34. - memset(x,0,...);
  35. @depends on patch@
  36. expression x;
  37. expression a,b,c;
  38. statement S;
  39. @@
  40. - x = pci_pool_alloc(a,b,c);
  41. + x = pci_pool_zalloc(a,b,c);
  42. if ((x==NULL) || ...) S
  43. - memset(x,0,...);
  44. //----------------------------------------------------------
  45. // For org and report mode
  46. //----------------------------------------------------------
  47. @r depends on org || report@
  48. expression x;
  49. expression a,b,c;
  50. statement S;
  51. position p;
  52. @@
  53. x = @p\(dma_pool_alloc\|pci_pool_alloc\)(a,b,c);
  54. if ((x==NULL) || ...) S
  55. memset(x,0, ...);
  56. @script:python depends on org@
  57. p << r.p;
  58. x << r.x;
  59. @@
  60. msg="%s" % (x)
  61. msg_safe=msg.replace("[","@(").replace("]",")")
  62. coccilib.org.print_todo(p[0], msg_safe)
  63. @script:python depends on report@
  64. p << r.p;
  65. x << r.x;
  66. @@
  67. msg="WARNING: *_pool_zalloc should be used for %s, instead of *_pool_alloc/memset" % (x)
  68. coccilib.report.print_report(p[0], msg)