3.4-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Alexey Khoroshilov <[email protected]>

commit bcb4a75bde3821cecb17a71d287abfd6ef9bd68d upstream.

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 <[email protected]>
Signed-off-by: Jiri Kosina <[email protected]>
Signed-off-by: Ben Hutchings <[email protected]>
Cc: Yijing Wang <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>

---
 drivers/hid/hidraw.c |   15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

--- a/drivers/hid/hidraw.c
+++ b/drivers/hid/hidraw.c
@@ -559,21 +559,28 @@ int __init hidraw_init(void)
 
        if (result < 0) {
                pr_warn("can't get major number\n");
-               result = 0;
                goto out;
        }
 
        hidraw_class = class_create(THIS_MODULE, "hidraw");
        if (IS_ERR(hidraw_class)) {
                result = PTR_ERR(hidraw_class);
-               unregister_chrdev(hidraw_major, "hidraw");
-               goto out;
+               goto error_cdev;
        }
 
         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:
        return result;
+
+error_class:
+       class_destroy(hidraw_class);
+error_cdev:
+       unregister_chrdev_region(dev_id, HIDRAW_MAX_DEVICES);
+       goto out;
 }
 
 void hidraw_exit(void)


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to