diff options
author | Andrzej Pietrasiewicz <andrzej.p@samsung.com> | 2015-03-03 12:52:09 +0300 |
---|---|---|
committer | Felipe Balbi <balbi@ti.com> | 2015-03-10 23:33:35 +0300 |
commit | 44b316525986252bb95d356419fc9e75f0532112 (patch) | |
tree | d7cebd8bc5131a390a584ef025ed23372091a9cb /drivers/usb/gadget/legacy/printer.c | |
parent | f5bda0034fba942adf5555246e248ddb66c76052 (diff) | |
download | linux-44b316525986252bb95d356419fc9e75f0532112.tar.xz |
usb: gadget: printer: add missing error handling
If cdev_add() in printer_bind_config() fails, care is taken to
reverse the effects of initializations completed until the fail
happens. But if printer_req_alloc() fails, it is just one of the
two lists that is cleaned up while the effects of cdev_add()
and device_create() are not reverted.
This patch changes error handling so that at least as much cleanup is done
as when a failure happens before printer_req_alloc() invocations.
Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Diffstat (limited to 'drivers/usb/gadget/legacy/printer.c')
-rw-r--r-- | drivers/usb/gadget/legacy/printer.c | 23 |
1 files changed, 5 insertions, 18 deletions
diff --git a/drivers/usb/gadget/legacy/printer.c b/drivers/usb/gadget/legacy/printer.c index eb02a6b8da08..bbcd6aa9abd1 100644 --- a/drivers/usb/gadget/legacy/printer.c +++ b/drivers/usb/gadget/legacy/printer.c @@ -1249,31 +1249,18 @@ static int __init printer_bind_config(struct usb_configuration *c) dev->current_rx_bytes = 0; dev->current_rx_buf = NULL; + status = -ENOMEM; for (i = 0; i < QLEN; i++) { req = printer_req_alloc(dev->in_ep, USB_BUFSIZE, GFP_KERNEL); - if (!req) { - while (!list_empty(&dev->tx_reqs)) { - req = container_of(dev->tx_reqs.next, - struct usb_request, list); - list_del(&req->list); - printer_req_free(dev->in_ep, req); - } - return -ENOMEM; - } + if (!req) + goto fail; list_add(&req->list, &dev->tx_reqs); } for (i = 0; i < QLEN; i++) { req = printer_req_alloc(dev->out_ep, USB_BUFSIZE, GFP_KERNEL); - if (!req) { - while (!list_empty(&dev->rx_reqs)) { - req = container_of(dev->rx_reqs.next, - struct usb_request, list); - list_del(&req->list); - printer_req_free(dev->out_ep, req); - } - return -ENOMEM; - } + if (!req) + goto fail; list_add(&req->list, &dev->rx_reqs); } |