d_find_alias.cocci 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /// Make sure calls to d_find_alias() have a corresponding call to dput().
  2. //
  3. // Keywords: d_find_alias, dput
  4. //
  5. // Confidence: Moderate
  6. // URL: http://coccinelle.lip6.fr/
  7. // Options: --include-headers
  8. virtual context
  9. virtual org
  10. virtual patch
  11. virtual report
  12. @r exists@
  13. local idexpression struct dentry *dent;
  14. expression E, E1;
  15. statement S1, S2;
  16. position p1, p2;
  17. @@
  18. (
  19. if (!(dent@p1 = d_find_alias(...))) S1
  20. |
  21. dent@p1 = d_find_alias(...)
  22. )
  23. <...when != dput(dent)
  24. when != if (...) { <+... dput(dent) ...+> }
  25. when != true !dent || ...
  26. when != dent = E
  27. when != E = dent
  28. if (!dent || ...) S2
  29. ...>
  30. (
  31. return <+...dent...+>;
  32. |
  33. return @p2 ...;
  34. |
  35. dent@p2 = E1;
  36. |
  37. E1 = dent;
  38. )
  39. @depends on context@
  40. local idexpression struct dentry *r.dent;
  41. position r.p1,r.p2;
  42. @@
  43. * dent@p1 = ...
  44. ...
  45. (
  46. * return@p2 ...;
  47. |
  48. * dent@p2
  49. )
  50. @script:python depends on org@
  51. p1 << r.p1;
  52. p2 << r.p2;
  53. @@
  54. cocci.print_main("Missing call to dput()",p1)
  55. cocci.print_secs("",p2)
  56. @depends on patch@
  57. local idexpression struct dentry *r.dent;
  58. position r.p2;
  59. @@
  60. (
  61. + dput(dent);
  62. return @p2 ...;
  63. |
  64. + dput(dent);
  65. dent@p2 = ...;
  66. )
  67. @script:python depends on report@
  68. p1 << r.p1;
  69. p2 << r.p2;
  70. @@
  71. msg = "Missing call to dput() at line %s."
  72. coccilib.report.print_report(p1[0], msg % (p2[0].line))