diff options
author | Dan Carpenter <dan.carpenter@oracle.com> | 2014-11-13 01:20:59 -0500 |
---|---|---|
committer | Felipe Balbi <balbi@ti.com> | 2014-11-18 09:47:44 -0500 |
commit | 0448d38c1e8cd64fb2fa88f44cbc7c3dcf75ed6c (patch) | |
tree | 394b9a301440c096215d0ae053943ce7dd1a40c0 /drivers/usb | |
parent | 828f6148e89ec051c2540400773655c0174ccaa3 (diff) |
usb: gadget: f_hid: fix error handling in ghid_setup()
There were a two issues here.
1) We returned PTR_ERR(NULL) which means success if class_create()
failed.
2) If alloc_chrdev_region() failed then we should clean up before
returning.
Also kernel style is to have "error handling" as opposed to "success
handling". In the original code checking for "if (!status) " is
confusing and this bad style is what lead to bug #2.
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Diffstat (limited to 'drivers/usb')
-rw-r--r-- | drivers/usb/gadget/function/f_hid.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/drivers/usb/gadget/function/f_hid.c b/drivers/usb/gadget/function/f_hid.c index f0545f801c9d..488ac66aae9e 100644 --- a/drivers/usb/gadget/function/f_hid.c +++ b/drivers/usb/gadget/function/f_hid.c | |||
@@ -972,17 +972,22 @@ int ghid_setup(struct usb_gadget *g, int count) | |||
972 | 972 | ||
973 | hidg_class = class_create(THIS_MODULE, "hidg"); | 973 | hidg_class = class_create(THIS_MODULE, "hidg"); |
974 | if (IS_ERR(hidg_class)) { | 974 | if (IS_ERR(hidg_class)) { |
975 | status = PTR_ERR(hidg_class); | ||
975 | hidg_class = NULL; | 976 | hidg_class = NULL; |
976 | return PTR_ERR(hidg_class); | 977 | return status; |
977 | } | 978 | } |
978 | 979 | ||
979 | status = alloc_chrdev_region(&dev, 0, count, "hidg"); | 980 | status = alloc_chrdev_region(&dev, 0, count, "hidg"); |
980 | if (!status) { | 981 | if (status) { |
981 | major = MAJOR(dev); | 982 | class_destroy(hidg_class); |
982 | minors = count; | 983 | hidg_class = NULL; |
984 | return status; | ||
983 | } | 985 | } |
984 | 986 | ||
985 | return status; | 987 | major = MAJOR(dev); |
988 | minors = count; | ||
989 | |||
990 | return 0; | ||
986 | } | 991 | } |
987 | 992 | ||
988 | void ghid_cleanup(void) | 993 | void ghid_cleanup(void) |