mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2025-01-07 22:34:18 +08:00
HID: hidraw: improve error handling in hidraw_init()
Several improvements in error handling: - do not report success if alloc_chrdev_region() failed - check for error code of cdev_add() - use unregister_chrdev_region() instead of unregister_chrdev() if class_create() failed Found by Linux Driver Verification project (linuxtesting.org). Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
This commit is contained in:
parent
2843b673d0
commit
bcb4a75bde
@ -559,21 +559,28 @@ int __init hidraw_init(void)
|
|||||||
|
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
pr_warn("can't get major number\n");
|
pr_warn("can't get major number\n");
|
||||||
result = 0;
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
hidraw_class = class_create(THIS_MODULE, "hidraw");
|
hidraw_class = class_create(THIS_MODULE, "hidraw");
|
||||||
if (IS_ERR(hidraw_class)) {
|
if (IS_ERR(hidraw_class)) {
|
||||||
result = PTR_ERR(hidraw_class);
|
result = PTR_ERR(hidraw_class);
|
||||||
unregister_chrdev(hidraw_major, "hidraw");
|
goto error_cdev;
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cdev_init(&hidraw_cdev, &hidraw_ops);
|
cdev_init(&hidraw_cdev, &hidraw_ops);
|
||||||
cdev_add(&hidraw_cdev, dev_id, HIDRAW_MAX_DEVICES);
|
result = cdev_add(&hidraw_cdev, dev_id, HIDRAW_MAX_DEVICES);
|
||||||
|
if (result < 0)
|
||||||
|
goto error_class;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
|
error_class:
|
||||||
|
class_destroy(hidraw_class);
|
||||||
|
error_cdev:
|
||||||
|
unregister_chrdev_region(dev_id, HIDRAW_MAX_DEVICES);
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hidraw_exit(void)
|
void hidraw_exit(void)
|
||||||
|
Loading…
Reference in New Issue
Block a user