debugfs_simple_attr.cocci 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // SPDX-License-Identifier: GPL-2.0
  2. /// Use DEFINE_DEBUGFS_ATTRIBUTE rather than DEFINE_SIMPLE_ATTRIBUTE
  3. /// for debugfs files.
  4. ///
  5. //# Rationale: DEFINE_SIMPLE_ATTRIBUTE + debugfs_create_file()
  6. //# imposes some significant overhead as compared to
  7. //# DEFINE_DEBUGFS_ATTRIBUTE + debugfs_create_file_unsafe().
  8. //
  9. // Copyright (C): 2016 Nicolai Stange
  10. // Options: --no-includes
  11. //
  12. virtual context
  13. virtual patch
  14. virtual org
  15. virtual report
  16. @dsa@
  17. declarer name DEFINE_SIMPLE_ATTRIBUTE;
  18. identifier dsa_fops;
  19. expression dsa_get, dsa_set, dsa_fmt;
  20. position p;
  21. @@
  22. DEFINE_SIMPLE_ATTRIBUTE@p(dsa_fops, dsa_get, dsa_set, dsa_fmt);
  23. @dcf@
  24. expression name, mode, parent, data;
  25. identifier dsa.dsa_fops;
  26. @@
  27. debugfs_create_file(name, mode, parent, data, &dsa_fops)
  28. @context_dsa depends on context && dcf@
  29. declarer name DEFINE_DEBUGFS_ATTRIBUTE;
  30. identifier dsa.dsa_fops;
  31. expression dsa.dsa_get, dsa.dsa_set, dsa.dsa_fmt;
  32. @@
  33. * DEFINE_SIMPLE_ATTRIBUTE(dsa_fops, dsa_get, dsa_set, dsa_fmt);
  34. @patch_dcf depends on patch expression@
  35. expression name, mode, parent, data;
  36. identifier dsa.dsa_fops;
  37. @@
  38. - debugfs_create_file(name, mode, parent, data, &dsa_fops)
  39. + debugfs_create_file_unsafe(name, mode, parent, data, &dsa_fops)
  40. @patch_dsa depends on patch_dcf && patch@
  41. identifier dsa.dsa_fops;
  42. expression dsa.dsa_get, dsa.dsa_set, dsa.dsa_fmt;
  43. @@
  44. - DEFINE_SIMPLE_ATTRIBUTE(dsa_fops, dsa_get, dsa_set, dsa_fmt);
  45. + DEFINE_DEBUGFS_ATTRIBUTE(dsa_fops, dsa_get, dsa_set, dsa_fmt);
  46. @script:python depends on org && dcf@
  47. fops << dsa.dsa_fops;
  48. p << dsa.p;
  49. @@
  50. msg="%s should be defined with DEFINE_DEBUGFS_ATTRIBUTE" % (fops)
  51. coccilib.org.print_todo(p[0], msg)
  52. @script:python depends on report && dcf@
  53. fops << dsa.dsa_fops;
  54. p << dsa.p;
  55. @@
  56. msg="WARNING: %s should be defined with DEFINE_DEBUGFS_ATTRIBUTE" % (fops)
  57. coccilib.report.print_report(p[0], msg)