d_find_alias.cocci 1.3 KB

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