diff options
| author | Alexey Khoroshilov <khoroshilov@ispras.ru> | 2012-08-15 15:31:45 -0400 |
|---|---|---|
| committer | Jiri Kosina <jkosina@suse.cz> | 2012-08-15 15:37:09 -0400 |
| commit | bcb4a75bde3821cecb17a71d287abfd6ef9bd68d (patch) | |
| tree | ac7c344f803ee7ce31f04ffb94ca133a02ea59eb /drivers/hid | |
| parent | 2843b673d03421e0e73cf061820d1db328f7c8eb (diff) | |
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>
Diffstat (limited to 'drivers/hid')
| -rw-r--r-- | drivers/hid/hidraw.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/drivers/hid/hidraw.c b/drivers/hid/hidraw.c index 3b6f7bf5a77e..7c47fc3f7b2b 100644 --- a/drivers/hid/hidraw.c +++ b/drivers/hid/hidraw.c | |||
| @@ -559,21 +559,28 @@ int __init hidraw_init(void) | |||
| 559 | 559 | ||
| 560 | if (result < 0) { | 560 | if (result < 0) { |
| 561 | pr_warn("can't get major number\n"); | 561 | pr_warn("can't get major number\n"); |
| 562 | result = 0; | ||
| 563 | goto out; | 562 | goto out; |
| 564 | } | 563 | } |
| 565 | 564 | ||
| 566 | hidraw_class = class_create(THIS_MODULE, "hidraw"); | 565 | hidraw_class = class_create(THIS_MODULE, "hidraw"); |
| 567 | if (IS_ERR(hidraw_class)) { | 566 | if (IS_ERR(hidraw_class)) { |
| 568 | result = PTR_ERR(hidraw_class); | 567 | result = PTR_ERR(hidraw_class); |
| 569 | unregister_chrdev(hidraw_major, "hidraw"); | 568 | goto error_cdev; |
| 570 | goto out; | ||
| 571 | } | 569 | } |
| 572 | 570 | ||
| 573 | cdev_init(&hidraw_cdev, &hidraw_ops); | 571 | cdev_init(&hidraw_cdev, &hidraw_ops); |
| 574 | cdev_add(&hidraw_cdev, dev_id, HIDRAW_MAX_DEVICES); | 572 | result = cdev_add(&hidraw_cdev, dev_id, HIDRAW_MAX_DEVICES); |
| 573 | if (result < 0) | ||
| 574 | goto error_class; | ||
| 575 | |||
| 575 | out: | 576 | out: |
| 576 | return result; | 577 | return result; |
| 578 | |||
| 579 | error_class: | ||
| 580 | class_destroy(hidraw_class); | ||
| 581 | error_cdev: | ||
| 582 | unregister_chrdev_region(dev_id, HIDRAW_MAX_DEVICES); | ||
| 583 | goto out; | ||
| 577 | } | 584 | } |
| 578 | 585 | ||
| 579 | void hidraw_exit(void) | 586 | void hidraw_exit(void) |
