[PATCH] Return better error codes if drivers/char/raw.c module init fails
Currently this module just returns 1 if anything on module init fails. Store the error code of the different function calls and return their error on problems. Signed-off-by: Rolf Eike Beer <eike-kernel@sf-tec.de> Cc: Greg KH <greg@kroah.com> Signed-off-by: Andrew Morton <akpm@osdl.org> [ Fixed to not unregister twice on error ] Signed-off-by: Linus Torvalds <torvalds@osdl.org>
This commit is contained in:
parent
416bc51292
commit
3e26a423e7
1 changed files with 11 additions and 8 deletions
|
@ -288,31 +288,34 @@ static struct cdev raw_cdev = {
|
||||||
static int __init raw_init(void)
|
static int __init raw_init(void)
|
||||||
{
|
{
|
||||||
dev_t dev = MKDEV(RAW_MAJOR, 0);
|
dev_t dev = MKDEV(RAW_MAJOR, 0);
|
||||||
|
int ret;
|
||||||
|
|
||||||
if (register_chrdev_region(dev, MAX_RAW_MINORS, "raw"))
|
ret = register_chrdev_region(dev, MAX_RAW_MINORS, "raw");
|
||||||
|
if (ret)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
cdev_init(&raw_cdev, &raw_fops);
|
cdev_init(&raw_cdev, &raw_fops);
|
||||||
if (cdev_add(&raw_cdev, dev, MAX_RAW_MINORS)) {
|
ret = cdev_add(&raw_cdev, dev, MAX_RAW_MINORS);
|
||||||
|
if (ret) {
|
||||||
kobject_put(&raw_cdev.kobj);
|
kobject_put(&raw_cdev.kobj);
|
||||||
unregister_chrdev_region(dev, MAX_RAW_MINORS);
|
goto error_region;
|
||||||
goto error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
raw_class = class_create(THIS_MODULE, "raw");
|
raw_class = class_create(THIS_MODULE, "raw");
|
||||||
if (IS_ERR(raw_class)) {
|
if (IS_ERR(raw_class)) {
|
||||||
printk(KERN_ERR "Error creating raw class.\n");
|
printk(KERN_ERR "Error creating raw class.\n");
|
||||||
cdev_del(&raw_cdev);
|
cdev_del(&raw_cdev);
|
||||||
unregister_chrdev_region(dev, MAX_RAW_MINORS);
|
ret = PTR_ERR(raw_class);
|
||||||
goto error;
|
goto error_region;
|
||||||
}
|
}
|
||||||
class_device_create(raw_class, NULL, MKDEV(RAW_MAJOR, 0), NULL, "rawctl");
|
class_device_create(raw_class, NULL, MKDEV(RAW_MAJOR, 0), NULL, "rawctl");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
error_region:
|
||||||
|
unregister_chrdev_region(dev, MAX_RAW_MINORS);
|
||||||
error:
|
error:
|
||||||
printk(KERN_ERR "error register raw device\n");
|
return ret;
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __exit raw_exit(void)
|
static void __exit raw_exit(void)
|
||||||
|
|
Loading…
Add table
Reference in a new issue