drop_kmalloc_cast.cocci 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. ///
  2. /// Casting (void *) value returned by kmalloc is useless
  3. /// as mentioned in Documentation/CodingStyle, Chap 14.
  4. ///
  5. // Confidence: High
  6. // Copyright: 2009,2010 Nicolas Palix, DIKU. GPLv2.
  7. // URL: http://coccinelle.lip6.fr/
  8. // Options: -no_includes -include_headers
  9. //
  10. // Keywords: kmalloc, kzalloc, kcalloc
  11. // Version min: < 2.6.12 kmalloc
  12. // Version min: < 2.6.12 kcalloc
  13. // Version min: 2.6.14 kzalloc
  14. //
  15. virtual context
  16. virtual patch
  17. virtual org
  18. virtual report
  19. //----------------------------------------------------------
  20. // For context mode
  21. //----------------------------------------------------------
  22. @depends on context@
  23. type T;
  24. @@
  25. * (T *)
  26. \(kmalloc\|kzalloc\|kcalloc\)(...)
  27. //----------------------------------------------------------
  28. // For patch mode
  29. //----------------------------------------------------------
  30. @depends on patch@
  31. type T;
  32. @@
  33. - (T *)
  34. \(kmalloc\|kzalloc\|kcalloc\)(...)
  35. //----------------------------------------------------------
  36. // For org and report mode
  37. //----------------------------------------------------------
  38. @r depends on org || report@
  39. type T;
  40. position p;
  41. @@
  42. (T@p *)\(kmalloc\|kzalloc\|kcalloc\)(...)
  43. @script:python depends on org@
  44. p << r.p;
  45. t << r.T;
  46. @@
  47. coccilib.org.print_safe_todo(p[0], t)
  48. @script:python depends on report@
  49. p << r.p;
  50. t << r.T;
  51. @@
  52. msg="WARNING: casting value returned by k[cmz]alloc to (%s *) is useless." % (t)
  53. coccilib.report.print_report(p[0], msg)