1906a1f4e5cfb172325a90303e485a07243cf464
[openwrt/staging/florian.git] /
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
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.
11
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>
17 ---
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(-)
22
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
26
27 static int __init watchdog_init(void)
28 {
29 - int err;
30 -
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);
37 - }
38 -
39 - err = watchdog_dev_init();
40 - if (err < 0) {
41 - class_destroy(watchdog_class);
42 - return err;
43 - }
44
45 watchdog_deferred_registration();
46 return 0;
47 @@ -391,7 +381,6 @@ static int __init watchdog_init(void)
48 static void __exit watchdog_exit(void)
49 {
50 watchdog_dev_exit();
51 - class_destroy(watchdog_class);
52 ida_destroy(&watchdog_ida);
53 }
54
55 --- a/drivers/watchdog/watchdog_core.h
56 +++ b/drivers/watchdog/watchdog_core.h
57 @@ -33,5 +33,5 @@
58 */
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
67 return 0;
68 }
69
70 +static struct class watchdog_class = {
71 + .name = "watchdog",
72 + .owner = THIS_MODULE,
73 +};
74 +
75 /*
76 * watchdog_dev_init: init dev part of watchdog core
77 *
78 * Allocate a range of chardev nodes to use for watchdog devices
79 */
80
81 -int __init watchdog_dev_init(void)
82 +struct class * __init watchdog_dev_init(void)
83 {
84 - int err = alloc_chrdev_region(&watchdog_devt, 0, MAX_DOGS, "watchdog");
85 - if (err < 0)
86 + int err;
87 +
88 + err = class_register(&watchdog_class);
89 + if (err < 0) {
90 + pr_err("couldn't register class\n");
91 + return ERR_PTR(err);
92 + }
93 +
94 + err = alloc_chrdev_region(&watchdog_devt, 0, MAX_DOGS, "watchdog");
95 + if (err < 0) {
96 pr_err("watchdog: unable to allocate char dev region\n");
97 - return err;
98 + class_unregister(&watchdog_class);
99 + return ERR_PTR(err);
100 + }
101 +
102 + return &watchdog_class;
103 }
104
105 /*
106 @@ -604,4 +621,5 @@ int __init watchdog_dev_init(void)
107 void __exit watchdog_dev_exit(void)
108 {
109 unregister_chrdev_region(watchdog_devt, MAX_DOGS);
110 + class_unregister(&watchdog_class);
111 }