usb: gadget: f_hid: check return value of device_create
authorAndrzej Pietrasiewicz <andrzej.p@samsung.com>
Thu, 6 Nov 2014 10:11:57 +0000 (11:11 +0100)
committerFelipe Balbi <balbi@ti.com>
Thu, 6 Nov 2014 22:18:17 +0000 (16:18 -0600)
device_create() might fail, so check its return value and react
appropriately.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
drivers/usb/gadget/function/f_hid.c

index f3b3e19281eae72b86e7f0b37ce0fc7ed00618f0..ad538811c48b8fa350c48af0fb5d157a8286b628 100644 (file)
@@ -556,6 +556,7 @@ static int __init hidg_bind(struct usb_configuration *c, struct usb_function *f)
 {
        struct usb_ep           *ep;
        struct f_hidg           *hidg = func_to_hidg(f);
+       struct device           *device;
        int                     status;
        dev_t                   dev;
 
@@ -623,10 +624,16 @@ static int __init hidg_bind(struct usb_configuration *c, struct usb_function *f)
        if (status)
                goto fail_free_descs;
 
-       device_create(hidg_class, NULL, dev, NULL, "%s%d", "hidg", hidg->minor);
+       device = device_create(hidg_class, NULL, dev, NULL,
+                              "%s%d", "hidg", hidg->minor);
+       if (IS_ERR(device)) {
+               status = PTR_ERR(device);
+               goto del;
+       }
 
        return 0;
-
+del:
+       cdev_del(&hidg->cdev);
 fail_free_descs:
        usb_free_all_descriptors(f);
 fail: