summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohan Hovold <johan@kernel.org>2017-03-17 11:35:43 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-03-23 13:54:03 +0100
commitaac96ef9ed3aba10d97cbc5afaf79365701a2f14 (patch)
treeb565f6fb8f7c68b5c154c3127b5f7322671d5160
parent9b181166f17534a82b4b628b13e524a893715dfc (diff)
USB: usblcd: refactor endpoint retrieval
Use the new endpoint helpers to lookup the required bulk-in and bulk-out endpoints. Signed-off-by: Johan Hovold <johan@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/usb/misc/usblcd.c47
1 files changed, 18 insertions, 29 deletions
diff --git a/drivers/usb/misc/usblcd.c b/drivers/usb/misc/usblcd.c
index 9f48419abc46..0f5ad896c7e3 100644
--- a/drivers/usb/misc/usblcd.c
+++ b/drivers/usb/misc/usblcd.c
@@ -313,16 +313,15 @@ static int lcd_probe(struct usb_interface *interface,
const struct usb_device_id *id)
{
struct usb_lcd *dev = NULL;
- struct usb_host_interface *iface_desc;
- struct usb_endpoint_descriptor *endpoint;
- size_t buffer_size;
+ struct usb_endpoint_descriptor *bulk_in, *bulk_out;
int i;
- int retval = -ENOMEM;
+ int retval;
/* allocate memory for our device state and initialize it */
dev = kzalloc(sizeof(*dev), GFP_KERNEL);
if (!dev)
- goto error;
+ return -ENOMEM;
+
kref_init(&dev->kref);
sema_init(&dev->limit_sem, USB_LCD_CONCURRENT_WRITES);
init_usb_anchor(&dev->submitted);
@@ -338,33 +337,24 @@ static int lcd_probe(struct usb_interface *interface,
/* set up the endpoint information */
/* use only the first bulk-in and bulk-out endpoints */
- iface_desc = interface->cur_altsetting;
- for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
- endpoint = &iface_desc->endpoint[i].desc;
-
- if (!dev->bulk_in_endpointAddr &&
- usb_endpoint_is_bulk_in(endpoint)) {
- /* we found a bulk in endpoint */
- buffer_size = usb_endpoint_maxp(endpoint);
- dev->bulk_in_size = buffer_size;
- dev->bulk_in_endpointAddr = endpoint->bEndpointAddress;
- dev->bulk_in_buffer = kmalloc(buffer_size, GFP_KERNEL);
- if (!dev->bulk_in_buffer)
- goto error;
- }
-
- if (!dev->bulk_out_endpointAddr &&
- usb_endpoint_is_bulk_out(endpoint)) {
- /* we found a bulk out endpoint */
- dev->bulk_out_endpointAddr = endpoint->bEndpointAddress;
- }
- }
- if (!(dev->bulk_in_endpointAddr && dev->bulk_out_endpointAddr)) {
+ retval = usb_find_common_endpoints(interface->cur_altsetting,
+ &bulk_in, &bulk_out, NULL, NULL);
+ if (retval) {
dev_err(&interface->dev,
"Could not find both bulk-in and bulk-out endpoints\n");
goto error;
}
+ dev->bulk_in_size = usb_endpoint_maxp(bulk_in);
+ dev->bulk_in_endpointAddr = bulk_in->bEndpointAddress;
+ dev->bulk_in_buffer = kmalloc(dev->bulk_in_size, GFP_KERNEL);
+ if (!dev->bulk_in_buffer) {
+ retval = -ENOMEM;
+ goto error;
+ }
+
+ dev->bulk_out_endpointAddr = bulk_out->bEndpointAddress;
+
/* save our data pointer in this interface device */
usb_set_intfdata(interface, dev);
@@ -390,8 +380,7 @@ static int lcd_probe(struct usb_interface *interface,
return 0;
error:
- if (dev)
- kref_put(&dev->kref, lcd_delete);
+ kref_put(&dev->kref, lcd_delete);
return retval;
}