put_device.cocci 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // SPDX-License-Identifier: GPL-2.0
  2. /// Find missing put_device for every of_find_device_by_node.
  3. ///
  4. // Confidence: Moderate
  5. // Copyright: (C) 2018-2019 Wen Yang, ZTE.
  6. // Comments:
  7. // Options: --no-includes --include-headers
  8. virtual report
  9. virtual org
  10. @search exists@
  11. local idexpression id;
  12. expression x,e,e1;
  13. position p1,p2;
  14. type T,T1,T2,T3;
  15. @@
  16. id = of_find_device_by_node@p1(x)
  17. ... when != e = id
  18. if (id == NULL || ...) { ... return ...; }
  19. ... when != put_device(&id->dev)
  20. when != platform_device_put(id)
  21. when != if (id) { ... put_device(&id->dev) ... }
  22. when != e1 = (T)id
  23. when != e1 = (T)(&id->dev)
  24. when != e1 = get_device(&id->dev)
  25. when != e1 = (T1)platform_get_drvdata(id)
  26. (
  27. return
  28. ( id
  29. | (T2)dev_get_drvdata(&id->dev)
  30. | (T3)platform_get_drvdata(id)
  31. | &id->dev
  32. );
  33. | return@p2 ...;
  34. )
  35. @script:python depends on report@
  36. p1 << search.p1;
  37. p2 << search.p2;
  38. @@
  39. coccilib.report.print_report(p2[0],
  40. "ERROR: missing put_device; call of_find_device_by_node on line "
  41. + p1[0].line
  42. + ", but without a corresponding object release within this function.")
  43. @script:python depends on org@
  44. p1 << search.p1;
  45. p2 << search.p2;
  46. @@
  47. cocci.print_main("of_find_device_by_node", p1)
  48. cocci.print_secs("needed put_device", p2)