device_attr_show.cocci 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. ///
  3. /// From Documentation/filesystems/sysfs.rst:
  4. /// show() should only use sysfs_emit() or sysfs_emit_at() when formatting
  5. /// the value to be returned to user space.
  6. ///
  7. // Confidence: High
  8. // Copyright: (C) 2020 Denis Efremov ISPRAS
  9. // Options: --no-includes --include-headers
  10. //
  11. virtual report
  12. virtual org
  13. virtual context
  14. virtual patch
  15. @r depends on !patch@
  16. identifier show, dev, attr, buf;
  17. position p;
  18. @@
  19. ssize_t show(struct device *dev, struct device_attribute *attr, char *buf)
  20. {
  21. <...
  22. * return snprintf@p(...);
  23. ...>
  24. }
  25. @rp depends on patch@
  26. identifier show, dev, attr, buf;
  27. expression BUF, SZ, FORMAT;
  28. @@
  29. ssize_t show(struct device *dev, struct device_attribute *attr, char *buf)
  30. {
  31. <...
  32. return
  33. - snprintf(BUF, SZ, FORMAT
  34. + sysfs_emit(BUF, FORMAT
  35. ,...);
  36. ...>
  37. }
  38. @script: python depends on report@
  39. p << r.p;
  40. @@
  41. coccilib.report.print_report(p[0], "WARNING: please use sysfs_emit or sysfs_emit_at")
  42. @script: python depends on org@
  43. p << r.p;
  44. @@
  45. coccilib.org.print_todo(p[0], "WARNING: please use sysfs_emit or sysfs_emit_at")