Commit 125178d1 authored by Ian Abbott's avatar Ian Abbott Committed by Greg Kroah-Hartman

staging: comedi: use centralized error clean-up in comedi_init()

Centralize the "clean-up on error" handling in `comedi_init()` using
`goto` statements.  Also change some of the explicit `-EIO` return
values to the error return values from the failing functions as there is
no good reason to use `-EIO` explicitly.
Signed-off-by: default avatarIan Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent a9332e9a
...@@ -2881,29 +2881,25 @@ static int __init comedi_init(void) ...@@ -2881,29 +2881,25 @@ static int __init comedi_init(void)
retval = register_chrdev_region(MKDEV(COMEDI_MAJOR, 0), retval = register_chrdev_region(MKDEV(COMEDI_MAJOR, 0),
COMEDI_NUM_MINORS, "comedi"); COMEDI_NUM_MINORS, "comedi");
if (retval) if (retval)
return -EIO; return retval;
cdev_init(&comedi_cdev, &comedi_fops); cdev_init(&comedi_cdev, &comedi_fops);
comedi_cdev.owner = THIS_MODULE; comedi_cdev.owner = THIS_MODULE;
retval = kobject_set_name(&comedi_cdev.kobj, "comedi"); retval = kobject_set_name(&comedi_cdev.kobj, "comedi");
if (retval) { if (retval)
unregister_chrdev_region(MKDEV(COMEDI_MAJOR, 0), goto out_unregister_chrdev_region;
COMEDI_NUM_MINORS);
return retval; retval = cdev_add(&comedi_cdev, MKDEV(COMEDI_MAJOR, 0),
} COMEDI_NUM_MINORS);
if (retval)
goto out_unregister_chrdev_region;
if (cdev_add(&comedi_cdev, MKDEV(COMEDI_MAJOR, 0), COMEDI_NUM_MINORS)) {
unregister_chrdev_region(MKDEV(COMEDI_MAJOR, 0),
COMEDI_NUM_MINORS);
return -EIO;
}
comedi_class = class_create(THIS_MODULE, "comedi"); comedi_class = class_create(THIS_MODULE, "comedi");
if (IS_ERR(comedi_class)) { if (IS_ERR(comedi_class)) {
retval = PTR_ERR(comedi_class);
pr_err("failed to create class\n"); pr_err("failed to create class\n");
cdev_del(&comedi_cdev); goto out_cdev_del;
unregister_chrdev_region(MKDEV(COMEDI_MAJOR, 0),
COMEDI_NUM_MINORS);
return PTR_ERR(comedi_class);
} }
comedi_class->dev_groups = comedi_dev_groups; comedi_class->dev_groups = comedi_dev_groups;
...@@ -2914,12 +2910,8 @@ static int __init comedi_init(void) ...@@ -2914,12 +2910,8 @@ static int __init comedi_init(void)
dev = comedi_alloc_board_minor(NULL); dev = comedi_alloc_board_minor(NULL);
if (IS_ERR(dev)) { if (IS_ERR(dev)) {
comedi_cleanup_board_minors(); retval = PTR_ERR(dev);
class_destroy(comedi_class); goto out_cleanup_board_minors;
cdev_del(&comedi_cdev);
unregister_chrdev_region(MKDEV(COMEDI_MAJOR, 0),
COMEDI_NUM_MINORS);
return PTR_ERR(dev);
} }
/* comedi_alloc_board_minor() locked the mutex */ /* comedi_alloc_board_minor() locked the mutex */
mutex_unlock(&dev->mutex); mutex_unlock(&dev->mutex);
...@@ -2929,6 +2921,15 @@ static int __init comedi_init(void) ...@@ -2929,6 +2921,15 @@ static int __init comedi_init(void)
comedi_proc_init(); comedi_proc_init();
return 0; return 0;
out_cleanup_board_minors:
comedi_cleanup_board_minors();
class_destroy(comedi_class);
out_cdev_del:
cdev_del(&comedi_cdev);
out_unregister_chrdev_region:
unregister_chrdev_region(MKDEV(COMEDI_MAJOR, 0), COMEDI_NUM_MINORS);
return retval;
} }
module_init(comedi_init); module_init(comedi_init);
......
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