009-3-watchdog-Use-static-struct-class-watchdog_class-instead-of-pointer.patch 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. From 906d7a5cfeda508e7361f021605579a00cd82815 Mon Sep 17 00:00:00 2001
  2. From: Pratyush Anand <panand@redhat.com>
  3. Date: Thu, 17 Dec 2015 17:53:58 +0530
  4. Subject: watchdog: Use static struct class watchdog_class in stead of pointer
  5. We need few sysfs attributes to know different status of a watchdog device.
  6. To do that, we need to associate .dev_groups with watchdog_class. So
  7. convert it from pointer to static.
  8. Putting this static struct in watchdog_dev.c, so that static device
  9. attributes defined in that file can be attached to it.
  10. Signed-off-by: Pratyush Anand <panand@redhat.com>
  11. Suggested-by: Guenter Roeck <linux@roeck-us.net>
  12. Reviewed-by: Guenter Roeck <linux@roeck-us.net>
  13. Signed-off-by: Guenter Roeck <linux@roeck-us.net>
  14. Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
  15. ---
  16. drivers/watchdog/watchdog_core.c | 15 ++-------------
  17. drivers/watchdog/watchdog_core.h | 2 +-
  18. drivers/watchdog/watchdog_dev.c | 26 ++++++++++++++++++++++----
  19. 3 files changed, 25 insertions(+), 18 deletions(-)
  20. --- a/drivers/watchdog/watchdog_core.c
  21. +++ b/drivers/watchdog/watchdog_core.c
  22. @@ -370,19 +370,9 @@ static int __init watchdog_deferred_regi
  23. static int __init watchdog_init(void)
  24. {
  25. - int err;
  26. -
  27. - watchdog_class = class_create(THIS_MODULE, "watchdog");
  28. - if (IS_ERR(watchdog_class)) {
  29. - pr_err("couldn't create class\n");
  30. + watchdog_class = watchdog_dev_init();
  31. + if (IS_ERR(watchdog_class))
  32. return PTR_ERR(watchdog_class);
  33. - }
  34. -
  35. - err = watchdog_dev_init();
  36. - if (err < 0) {
  37. - class_destroy(watchdog_class);
  38. - return err;
  39. - }
  40. watchdog_deferred_registration();
  41. return 0;
  42. @@ -391,7 +381,6 @@ static int __init watchdog_init(void)
  43. static void __exit watchdog_exit(void)
  44. {
  45. watchdog_dev_exit();
  46. - class_destroy(watchdog_class);
  47. ida_destroy(&watchdog_ida);
  48. }
  49. --- a/drivers/watchdog/watchdog_core.h
  50. +++ b/drivers/watchdog/watchdog_core.h
  51. @@ -33,5 +33,5 @@
  52. */
  53. extern int watchdog_dev_register(struct watchdog_device *);
  54. extern int watchdog_dev_unregister(struct watchdog_device *);
  55. -extern int __init watchdog_dev_init(void);
  56. +extern struct class * __init watchdog_dev_init(void);
  57. extern void __exit watchdog_dev_exit(void);
  58. --- a/drivers/watchdog/watchdog_dev.c
  59. +++ b/drivers/watchdog/watchdog_dev.c
  60. @@ -581,18 +581,35 @@ int watchdog_dev_unregister(struct watch
  61. return 0;
  62. }
  63. +static struct class watchdog_class = {
  64. + .name = "watchdog",
  65. + .owner = THIS_MODULE,
  66. +};
  67. +
  68. /*
  69. * watchdog_dev_init: init dev part of watchdog core
  70. *
  71. * Allocate a range of chardev nodes to use for watchdog devices
  72. */
  73. -int __init watchdog_dev_init(void)
  74. +struct class * __init watchdog_dev_init(void)
  75. {
  76. - int err = alloc_chrdev_region(&watchdog_devt, 0, MAX_DOGS, "watchdog");
  77. - if (err < 0)
  78. + int err;
  79. +
  80. + err = class_register(&watchdog_class);
  81. + if (err < 0) {
  82. + pr_err("couldn't register class\n");
  83. + return ERR_PTR(err);
  84. + }
  85. +
  86. + err = alloc_chrdev_region(&watchdog_devt, 0, MAX_DOGS, "watchdog");
  87. + if (err < 0) {
  88. pr_err("watchdog: unable to allocate char dev region\n");
  89. - return err;
  90. + class_unregister(&watchdog_class);
  91. + return ERR_PTR(err);
  92. + }
  93. +
  94. + return &watchdog_class;
  95. }
  96. /*
  97. @@ -604,4 +621,5 @@ int __init watchdog_dev_init(void)
  98. void __exit watchdog_dev_exit(void)
  99. {
  100. unregister_chrdev_region(watchdog_devt, MAX_DOGS);
  101. + class_unregister(&watchdog_class);
  102. }