Commit 906d7a5c authored by Pratyush Anand's avatar Pratyush Anand Committed by Wim Van Sebroeck

watchdog: Use static struct class watchdog_class in stead of pointer

We need few sysfs attributes to know different status of a watchdog device.
To do that, we need to associate .dev_groups with watchdog_class. So
convert it from pointer to static.
Putting this static struct in watchdog_dev.c, so that static device
attributes defined in that file can be attached to it.
Signed-off-by: default avatarPratyush Anand <panand@redhat.com>
Suggested-by: default avatarGuenter Roeck <linux@roeck-us.net>
Reviewed-by: default avatarGuenter Roeck <linux@roeck-us.net>
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
Signed-off-by: default avatarWim Van Sebroeck <wim@iguana.be>
parent d68106bb
...@@ -370,19 +370,9 @@ static int __init watchdog_deferred_registration(void) ...@@ -370,19 +370,9 @@ static int __init watchdog_deferred_registration(void)
static int __init watchdog_init(void) static int __init watchdog_init(void)
{ {
int err; watchdog_class = watchdog_dev_init();
if (IS_ERR(watchdog_class))
watchdog_class = class_create(THIS_MODULE, "watchdog");
if (IS_ERR(watchdog_class)) {
pr_err("couldn't create class\n");
return PTR_ERR(watchdog_class); return PTR_ERR(watchdog_class);
}
err = watchdog_dev_init();
if (err < 0) {
class_destroy(watchdog_class);
return err;
}
watchdog_deferred_registration(); watchdog_deferred_registration();
return 0; return 0;
...@@ -391,7 +381,6 @@ static int __init watchdog_init(void) ...@@ -391,7 +381,6 @@ static int __init watchdog_init(void)
static void __exit watchdog_exit(void) static void __exit watchdog_exit(void)
{ {
watchdog_dev_exit(); watchdog_dev_exit();
class_destroy(watchdog_class);
ida_destroy(&watchdog_ida); ida_destroy(&watchdog_ida);
} }
......
...@@ -33,5 +33,5 @@ ...@@ -33,5 +33,5 @@
*/ */
extern int watchdog_dev_register(struct watchdog_device *); extern int watchdog_dev_register(struct watchdog_device *);
extern int watchdog_dev_unregister(struct watchdog_device *); extern int watchdog_dev_unregister(struct watchdog_device *);
extern int __init watchdog_dev_init(void); extern struct class * __init watchdog_dev_init(void);
extern void __exit watchdog_dev_exit(void); extern void __exit watchdog_dev_exit(void);
...@@ -581,18 +581,35 @@ int watchdog_dev_unregister(struct watchdog_device *wdd) ...@@ -581,18 +581,35 @@ int watchdog_dev_unregister(struct watchdog_device *wdd)
return 0; return 0;
} }
static struct class watchdog_class = {
.name = "watchdog",
.owner = THIS_MODULE,
};
/* /*
* watchdog_dev_init: init dev part of watchdog core * watchdog_dev_init: init dev part of watchdog core
* *
* Allocate a range of chardev nodes to use for watchdog devices * Allocate a range of chardev nodes to use for watchdog devices
*/ */
int __init watchdog_dev_init(void) struct class * __init watchdog_dev_init(void)
{ {
int err = alloc_chrdev_region(&watchdog_devt, 0, MAX_DOGS, "watchdog"); int err;
if (err < 0)
err = class_register(&watchdog_class);
if (err < 0) {
pr_err("couldn't register class\n");
return ERR_PTR(err);
}
err = alloc_chrdev_region(&watchdog_devt, 0, MAX_DOGS, "watchdog");
if (err < 0) {
pr_err("watchdog: unable to allocate char dev region\n"); pr_err("watchdog: unable to allocate char dev region\n");
return err; class_unregister(&watchdog_class);
return ERR_PTR(err);
}
return &watchdog_class;
} }
/* /*
...@@ -604,4 +621,5 @@ int __init watchdog_dev_init(void) ...@@ -604,4 +621,5 @@ int __init watchdog_dev_init(void)
void __exit watchdog_dev_exit(void) void __exit watchdog_dev_exit(void)
{ {
unregister_chrdev_region(watchdog_devt, MAX_DOGS); unregister_chrdev_region(watchdog_devt, MAX_DOGS);
class_unregister(&watchdog_class);
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment