From 0ce68ce41779c353be780f635234a446ea30c49d Mon Sep 17 00:00:00 2001 From: Johan Hovold Date: Wed, 4 Nov 2015 18:55:14 +0100 Subject: [PATCH] greybus: es2: separate urb allocation and submission Refactor in-urb submission, and make sure to separate allocation and submission. Eventually we'll be submitting the urbs at cport enable rather than at probe, and this is also needed for the driver-model rework. Signed-off-by: Johan Hovold Signed-off-by: Greg Kroah-Hartman --- drivers/staging/greybus/es2.c | 41 +++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/drivers/staging/greybus/es2.c b/drivers/staging/greybus/es2.c index 4bb500f65873..156269645f46 100644 --- a/drivers/staging/greybus/es2.c +++ b/drivers/staging/greybus/es2.c @@ -209,6 +209,35 @@ static int unmap_cport(struct es2_ap_dev *es2, u16 cport_id) } #endif +static int es2_cport_in_enable(struct es2_ap_dev *es2, + struct es2_cport_in *cport_in) +{ + struct urb *urb; + int ret; + int i; + + for (i = 0; i < NUM_CPORT_IN_URB; ++i) { + urb = cport_in->urb[i]; + + ret = usb_submit_urb(urb, GFP_KERNEL); + if (ret) { + dev_err(&es2->usb_dev->dev, + "failed to submit in-urb: %d\n", ret); + goto err_kill_urbs; + } + } + + return 0; + +err_kill_urbs: + for (--i; i >= 0; --i) { + urb = cport_in->urb[i]; + usb_kill_urb(urb); + } + + return ret; +} + static struct urb *next_free_urb(struct es2_ap_dev *es2, gfp_t gfp_mask) { struct urb *urb = NULL; @@ -853,7 +882,7 @@ static int ap_probe(struct usb_interface *interface, goto error; } - /* Allocate buffers for our cport in messages and start them up */ + /* Allocate buffers for our cport in messages */ for (bulk_in = 0; bulk_in < NUM_BULKS; bulk_in++) { struct es2_cport_in *cport_in = &es2->cport_in[bulk_in]; @@ -875,9 +904,6 @@ static int ap_probe(struct usb_interface *interface, cport_in_callback, hd); cport_in->urb[i] = urb; cport_in->buffer[i] = buffer; - retval = usb_submit_urb(urb, GFP_KERNEL); - if (retval) - goto error; } } @@ -898,6 +924,13 @@ static int ap_probe(struct usb_interface *interface, (S_IWUSR | S_IRUGO), gb_debugfs_get(), es2, &apb_log_enable_fops); + + for (i = 0; i < NUM_BULKS; ++i) { + retval = es2_cport_in_enable(es2, &es2->cport_in[i]); + if (retval) + goto error; + } + return 0; error: ap_disconnect(interface);