USB: fix codingstyle issues in drivers/usb/core/message.c

Fixes a number of coding style issues in the message.c file.

Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
Greg Kroah-Hartman 2008-01-30 15:21:33 -08:00
parent 34bbe4c16c
commit 3e35bf39e0

View file

@ -74,7 +74,7 @@ out:
} }
/*-------------------------------------------------------------------*/ /*-------------------------------------------------------------------*/
// returns status (negative) or length (positive) /* returns status (negative) or length (positive) */
static int usb_internal_control_msg(struct usb_device *usb_dev, static int usb_internal_control_msg(struct usb_device *usb_dev,
unsigned int pipe, unsigned int pipe,
struct usb_ctrlrequest *cmd, struct usb_ctrlrequest *cmd,
@ -108,38 +108,42 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
* @index: USB message index value * @index: USB message index value
* @data: pointer to the data to send * @data: pointer to the data to send
* @size: length in bytes of the data to send * @size: length in bytes of the data to send
* @timeout: time in msecs to wait for the message to complete before * @timeout: time in msecs to wait for the message to complete before timing
* timing out (if 0 the wait is forever) * out (if 0 the wait is forever)
*
* Context: !in_interrupt () * Context: !in_interrupt ()
* *
* This function sends a simple control message to a specified endpoint * This function sends a simple control message to a specified endpoint and
* and waits for the message to complete, or timeout. * waits for the message to complete, or timeout.
* *
* If successful, it returns the number of bytes transferred, otherwise a negative error number. * If successful, it returns the number of bytes transferred, otherwise a
* negative error number.
* *
* Don't use this function from within an interrupt context, like a * Don't use this function from within an interrupt context, like a bottom half
* bottom half handler. If you need an asynchronous message, or need to send * handler. If you need an asynchronous message, or need to send a message
* a message from within interrupt context, use usb_submit_urb() * from within interrupt context, use usb_submit_urb().
* If a thread in your driver uses this call, make sure your disconnect() * If a thread in your driver uses this call, make sure your disconnect()
* method can wait for it to complete. Since you don't have a handle on * method can wait for it to complete. Since you don't have a handle on the
* the URB used, you can't cancel the request. * URB used, you can't cancel the request.
*/ */
int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request, __u8 requesttype, int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
__u16 value, __u16 index, void *data, __u16 size, int timeout) __u8 requesttype, __u16 value, __u16 index, void *data,
__u16 size, int timeout)
{ {
struct usb_ctrlrequest *dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_NOIO); struct usb_ctrlrequest *dr;
int ret; int ret;
dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_NOIO);
if (!dr) if (!dr)
return -ENOMEM; return -ENOMEM;
dr->bRequestType= requesttype; dr->bRequestType = requesttype;
dr->bRequest = request; dr->bRequest = request;
dr->wValue = cpu_to_le16p(&value); dr->wValue = cpu_to_le16p(&value);
dr->wIndex = cpu_to_le16p(&index); dr->wIndex = cpu_to_le16p(&index);
dr->wLength = cpu_to_le16p(&size); dr->wLength = cpu_to_le16p(&size);
//dbg("usb_control_msg"); /* dbg("usb_control_msg"); */
ret = usb_internal_control_msg(dev, pipe, dr, data, size, timeout); ret = usb_internal_control_msg(dev, pipe, dr, data, size, timeout);
@ -155,9 +159,11 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
* @pipe: endpoint "pipe" to send the message to * @pipe: endpoint "pipe" to send the message to
* @data: pointer to the data to send * @data: pointer to the data to send
* @len: length in bytes of the data to send * @len: length in bytes of the data to send
* @actual_length: pointer to a location to put the actual length transferred in bytes * @actual_length: pointer to a location to put the actual length transferred
* in bytes
* @timeout: time in msecs to wait for the message to complete before * @timeout: time in msecs to wait for the message to complete before
* timing out (if 0 the wait is forever) * timing out (if 0 the wait is forever)
*
* Context: !in_interrupt () * Context: !in_interrupt ()
* *
* This function sends a simple interrupt message to a specified endpoint and * This function sends a simple interrupt message to a specified endpoint and
@ -186,30 +192,30 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
* @pipe: endpoint "pipe" to send the message to * @pipe: endpoint "pipe" to send the message to
* @data: pointer to the data to send * @data: pointer to the data to send
* @len: length in bytes of the data to send * @len: length in bytes of the data to send
* @actual_length: pointer to a location to put the actual length transferred in bytes * @actual_length: pointer to a location to put the actual length transferred
* in bytes
* @timeout: time in msecs to wait for the message to complete before * @timeout: time in msecs to wait for the message to complete before
* timing out (if 0 the wait is forever) * timing out (if 0 the wait is forever)
*
* Context: !in_interrupt () * Context: !in_interrupt ()
* *
* This function sends a simple bulk message to a specified endpoint * This function sends a simple bulk message to a specified endpoint
* and waits for the message to complete, or timeout. * and waits for the message to complete, or timeout.
* *
* If successful, it returns 0, otherwise a negative error number. * If successful, it returns 0, otherwise a negative error number. The number
* The number of actual bytes transferred will be stored in the * of actual bytes transferred will be stored in the actual_length paramater.
* actual_length paramater.
* *
* Don't use this function from within an interrupt context, like a * Don't use this function from within an interrupt context, like a bottom half
* bottom half handler. If you need an asynchronous message, or need to * handler. If you need an asynchronous message, or need to send a message
* send a message from within interrupt context, use usb_submit_urb() * from within interrupt context, use usb_submit_urb() If a thread in your
* If a thread in your driver uses this call, make sure your disconnect() * driver uses this call, make sure your disconnect() method can wait for it to
* method can wait for it to complete. Since you don't have a handle on * complete. Since you don't have a handle on the URB used, you can't cancel
* the URB used, you can't cancel the request. * the request.
* *
* Because there is no usb_interrupt_msg() and no USBDEVFS_INTERRUPT * Because there is no usb_interrupt_msg() and no USBDEVFS_INTERRUPT ioctl,
* ioctl, users are forced to abuse this routine by using it to submit * users are forced to abuse this routine by using it to submit URBs for
* URBs for interrupt endpoints. We will take the liberty of creating * interrupt endpoints. We will take the liberty of creating an interrupt URB
* an interrupt URB (with the default interval) if the target is an * (with the default interval) if the target is an interrupt endpoint.
* interrupt endpoint.
*/ */
int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe, int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
void *data, int len, int *actual_length, int timeout) void *data, int len, int *actual_length, int timeout)
@ -242,26 +248,26 @@ EXPORT_SYMBOL_GPL(usb_bulk_msg);
/*-------------------------------------------------------------------*/ /*-------------------------------------------------------------------*/
static void sg_clean (struct usb_sg_request *io) static void sg_clean(struct usb_sg_request *io)
{ {
if (io->urbs) { if (io->urbs) {
while (io->entries--) while (io->entries--)
usb_free_urb (io->urbs [io->entries]); usb_free_urb(io->urbs [io->entries]);
kfree (io->urbs); kfree(io->urbs);
io->urbs = NULL; io->urbs = NULL;
} }
if (io->dev->dev.dma_mask != NULL) if (io->dev->dev.dma_mask != NULL)
usb_buffer_unmap_sg (io->dev, usb_pipein(io->pipe), usb_buffer_unmap_sg(io->dev, usb_pipein(io->pipe),
io->sg, io->nents); io->sg, io->nents);
io->dev = NULL; io->dev = NULL;
} }
static void sg_complete (struct urb *urb) static void sg_complete(struct urb *urb)
{ {
struct usb_sg_request *io = urb->context; struct usb_sg_request *io = urb->context;
int status = urb->status; int status = urb->status;
spin_lock (&io->lock); spin_lock(&io->lock);
/* In 2.5 we require hcds' endpoint queues not to progress after fault /* In 2.5 we require hcds' endpoint queues not to progress after fault
* reports, until the completion callback (this!) returns. That lets * reports, until the completion callback (this!) returns. That lets
@ -277,13 +283,13 @@ static void sg_complete (struct urb *urb)
&& (io->status != -ECONNRESET && (io->status != -ECONNRESET
|| status != -ECONNRESET) || status != -ECONNRESET)
&& urb->actual_length) { && urb->actual_length) {
dev_err (io->dev->bus->controller, dev_err(io->dev->bus->controller,
"dev %s ep%d%s scatterlist error %d/%d\n", "dev %s ep%d%s scatterlist error %d/%d\n",
io->dev->devpath, io->dev->devpath,
usb_endpoint_num(&urb->ep->desc), usb_endpoint_num(&urb->ep->desc),
usb_urb_dir_in(urb) ? "in" : "out", usb_urb_dir_in(urb) ? "in" : "out",
status, io->status); status, io->status);
// BUG (); /* BUG (); */
} }
if (io->status == 0 && status && status != -ECONNRESET) { if (io->status == 0 && status && status != -ECONNRESET) {
@ -295,22 +301,22 @@ static void sg_complete (struct urb *urb)
* unlink pending urbs so they won't rx/tx bad data. * unlink pending urbs so they won't rx/tx bad data.
* careful: unlink can sometimes be synchronous... * careful: unlink can sometimes be synchronous...
*/ */
spin_unlock (&io->lock); spin_unlock(&io->lock);
for (i = 0, found = 0; i < io->entries; i++) { for (i = 0, found = 0; i < io->entries; i++) {
if (!io->urbs [i] || !io->urbs [i]->dev) if (!io->urbs [i] || !io->urbs [i]->dev)
continue; continue;
if (found) { if (found) {
retval = usb_unlink_urb (io->urbs [i]); retval = usb_unlink_urb(io->urbs [i]);
if (retval != -EINPROGRESS && if (retval != -EINPROGRESS &&
retval != -ENODEV && retval != -ENODEV &&
retval != -EBUSY) retval != -EBUSY)
dev_err (&io->dev->dev, dev_err(&io->dev->dev,
"%s, unlink --> %d\n", "%s, unlink --> %d\n",
__FUNCTION__, retval); __FUNCTION__, retval);
} else if (urb == io->urbs [i]) } else if (urb == io->urbs [i])
found = 1; found = 1;
} }
spin_lock (&io->lock); spin_lock(&io->lock);
} }
urb->dev = NULL; urb->dev = NULL;
@ -318,9 +324,9 @@ static void sg_complete (struct urb *urb)
io->bytes += urb->actual_length; io->bytes += urb->actual_length;
io->count--; io->count--;
if (!io->count) if (!io->count)
complete (&io->complete); complete(&io->complete);
spin_unlock (&io->lock); spin_unlock(&io->lock);
} }
@ -349,28 +355,21 @@ static void sg_complete (struct urb *urb)
* The request may be canceled with usb_sg_cancel(), either before or after * The request may be canceled with usb_sg_cancel(), either before or after
* usb_sg_wait() is called. * usb_sg_wait() is called.
*/ */
int usb_sg_init ( int usb_sg_init(struct usb_sg_request *io, struct usb_device *dev,
struct usb_sg_request *io, unsigned pipe, unsigned period, struct scatterlist *sg,
struct usb_device *dev, int nents, size_t length, gfp_t mem_flags)
unsigned pipe,
unsigned period,
struct scatterlist *sg,
int nents,
size_t length,
gfp_t mem_flags
)
{ {
int i; int i;
int urb_flags; int urb_flags;
int dma; int dma;
if (!io || !dev || !sg if (!io || !dev || !sg
|| usb_pipecontrol (pipe) || usb_pipecontrol(pipe)
|| usb_pipeisoc (pipe) || usb_pipeisoc(pipe)
|| nents <= 0) || nents <= 0)
return -EINVAL; return -EINVAL;
spin_lock_init (&io->lock); spin_lock_init(&io->lock);
io->dev = dev; io->dev = dev;
io->pipe = pipe; io->pipe = pipe;
io->sg = sg; io->sg = sg;
@ -391,30 +390,30 @@ int usb_sg_init (
return io->entries; return io->entries;
io->count = io->entries; io->count = io->entries;
io->urbs = kmalloc (io->entries * sizeof *io->urbs, mem_flags); io->urbs = kmalloc(io->entries * sizeof *io->urbs, mem_flags);
if (!io->urbs) if (!io->urbs)
goto nomem; goto nomem;
urb_flags = URB_NO_TRANSFER_DMA_MAP | URB_NO_INTERRUPT; urb_flags = URB_NO_TRANSFER_DMA_MAP | URB_NO_INTERRUPT;
if (usb_pipein (pipe)) if (usb_pipein(pipe))
urb_flags |= URB_SHORT_NOT_OK; urb_flags |= URB_SHORT_NOT_OK;
for (i = 0; i < io->entries; i++) { for (i = 0; i < io->entries; i++) {
unsigned len; unsigned len;
io->urbs [i] = usb_alloc_urb (0, mem_flags); io->urbs[i] = usb_alloc_urb(0, mem_flags);
if (!io->urbs [i]) { if (!io->urbs[i]) {
io->entries = i; io->entries = i;
goto nomem; goto nomem;
} }
io->urbs [i]->dev = NULL; io->urbs[i]->dev = NULL;
io->urbs [i]->pipe = pipe; io->urbs[i]->pipe = pipe;
io->urbs [i]->interval = period; io->urbs[i]->interval = period;
io->urbs [i]->transfer_flags = urb_flags; io->urbs[i]->transfer_flags = urb_flags;
io->urbs [i]->complete = sg_complete; io->urbs[i]->complete = sg_complete;
io->urbs [i]->context = io; io->urbs[i]->context = io;
/* /*
* Some systems need to revert to PIO when DMA is temporarily * Some systems need to revert to PIO when DMA is temporarily
@ -433,8 +432,8 @@ int usb_sg_init (
* to prevent stale pointers and to help spot bugs. * to prevent stale pointers and to help spot bugs.
*/ */
if (dma) { if (dma) {
io->urbs [i]->transfer_dma = sg_dma_address (sg + i); io->urbs[i]->transfer_dma = sg_dma_address(sg + i);
len = sg_dma_len (sg + i); len = sg_dma_len(sg + i);
#if defined(CONFIG_HIGHMEM) || defined(CONFIG_GART_IOMMU) #if defined(CONFIG_HIGHMEM) || defined(CONFIG_GART_IOMMU)
io->urbs[i]->transfer_buffer = NULL; io->urbs[i]->transfer_buffer = NULL;
#else #else
@ -442,28 +441,28 @@ int usb_sg_init (
#endif #endif
} else { } else {
/* hc may use _only_ transfer_buffer */ /* hc may use _only_ transfer_buffer */
io->urbs [i]->transfer_buffer = sg_virt(&sg[i]); io->urbs[i]->transfer_buffer = sg_virt(&sg[i]);
len = sg [i].length; len = sg[i].length;
} }
if (length) { if (length) {
len = min_t (unsigned, len, length); len = min_t(unsigned, len, length);
length -= len; length -= len;
if (length == 0) if (length == 0)
io->entries = i + 1; io->entries = i + 1;
} }
io->urbs [i]->transfer_buffer_length = len; io->urbs[i]->transfer_buffer_length = len;
} }
io->urbs [--i]->transfer_flags &= ~URB_NO_INTERRUPT; io->urbs[--i]->transfer_flags &= ~URB_NO_INTERRUPT;
/* transaction state */ /* transaction state */
io->status = 0; io->status = 0;
io->bytes = 0; io->bytes = 0;
init_completion (&io->complete); init_completion(&io->complete);
return 0; return 0;
nomem: nomem:
sg_clean (io); sg_clean(io);
return -ENOMEM; return -ENOMEM;
} }
EXPORT_SYMBOL_GPL(usb_sg_init); EXPORT_SYMBOL_GPL(usb_sg_init);
@ -507,31 +506,32 @@ EXPORT_SYMBOL_GPL(usb_sg_init);
* speed interrupt endpoints, which allow at most one packet per millisecond, * speed interrupt endpoints, which allow at most one packet per millisecond,
* of at most 8 or 64 bytes (respectively). * of at most 8 or 64 bytes (respectively).
*/ */
void usb_sg_wait (struct usb_sg_request *io) void usb_sg_wait(struct usb_sg_request *io)
{ {
int i, entries = io->entries; int i;
int entries = io->entries;
/* queue the urbs. */ /* queue the urbs. */
spin_lock_irq (&io->lock); spin_lock_irq(&io->lock);
i = 0; i = 0;
while (i < entries && !io->status) { while (i < entries && !io->status) {
int retval; int retval;
io->urbs [i]->dev = io->dev; io->urbs[i]->dev = io->dev;
retval = usb_submit_urb (io->urbs [i], GFP_ATOMIC); retval = usb_submit_urb(io->urbs [i], GFP_ATOMIC);
/* after we submit, let completions or cancelations fire; /* after we submit, let completions or cancelations fire;
* we handshake using io->status. * we handshake using io->status.
*/ */
spin_unlock_irq (&io->lock); spin_unlock_irq(&io->lock);
switch (retval) { switch (retval) {
/* maybe we retrying will recover */ /* maybe we retrying will recover */
case -ENXIO: // hc didn't queue this one case -ENXIO: /* hc didn't queue this one */
case -EAGAIN: case -EAGAIN:
case -ENOMEM: case -ENOMEM:
io->urbs[i]->dev = NULL; io->urbs[i]->dev = NULL;
retval = 0; retval = 0;
yield (); yield();
break; break;
/* no error? continue immediately. /* no error? continue immediately.
@ -542,33 +542,33 @@ void usb_sg_wait (struct usb_sg_request *io)
*/ */
case 0: case 0:
++i; ++i;
cpu_relax (); cpu_relax();
break; break;
/* fail any uncompleted urbs */ /* fail any uncompleted urbs */
default: default:
io->urbs [i]->dev = NULL; io->urbs[i]->dev = NULL;
io->urbs [i]->status = retval; io->urbs[i]->status = retval;
dev_dbg (&io->dev->dev, "%s, submit --> %d\n", dev_dbg(&io->dev->dev, "%s, submit --> %d\n",
__FUNCTION__, retval); __FUNCTION__, retval);
usb_sg_cancel (io); usb_sg_cancel(io);
} }
spin_lock_irq (&io->lock); spin_lock_irq(&io->lock);
if (retval && (io->status == 0 || io->status == -ECONNRESET)) if (retval && (io->status == 0 || io->status == -ECONNRESET))
io->status = retval; io->status = retval;
} }
io->count -= entries - i; io->count -= entries - i;
if (io->count == 0) if (io->count == 0)
complete (&io->complete); complete(&io->complete);
spin_unlock_irq (&io->lock); spin_unlock_irq(&io->lock);
/* OK, yes, this could be packaged as non-blocking. /* OK, yes, this could be packaged as non-blocking.
* So could the submit loop above ... but it's easier to * So could the submit loop above ... but it's easier to
* solve neither problem than to solve both! * solve neither problem than to solve both!
*/ */
wait_for_completion (&io->complete); wait_for_completion(&io->complete);
sg_clean (io); sg_clean(io);
} }
EXPORT_SYMBOL_GPL(usb_sg_wait); EXPORT_SYMBOL_GPL(usb_sg_wait);
@ -580,31 +580,31 @@ EXPORT_SYMBOL_GPL(usb_sg_wait);
* It can also prevents one initialized by usb_sg_init() from starting, * It can also prevents one initialized by usb_sg_init() from starting,
* so that call just frees resources allocated to the request. * so that call just frees resources allocated to the request.
*/ */
void usb_sg_cancel (struct usb_sg_request *io) void usb_sg_cancel(struct usb_sg_request *io)
{ {
unsigned long flags; unsigned long flags;
spin_lock_irqsave (&io->lock, flags); spin_lock_irqsave(&io->lock, flags);
/* shut everything down, if it didn't already */ /* shut everything down, if it didn't already */
if (!io->status) { if (!io->status) {
int i; int i;
io->status = -ECONNRESET; io->status = -ECONNRESET;
spin_unlock (&io->lock); spin_unlock(&io->lock);
for (i = 0; i < io->entries; i++) { for (i = 0; i < io->entries; i++) {
int retval; int retval;
if (!io->urbs [i]->dev) if (!io->urbs [i]->dev)
continue; continue;
retval = usb_unlink_urb (io->urbs [i]); retval = usb_unlink_urb(io->urbs [i]);
if (retval != -EINPROGRESS && retval != -EBUSY) if (retval != -EINPROGRESS && retval != -EBUSY)
dev_warn (&io->dev->dev, "%s, unlink --> %d\n", dev_warn(&io->dev->dev, "%s, unlink --> %d\n",
__FUNCTION__, retval); __FUNCTION__, retval);
} }
spin_lock (&io->lock); spin_lock(&io->lock);
} }
spin_unlock_irqrestore (&io->lock, flags); spin_unlock_irqrestore(&io->lock, flags);
} }
EXPORT_SYMBOL_GPL(usb_sg_cancel); EXPORT_SYMBOL_GPL(usb_sg_cancel);
@ -632,12 +632,13 @@ EXPORT_SYMBOL_GPL(usb_sg_cancel);
* Returns the number of bytes received on success, or else the status code * Returns the number of bytes received on success, or else the status code
* returned by the underlying usb_control_msg() call. * returned by the underlying usb_control_msg() call.
*/ */
int usb_get_descriptor(struct usb_device *dev, unsigned char type, unsigned char index, void *buf, int size) int usb_get_descriptor(struct usb_device *dev, unsigned char type,
unsigned char index, void *buf, int size)
{ {
int i; int i;
int result; int result;
memset(buf,0,size); // Make sure we parse really received data memset(buf, 0, size); /* Make sure we parse really received data */
for (i = 0; i < 3; ++i) { for (i = 0; i < 3; ++i) {
/* retry on length 0 or error; some devices are flakey */ /* retry on length 0 or error; some devices are flakey */
@ -791,19 +792,19 @@ int usb_string(struct usb_device *dev, int index, char *buf, size_t size)
if (!dev->have_langid) { if (!dev->have_langid) {
err = usb_string_sub(dev, 0, 0, tbuf); err = usb_string_sub(dev, 0, 0, tbuf);
if (err < 0) { if (err < 0) {
dev_err (&dev->dev, dev_err(&dev->dev,
"string descriptor 0 read error: %d\n", "string descriptor 0 read error: %d\n",
err); err);
goto errout; goto errout;
} else if (err < 4) { } else if (err < 4) {
dev_err (&dev->dev, "string descriptor 0 too short\n"); dev_err(&dev->dev, "string descriptor 0 too short\n");
err = -EINVAL; err = -EINVAL;
goto errout; goto errout;
} else { } else {
dev->have_langid = 1; dev->have_langid = 1;
dev->string_langid = tbuf[2] | (tbuf[3]<< 8); dev->string_langid = tbuf[2] | (tbuf[3] << 8);
/* always use the first langid listed */ /* always use the first langid listed */
dev_dbg (&dev->dev, "default language 0x%04x\n", dev_dbg(&dev->dev, "default language 0x%04x\n",
dev->string_langid); dev->string_langid);
} }
} }
@ -825,7 +826,9 @@ int usb_string(struct usb_device *dev, int index, char *buf, size_t size)
err = idx; err = idx;
if (tbuf[1] != USB_DT_STRING) if (tbuf[1] != USB_DT_STRING)
dev_dbg(&dev->dev, "wrong descriptor type %02x for string %d (\"%s\")\n", tbuf[1], index, buf); dev_dbg(&dev->dev,
"wrong descriptor type %02x for string %d (\"%s\")\n",
tbuf[1], index, buf);
errout: errout:
kfree(tbuf); kfree(tbuf);
@ -847,9 +850,15 @@ char *usb_cache_string(struct usb_device *udev, int index)
char *smallbuf = NULL; char *smallbuf = NULL;
int len; int len;
if (index > 0 && (buf = kmalloc(256, GFP_KERNEL)) != NULL) { if (index <= 0)
if ((len = usb_string(udev, index, buf, 256)) > 0) { return NULL;
if ((smallbuf = kmalloc(++len, GFP_KERNEL)) == NULL)
buf = kmalloc(256, GFP_KERNEL);
if (buf) {
len = usb_string(udev, index, buf, 256);
if (len > 0) {
smallbuf = kmalloc(++len, GFP_KERNEL);
if (!smallbuf)
return buf; return buf;
memcpy(smallbuf, buf, len); memcpy(smallbuf, buf, len);
} }
@ -962,7 +971,7 @@ int usb_clear_halt(struct usb_device *dev, int pipe)
int result; int result;
int endp = usb_pipeendpoint(pipe); int endp = usb_pipeendpoint(pipe);
if (usb_pipein (pipe)) if (usb_pipein(pipe))
endp |= USB_DIR_IN; endp |= USB_DIR_IN;
/* we don't care if it wasn't halted first. in fact some devices /* we don't care if it wasn't halted first. in fact some devices
@ -1045,7 +1054,7 @@ void usb_disable_interface(struct usb_device *dev, struct usb_interface *intf)
} }
} }
/* /**
* usb_disable_device - Disable all the endpoints for a USB device * usb_disable_device - Disable all the endpoints for a USB device
* @dev: the device whose endpoints are being disabled * @dev: the device whose endpoints are being disabled
* @skip_ep0: 0 to disable endpoint 0, 1 to skip it. * @skip_ep0: 0 to disable endpoint 0, 1 to skip it.
@ -1078,17 +1087,17 @@ void usb_disable_device(struct usb_device *dev, int skip_ep0)
interface = dev->actconfig->interface[i]; interface = dev->actconfig->interface[i];
if (!device_is_registered(&interface->dev)) if (!device_is_registered(&interface->dev))
continue; continue;
dev_dbg (&dev->dev, "unregistering interface %s\n", dev_dbg(&dev->dev, "unregistering interface %s\n",
interface->dev.bus_id); interface->dev.bus_id);
usb_remove_sysfs_intf_files(interface); usb_remove_sysfs_intf_files(interface);
device_del (&interface->dev); device_del(&interface->dev);
} }
/* Now that the interfaces are unbound, nobody should /* Now that the interfaces are unbound, nobody should
* try to access them. * try to access them.
*/ */
for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) { for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) {
put_device (&dev->actconfig->interface[i]->dev); put_device(&dev->actconfig->interface[i]->dev);
dev->actconfig->interface[i] = NULL; dev->actconfig->interface[i] = NULL;
} }
dev->actconfig = NULL; dev->actconfig = NULL;
@ -1097,8 +1106,7 @@ void usb_disable_device(struct usb_device *dev, int skip_ep0)
} }
} }
/**
/*
* usb_enable_endpoint - Enable an endpoint for USB communications * usb_enable_endpoint - Enable an endpoint for USB communications
* @dev: the device whose interface is being enabled * @dev: the device whose interface is being enabled
* @ep: the endpoint * @ep: the endpoint
@ -1123,7 +1131,7 @@ void usb_enable_endpoint(struct usb_device *dev, struct usb_host_endpoint *ep)
ep->enabled = 1; ep->enabled = 1;
} }
/* /**
* usb_enable_interface - Enable all the endpoints for an interface * usb_enable_interface - Enable all the endpoints for an interface
* @dev: the device whose interface is being enabled * @dev: the device whose interface is being enabled
* @intf: pointer to the interface descriptor * @intf: pointer to the interface descriptor
@ -1179,6 +1187,8 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate)
struct usb_host_interface *alt; struct usb_host_interface *alt;
int ret; int ret;
int manual = 0; int manual = 0;
unsigned int epaddr;
unsigned int pipe;
if (dev->state == USB_STATE_SUSPENDED) if (dev->state == USB_STATE_SUSPENDED)
return -EHOSTUNREACH; return -EHOSTUNREACH;
@ -1233,11 +1243,11 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate)
int i; int i;
for (i = 0; i < alt->desc.bNumEndpoints; i++) { for (i = 0; i < alt->desc.bNumEndpoints; i++) {
unsigned int epaddr = epaddr = alt->endpoint[i].desc.bEndpointAddress;
alt->endpoint[i].desc.bEndpointAddress; pipe = __create_pipe(dev,
unsigned int pipe = USB_ENDPOINT_NUMBER_MASK & epaddr) |
__create_pipe(dev, USB_ENDPOINT_NUMBER_MASK & epaddr) (usb_endpoint_out(epaddr) ?
| (usb_endpoint_out(epaddr) ? USB_DIR_OUT : USB_DIR_IN); USB_DIR_OUT : USB_DIR_IN);
usb_clear_halt(dev, pipe); usb_clear_halt(dev, pipe);
} }
@ -1366,7 +1376,8 @@ static int usb_if_uevent(struct device *dev, struct kobj_uevent_env *env)
return -ENOMEM; return -ENOMEM;
if (add_uevent_var(env, if (add_uevent_var(env,
"MODALIAS=usb:v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02Xic%02Xisc%02Xip%02X", "MODALIAS=usb:"
"v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02Xic%02Xisc%02Xip%02X",
le16_to_cpu(usb_dev->descriptor.idVendor), le16_to_cpu(usb_dev->descriptor.idVendor),
le16_to_cpu(usb_dev->descriptor.idProduct), le16_to_cpu(usb_dev->descriptor.idProduct),
le16_to_cpu(usb_dev->descriptor.bcdDevice), le16_to_cpu(usb_dev->descriptor.bcdDevice),
@ -1424,7 +1435,6 @@ static struct usb_interface_assoc_descriptor *find_iad(struct usb_device *dev,
return retval; return retval;
} }
/* /*
* usb_set_configuration - Makes a particular device setting be current * usb_set_configuration - Makes a particular device setting be current
* @dev: the device whose configuration is being updated * @dev: the device whose configuration is being updated
@ -1542,12 +1552,12 @@ free_interfaces:
* getting rid of old interfaces means unbinding their drivers. * getting rid of old interfaces means unbinding their drivers.
*/ */
if (dev->state != USB_STATE_ADDRESS) if (dev->state != USB_STATE_ADDRESS)
usb_disable_device (dev, 1); // Skip ep0 usb_disable_device(dev, 1); /* Skip ep0 */
if ((ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
USB_REQ_SET_CONFIGURATION, 0, configuration, 0, USB_REQ_SET_CONFIGURATION, 0, configuration, 0,
NULL, 0, USB_CTRL_SET_TIMEOUT)) < 0) { NULL, 0, USB_CTRL_SET_TIMEOUT);
if (ret < 0) {
/* All the old state is gone, so what else can we do? /* All the old state is gone, so what else can we do?
* The device is probably useless now anyway. * The device is probably useless now anyway.
*/ */
@ -1594,9 +1604,9 @@ free_interfaces:
intf->dev.bus = &usb_bus_type; intf->dev.bus = &usb_bus_type;
intf->dev.type = &usb_if_device_type; intf->dev.type = &usb_if_device_type;
intf->dev.dma_mask = dev->dev.dma_mask; intf->dev.dma_mask = dev->dev.dma_mask;
device_initialize (&intf->dev); device_initialize(&intf->dev);
mark_quiesced(intf); mark_quiesced(intf);
sprintf (&intf->dev.bus_id[0], "%d-%s:%d.%d", sprintf(&intf->dev.bus_id[0], "%d-%s:%d.%d",
dev->bus->busnum, dev->devpath, dev->bus->busnum, dev->devpath,
configuration, alt->desc.bInterfaceNumber); configuration, alt->desc.bInterfaceNumber);
} }
@ -1614,11 +1624,11 @@ free_interfaces:
for (i = 0; i < nintf; ++i) { for (i = 0; i < nintf; ++i) {
struct usb_interface *intf = cp->interface[i]; struct usb_interface *intf = cp->interface[i];
dev_dbg (&dev->dev, dev_dbg(&dev->dev,
"adding %s (config #%d, interface %d)\n", "adding %s (config #%d, interface %d)\n",
intf->dev.bus_id, configuration, intf->dev.bus_id, configuration,
intf->cur_altsetting->desc.bInterfaceNumber); intf->cur_altsetting->desc.bInterfaceNumber);
ret = device_add (&intf->dev); ret = device_add(&intf->dev);
if (ret != 0) { if (ret != 0) {
dev_err(&dev->dev, "device_add(%s) --> %d\n", dev_err(&dev->dev, "device_add(%s) --> %d\n",
intf->dev.bus_id, ret); intf->dev.bus_id, ret);