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
6 We need few sysfs attributes to know different status of a watchdog device.
7 To do that, we need to associate .dev_groups with watchdog_class. So
8 convert it from pointer to static.
9 Putting this static struct in watchdog_dev.c, so that static device
10 attributes defined in that file can be attached to it.
12 Signed-off-by: Pratyush Anand <panand@redhat.com>
13 Suggested-by: Guenter Roeck <linux@roeck-us.net>
14 Reviewed-by: Guenter Roeck <linux@roeck-us.net>
15 Signed-off-by: Guenter Roeck <linux@roeck-us.net>
16 Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
18 drivers/watchdog/watchdog_core.c | 15 ++-------------
19 drivers/watchdog/watchdog_core.h | 2 +-
20 drivers/watchdog/watchdog_dev.c | 26 ++++++++++++++++++++++----
21 3 files changed, 25 insertions(+), 18 deletions(-)
23 --- a/drivers/watchdog/watchdog_core.c
24 +++ b/drivers/watchdog/watchdog_core.c
25 @@ -370,19 +370,9 @@ static int __init watchdog_deferred_regi
27 static int __init watchdog_init(void)
31 - watchdog_class = class_create(THIS_MODULE, "watchdog");
32 - if (IS_ERR(watchdog_class)) {
33 - pr_err("couldn't create class\n");
34 + watchdog_class = watchdog_dev_init();
35 + if (IS_ERR(watchdog_class))
36 return PTR_ERR(watchdog_class);
39 - err = watchdog_dev_init();
41 - class_destroy(watchdog_class);
45 watchdog_deferred_registration();
47 @@ -391,7 +381,6 @@ static int __init watchdog_init(void)
48 static void __exit watchdog_exit(void)
51 - class_destroy(watchdog_class);
52 ida_destroy(&watchdog_ida);
55 --- a/drivers/watchdog/watchdog_core.h
56 +++ b/drivers/watchdog/watchdog_core.h
59 extern int watchdog_dev_register(struct watchdog_device *);
60 extern int watchdog_dev_unregister(struct watchdog_device *);
61 -extern int __init watchdog_dev_init(void);
62 +extern struct class * __init watchdog_dev_init(void);
63 extern void __exit watchdog_dev_exit(void);
64 --- a/drivers/watchdog/watchdog_dev.c
65 +++ b/drivers/watchdog/watchdog_dev.c
66 @@ -581,18 +581,35 @@ int watchdog_dev_unregister(struct watch
70 +static struct class watchdog_class = {
72 + .owner = THIS_MODULE,
76 * watchdog_dev_init: init dev part of watchdog core
78 * Allocate a range of chardev nodes to use for watchdog devices
81 -int __init watchdog_dev_init(void)
82 +struct class * __init watchdog_dev_init(void)
84 - int err = alloc_chrdev_region(&watchdog_devt, 0, MAX_DOGS, "watchdog");
88 + err = class_register(&watchdog_class);
90 + pr_err("couldn't register class\n");
91 + return ERR_PTR(err);
94 + err = alloc_chrdev_region(&watchdog_devt, 0, MAX_DOGS, "watchdog");
96 pr_err("watchdog: unable to allocate char dev region\n");
98 + class_unregister(&watchdog_class);
99 + return ERR_PTR(err);
102 + return &watchdog_class;
106 @@ -604,4 +621,5 @@ int __init watchdog_dev_init(void)
107 void __exit watchdog_dev_exit(void)
109 unregister_chrdev_region(watchdog_devt, MAX_DOGS);
110 + class_unregister(&watchdog_class);