USB: usb-skeleton: 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>
This commit is contained in:
parent
499841e678
commit
af59f8955f
@ -491,16 +491,14 @@ static int skel_probe(struct usb_interface *interface,
|
|||||||
const struct usb_device_id *id)
|
const struct usb_device_id *id)
|
||||||
{
|
{
|
||||||
struct usb_skel *dev;
|
struct usb_skel *dev;
|
||||||
struct usb_host_interface *iface_desc;
|
struct usb_endpoint_descriptor *bulk_in, *bulk_out;
|
||||||
struct usb_endpoint_descriptor *endpoint;
|
int retval;
|
||||||
size_t buffer_size;
|
|
||||||
int i;
|
|
||||||
int retval = -ENOMEM;
|
|
||||||
|
|
||||||
/* allocate memory for our device state and initialize it */
|
/* allocate memory for our device state and initialize it */
|
||||||
dev = kzalloc(sizeof(*dev), GFP_KERNEL);
|
dev = kzalloc(sizeof(*dev), GFP_KERNEL);
|
||||||
if (!dev)
|
if (!dev)
|
||||||
goto error;
|
return -ENOMEM;
|
||||||
|
|
||||||
kref_init(&dev->kref);
|
kref_init(&dev->kref);
|
||||||
sema_init(&dev->limit_sem, WRITES_IN_FLIGHT);
|
sema_init(&dev->limit_sem, WRITES_IN_FLIGHT);
|
||||||
mutex_init(&dev->io_mutex);
|
mutex_init(&dev->io_mutex);
|
||||||
@ -513,36 +511,29 @@ static int skel_probe(struct usb_interface *interface,
|
|||||||
|
|
||||||
/* set up the endpoint information */
|
/* set up the endpoint information */
|
||||||
/* use only the first bulk-in and bulk-out endpoints */
|
/* use only the first bulk-in and bulk-out endpoints */
|
||||||
iface_desc = interface->cur_altsetting;
|
retval = usb_find_common_endpoints(interface->cur_altsetting,
|
||||||
for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
|
&bulk_in, &bulk_out, NULL, NULL);
|
||||||
endpoint = &iface_desc->endpoint[i].desc;
|
if (retval) {
|
||||||
|
|
||||||
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;
|
|
||||||
dev->bulk_in_urb = usb_alloc_urb(0, GFP_KERNEL);
|
|
||||||
if (!dev->bulk_in_urb)
|
|
||||||
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)) {
|
|
||||||
dev_err(&interface->dev,
|
dev_err(&interface->dev,
|
||||||
"Could not find both bulk-in and bulk-out endpoints\n");
|
"Could not find both bulk-in and bulk-out endpoints\n");
|
||||||
goto error;
|
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_in_urb = usb_alloc_urb(0, GFP_KERNEL);
|
||||||
|
if (!dev->bulk_in_urb) {
|
||||||
|
retval = -ENOMEM;
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
dev->bulk_out_endpointAddr = bulk_out->bEndpointAddress;
|
||||||
|
|
||||||
/* save our data pointer in this interface device */
|
/* save our data pointer in this interface device */
|
||||||
usb_set_intfdata(interface, dev);
|
usb_set_intfdata(interface, dev);
|
||||||
|
|
||||||
@ -563,9 +554,9 @@ static int skel_probe(struct usb_interface *interface,
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
if (dev)
|
/* this frees allocated memory */
|
||||||
/* this frees allocated memory */
|
kref_put(&dev->kref, skel_delete);
|
||||||
kref_put(&dev->kref, skel_delete);
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user