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>

+199 -189
+199 -189
drivers/usb/core/message.c
··· 39 * own interruptible routines. 40 */ 41 static int usb_start_wait_urb(struct urb *urb, int timeout, int *actual_length) 42 - { 43 struct api_context ctx; 44 unsigned long expire; 45 int retval; ··· 74 } 75 76 /*-------------------------------------------------------------------*/ 77 - // returns status (negative) or length (positive) 78 static int usb_internal_control_msg(struct usb_device *usb_dev, 79 - unsigned int pipe, 80 struct usb_ctrlrequest *cmd, 81 void *data, int len, int timeout) 82 { ··· 87 urb = usb_alloc_urb(0, GFP_NOIO); 88 if (!urb) 89 return -ENOMEM; 90 - 91 usb_fill_control_urb(urb, usb_dev, pipe, (unsigned char *)cmd, data, 92 len, usb_api_blocking_completion, NULL); 93 ··· 99 } 100 101 /** 102 - * usb_control_msg - Builds a control urb, sends it off and waits for completion 103 - * @dev: pointer to the usb device to send the message to 104 - * @pipe: endpoint "pipe" to send the message to 105 - * @request: USB message request value 106 - * @requesttype: USB message request type value 107 - * @value: USB message value 108 - * @index: USB message index value 109 - * @data: pointer to the data to send 110 - * @size: length in bytes of the data to send 111 - * @timeout: time in msecs to wait for the message to complete before 112 - * timing out (if 0 the wait is forever) 113 - * Context: !in_interrupt () 114 * 115 - * This function sends a simple control message to a specified endpoint 116 - * and waits for the message to complete, or timeout. 117 - * 118 - * If successful, it returns the number of bytes transferred, otherwise a negative error number. 119 * 120 - * Don't use this function from within an interrupt context, like a 121 - * bottom half handler. If you need an asynchronous message, or need to send 122 - * a message from within interrupt context, use usb_submit_urb() 123 - * If a thread in your driver uses this call, make sure your disconnect() 124 - * method can wait for it to complete. Since you don't have a handle on 125 - * the URB used, you can't cancel the request. 126 */ 127 - int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request, __u8 requesttype, 128 - __u16 value, __u16 index, void *data, __u16 size, int timeout) 129 { 130 - struct usb_ctrlrequest *dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_NOIO); 131 int ret; 132 - 133 if (!dr) 134 return -ENOMEM; 135 136 - dr->bRequestType= requesttype; 137 dr->bRequest = request; 138 dr->wValue = cpu_to_le16p(&value); 139 dr->wIndex = cpu_to_le16p(&index); 140 dr->wLength = cpu_to_le16p(&size); 141 142 - //dbg("usb_control_msg"); 143 144 ret = usb_internal_control_msg(dev, pipe, dr, data, size, timeout); 145 ··· 159 * @pipe: endpoint "pipe" to send the message to 160 * @data: pointer to the data to send 161 * @len: length in bytes of the data to send 162 - * @actual_length: pointer to a location to put the actual length transferred in bytes 163 * @timeout: time in msecs to wait for the message to complete before 164 * timing out (if 0 the wait is forever) 165 * Context: !in_interrupt () 166 * 167 * This function sends a simple interrupt message to a specified endpoint and ··· 187 EXPORT_SYMBOL_GPL(usb_interrupt_msg); 188 189 /** 190 - * usb_bulk_msg - Builds a bulk urb, sends it off and waits for completion 191 - * @usb_dev: pointer to the usb device to send the message to 192 - * @pipe: endpoint "pipe" to send the message to 193 - * @data: pointer to the data to send 194 - * @len: length in bytes of the data to send 195 - * @actual_length: pointer to a location to put the actual length transferred in bytes 196 - * @timeout: time in msecs to wait for the message to complete before 197 - * timing out (if 0 the wait is forever) 198 - * Context: !in_interrupt () 199 * 200 - * This function sends a simple bulk message to a specified endpoint 201 - * and waits for the message to complete, or timeout. 202 - * 203 - * If successful, it returns 0, otherwise a negative error number. 204 - * The number of actual bytes transferred will be stored in the 205 - * actual_length paramater. 206 * 207 - * Don't use this function from within an interrupt context, like a 208 - * bottom half handler. If you need an asynchronous message, or need to 209 - * send a message from within interrupt context, use usb_submit_urb() 210 - * If a thread in your driver uses this call, make sure your disconnect() 211 - * method can wait for it to complete. Since you don't have a handle on 212 - * the URB used, you can't cancel the request. 213 * 214 - * Because there is no usb_interrupt_msg() and no USBDEVFS_INTERRUPT 215 - * ioctl, users are forced to abuse this routine by using it to submit 216 - * URBs for interrupt endpoints. We will take the liberty of creating 217 - * an interrupt URB (with the default interval) if the target is an 218 - * interrupt endpoint. 219 */ 220 - int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe, 221 - void *data, int len, int *actual_length, int timeout) 222 { 223 struct urb *urb; 224 struct usb_host_endpoint *ep; ··· 248 249 /*-------------------------------------------------------------------*/ 250 251 - static void sg_clean (struct usb_sg_request *io) 252 { 253 if (io->urbs) { 254 while (io->entries--) 255 - usb_free_urb (io->urbs [io->entries]); 256 - kfree (io->urbs); 257 io->urbs = NULL; 258 } 259 if (io->dev->dev.dma_mask != NULL) 260 - usb_buffer_unmap_sg (io->dev, usb_pipein(io->pipe), 261 - io->sg, io->nents); 262 io->dev = NULL; 263 } 264 265 - static void sg_complete (struct urb *urb) 266 { 267 - struct usb_sg_request *io = urb->context; 268 int status = urb->status; 269 270 - spin_lock (&io->lock); 271 272 /* In 2.5 we require hcds' endpoint queues not to progress after fault 273 * reports, until the completion callback (this!) returns. That lets ··· 283 && (io->status != -ECONNRESET 284 || status != -ECONNRESET) 285 && urb->actual_length) { 286 - dev_err (io->dev->bus->controller, 287 "dev %s ep%d%s scatterlist error %d/%d\n", 288 io->dev->devpath, 289 usb_endpoint_num(&urb->ep->desc), 290 usb_urb_dir_in(urb) ? "in" : "out", 291 status, io->status); 292 - // BUG (); 293 } 294 295 if (io->status == 0 && status && status != -ECONNRESET) { ··· 301 * unlink pending urbs so they won't rx/tx bad data. 302 * careful: unlink can sometimes be synchronous... 303 */ 304 - spin_unlock (&io->lock); 305 for (i = 0, found = 0; i < io->entries; i++) { 306 if (!io->urbs [i] || !io->urbs [i]->dev) 307 continue; 308 if (found) { 309 - retval = usb_unlink_urb (io->urbs [i]); 310 if (retval != -EINPROGRESS && 311 retval != -ENODEV && 312 retval != -EBUSY) 313 - dev_err (&io->dev->dev, 314 "%s, unlink --> %d\n", 315 __FUNCTION__, retval); 316 } else if (urb == io->urbs [i]) 317 found = 1; 318 } 319 - spin_lock (&io->lock); 320 } 321 urb->dev = NULL; 322 ··· 324 io->bytes += urb->actual_length; 325 io->count--; 326 if (!io->count) 327 - complete (&io->complete); 328 329 - spin_unlock (&io->lock); 330 } 331 332 ··· 355 * The request may be canceled with usb_sg_cancel(), either before or after 356 * usb_sg_wait() is called. 357 */ 358 - int usb_sg_init ( 359 - struct usb_sg_request *io, 360 - struct usb_device *dev, 361 - unsigned pipe, 362 - unsigned period, 363 - struct scatterlist *sg, 364 - int nents, 365 - size_t length, 366 - gfp_t mem_flags 367 - ) 368 { 369 - int i; 370 - int urb_flags; 371 - int dma; 372 373 if (!io || !dev || !sg 374 - || usb_pipecontrol (pipe) 375 - || usb_pipeisoc (pipe) 376 || nents <= 0) 377 return -EINVAL; 378 379 - spin_lock_init (&io->lock); 380 io->dev = dev; 381 io->pipe = pipe; 382 io->sg = sg; ··· 381 dma = (dev->dev.dma_mask != NULL); 382 if (dma) 383 io->entries = usb_buffer_map_sg(dev, usb_pipein(pipe), 384 - sg, nents); 385 else 386 io->entries = nents; 387 ··· 390 return io->entries; 391 392 io->count = io->entries; 393 - io->urbs = kmalloc (io->entries * sizeof *io->urbs, mem_flags); 394 if (!io->urbs) 395 goto nomem; 396 397 urb_flags = URB_NO_TRANSFER_DMA_MAP | URB_NO_INTERRUPT; 398 - if (usb_pipein (pipe)) 399 urb_flags |= URB_SHORT_NOT_OK; 400 401 for (i = 0; i < io->entries; i++) { 402 - unsigned len; 403 404 - io->urbs [i] = usb_alloc_urb (0, mem_flags); 405 - if (!io->urbs [i]) { 406 io->entries = i; 407 goto nomem; 408 } 409 410 - io->urbs [i]->dev = NULL; 411 - io->urbs [i]->pipe = pipe; 412 - io->urbs [i]->interval = period; 413 - io->urbs [i]->transfer_flags = urb_flags; 414 415 - io->urbs [i]->complete = sg_complete; 416 - io->urbs [i]->context = io; 417 418 /* 419 * Some systems need to revert to PIO when DMA is temporarily ··· 432 * to prevent stale pointers and to help spot bugs. 433 */ 434 if (dma) { 435 - io->urbs [i]->transfer_dma = sg_dma_address (sg + i); 436 - len = sg_dma_len (sg + i); 437 #if defined(CONFIG_HIGHMEM) || defined(CONFIG_GART_IOMMU) 438 io->urbs[i]->transfer_buffer = NULL; 439 #else ··· 441 #endif 442 } else { 443 /* hc may use _only_ transfer_buffer */ 444 - io->urbs [i]->transfer_buffer = sg_virt(&sg[i]); 445 - len = sg [i].length; 446 } 447 448 if (length) { 449 - len = min_t (unsigned, len, length); 450 length -= len; 451 if (length == 0) 452 io->entries = i + 1; 453 } 454 - io->urbs [i]->transfer_buffer_length = len; 455 } 456 - io->urbs [--i]->transfer_flags &= ~URB_NO_INTERRUPT; 457 458 /* transaction state */ 459 io->status = 0; 460 io->bytes = 0; 461 - init_completion (&io->complete); 462 return 0; 463 464 nomem: 465 - sg_clean (io); 466 return -ENOMEM; 467 } 468 EXPORT_SYMBOL_GPL(usb_sg_init); ··· 506 * speed interrupt endpoints, which allow at most one packet per millisecond, 507 * of at most 8 or 64 bytes (respectively). 508 */ 509 - void usb_sg_wait (struct usb_sg_request *io) 510 { 511 - int i, entries = io->entries; 512 513 /* queue the urbs. */ 514 - spin_lock_irq (&io->lock); 515 i = 0; 516 while (i < entries && !io->status) { 517 - int retval; 518 519 - io->urbs [i]->dev = io->dev; 520 - retval = usb_submit_urb (io->urbs [i], GFP_ATOMIC); 521 522 /* after we submit, let completions or cancelations fire; 523 * we handshake using io->status. 524 */ 525 - spin_unlock_irq (&io->lock); 526 switch (retval) { 527 /* maybe we retrying will recover */ 528 - case -ENXIO: // hc didn't queue this one 529 case -EAGAIN: 530 case -ENOMEM: 531 io->urbs[i]->dev = NULL; 532 retval = 0; 533 - yield (); 534 break; 535 536 /* no error? continue immediately. ··· 542 */ 543 case 0: 544 ++i; 545 - cpu_relax (); 546 break; 547 548 /* fail any uncompleted urbs */ 549 default: 550 - io->urbs [i]->dev = NULL; 551 - io->urbs [i]->status = retval; 552 - dev_dbg (&io->dev->dev, "%s, submit --> %d\n", 553 __FUNCTION__, retval); 554 - usb_sg_cancel (io); 555 } 556 - spin_lock_irq (&io->lock); 557 if (retval && (io->status == 0 || io->status == -ECONNRESET)) 558 io->status = retval; 559 } 560 io->count -= entries - i; 561 if (io->count == 0) 562 - complete (&io->complete); 563 - spin_unlock_irq (&io->lock); 564 565 /* OK, yes, this could be packaged as non-blocking. 566 * So could the submit loop above ... but it's easier to 567 * solve neither problem than to solve both! 568 */ 569 - wait_for_completion (&io->complete); 570 571 - sg_clean (io); 572 } 573 EXPORT_SYMBOL_GPL(usb_sg_wait); 574 ··· 580 * It can also prevents one initialized by usb_sg_init() from starting, 581 * so that call just frees resources allocated to the request. 582 */ 583 - void usb_sg_cancel (struct usb_sg_request *io) 584 { 585 - unsigned long flags; 586 587 - spin_lock_irqsave (&io->lock, flags); 588 589 /* shut everything down, if it didn't already */ 590 if (!io->status) { 591 - int i; 592 593 io->status = -ECONNRESET; 594 - spin_unlock (&io->lock); 595 for (i = 0; i < io->entries; i++) { 596 - int retval; 597 598 if (!io->urbs [i]->dev) 599 continue; 600 - retval = usb_unlink_urb (io->urbs [i]); 601 if (retval != -EINPROGRESS && retval != -EBUSY) 602 - dev_warn (&io->dev->dev, "%s, unlink --> %d\n", 603 __FUNCTION__, retval); 604 } 605 - spin_lock (&io->lock); 606 } 607 - spin_unlock_irqrestore (&io->lock, flags); 608 } 609 EXPORT_SYMBOL_GPL(usb_sg_cancel); 610 ··· 632 * Returns the number of bytes received on success, or else the status code 633 * returned by the underlying usb_control_msg() call. 634 */ 635 - int usb_get_descriptor(struct usb_device *dev, unsigned char type, unsigned char index, void *buf, int size) 636 { 637 int i; 638 int result; 639 - 640 - memset(buf,0,size); // Make sure we parse really received data 641 642 for (i = 0; i < 3; ++i) { 643 /* retry on length 0 or error; some devices are flakey */ ··· 713 } 714 715 static int usb_string_sub(struct usb_device *dev, unsigned int langid, 716 - unsigned int index, unsigned char *buf) 717 { 718 int rc; 719 ··· 756 * @buf: where to put the string 757 * @size: how big is "buf"? 758 * Context: !in_interrupt () 759 - * 760 * This converts the UTF-16LE encoded strings returned by devices, from 761 * usb_get_string_descriptor(), to null-terminated ISO-8859-1 encoded ones 762 * that are more usable in most kernel contexts. Note that all characters ··· 792 if (!dev->have_langid) { 793 err = usb_string_sub(dev, 0, 0, tbuf); 794 if (err < 0) { 795 - dev_err (&dev->dev, 796 "string descriptor 0 read error: %d\n", 797 err); 798 goto errout; 799 } else if (err < 4) { 800 - dev_err (&dev->dev, "string descriptor 0 too short\n"); 801 err = -EINVAL; 802 goto errout; 803 } else { 804 dev->have_langid = 1; 805 - dev->string_langid = tbuf[2] | (tbuf[3]<< 8); 806 - /* always use the first langid listed */ 807 - dev_dbg (&dev->dev, "default language 0x%04x\n", 808 dev->string_langid); 809 } 810 } 811 - 812 err = usb_string_sub(dev, dev->string_langid, index, tbuf); 813 if (err < 0) 814 goto errout; ··· 826 err = idx; 827 828 if (tbuf[1] != USB_DT_STRING) 829 - dev_dbg(&dev->dev, "wrong descriptor type %02x for string %d (\"%s\")\n", tbuf[1], index, buf); 830 831 errout: 832 kfree(tbuf); ··· 850 char *smallbuf = NULL; 851 int len; 852 853 - if (index > 0 && (buf = kmalloc(256, GFP_KERNEL)) != NULL) { 854 - if ((len = usb_string(udev, index, buf, 256)) > 0) { 855 - if ((smallbuf = kmalloc(++len, GFP_KERNEL)) == NULL) 856 return buf; 857 memcpy(smallbuf, buf, len); 858 } ··· 897 return -ENOMEM; 898 899 ret = usb_get_descriptor(dev, USB_DT_DEVICE, 0, desc, size); 900 - if (ret >= 0) 901 memcpy(&dev->descriptor, desc, size); 902 kfree(desc); 903 return ret; ··· 970 { 971 int result; 972 int endp = usb_pipeendpoint(pipe); 973 - 974 - if (usb_pipein (pipe)) 975 endp |= USB_DIR_IN; 976 977 /* we don't care if it wasn't halted first. in fact some devices ··· 1054 } 1055 } 1056 1057 - /* 1058 * usb_disable_device - Disable all the endpoints for a USB device 1059 * @dev: the device whose endpoints are being disabled 1060 * @skip_ep0: 0 to disable endpoint 0, 1 to skip it. ··· 1069 int i; 1070 1071 dev_dbg(&dev->dev, "%s nuking %s URBs\n", __FUNCTION__, 1072 - skip_ep0 ? "non-ep0" : "all"); 1073 for (i = skip_ep0; i < 16; ++i) { 1074 usb_disable_endpoint(dev, i); 1075 usb_disable_endpoint(dev, i + USB_DIR_IN); ··· 1087 interface = dev->actconfig->interface[i]; 1088 if (!device_is_registered(&interface->dev)) 1089 continue; 1090 - dev_dbg (&dev->dev, "unregistering interface %s\n", 1091 interface->dev.bus_id); 1092 usb_remove_sysfs_intf_files(interface); 1093 - device_del (&interface->dev); 1094 } 1095 1096 /* Now that the interfaces are unbound, nobody should 1097 * try to access them. 1098 */ 1099 for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) { 1100 - put_device (&dev->actconfig->interface[i]->dev); 1101 dev->actconfig->interface[i] = NULL; 1102 } 1103 dev->actconfig = NULL; ··· 1106 } 1107 } 1108 1109 - 1110 - /* 1111 * usb_enable_endpoint - Enable an endpoint for USB communications 1112 * @dev: the device whose interface is being enabled 1113 * @ep: the endpoint ··· 1131 ep->enabled = 1; 1132 } 1133 1134 - /* 1135 * usb_enable_interface - Enable all the endpoints for an interface 1136 * @dev: the device whose interface is being enabled 1137 * @intf: pointer to the interface descriptor ··· 1187 struct usb_host_interface *alt; 1188 int ret; 1189 int manual = 0; 1190 1191 if (dev->state == USB_STATE_SUSPENDED) 1192 return -EHOSTUNREACH; ··· 1243 int i; 1244 1245 for (i = 0; i < alt->desc.bNumEndpoints; i++) { 1246 - unsigned int epaddr = 1247 - alt->endpoint[i].desc.bEndpointAddress; 1248 - unsigned int pipe = 1249 - __create_pipe(dev, USB_ENDPOINT_NUMBER_MASK & epaddr) 1250 - | (usb_endpoint_out(epaddr) ? USB_DIR_OUT : USB_DIR_IN); 1251 1252 usb_clear_halt(dev, pipe); 1253 } ··· 1376 return -ENOMEM; 1377 1378 if (add_uevent_var(env, 1379 - "MODALIAS=usb:v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02Xic%02Xisc%02Xip%02X", 1380 le16_to_cpu(usb_dev->descriptor.idVendor), 1381 le16_to_cpu(usb_dev->descriptor.idProduct), 1382 le16_to_cpu(usb_dev->descriptor.bcdDevice), ··· 1407 }; 1408 1409 static struct usb_interface_assoc_descriptor *find_iad(struct usb_device *dev, 1410 - struct usb_host_config *config, 1411 - u8 inum) 1412 { 1413 struct usb_interface_assoc_descriptor *retval = NULL; 1414 struct usb_interface_assoc_descriptor *intf_assoc; ··· 1434 1435 return retval; 1436 } 1437 - 1438 1439 /* 1440 * usb_set_configuration - Makes a particular device setting be current ··· 1552 * getting rid of old interfaces means unbinding their drivers. 1553 */ 1554 if (dev->state != USB_STATE_ADDRESS) 1555 - usb_disable_device (dev, 1); // Skip ep0 1556 1557 - if ((ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 1558 - USB_REQ_SET_CONFIGURATION, 0, configuration, 0, 1559 - NULL, 0, USB_CTRL_SET_TIMEOUT)) < 0) { 1560 - 1561 /* All the old state is gone, so what else can we do? 1562 * The device is probably useless now anyway. 1563 */ ··· 1604 intf->dev.bus = &usb_bus_type; 1605 intf->dev.type = &usb_if_device_type; 1606 intf->dev.dma_mask = dev->dev.dma_mask; 1607 - device_initialize (&intf->dev); 1608 mark_quiesced(intf); 1609 - sprintf (&intf->dev.bus_id[0], "%d-%s:%d.%d", 1610 - dev->bus->busnum, dev->devpath, 1611 - configuration, alt->desc.bInterfaceNumber); 1612 } 1613 kfree(new_interfaces); 1614 ··· 1624 for (i = 0; i < nintf; ++i) { 1625 struct usb_interface *intf = cp->interface[i]; 1626 1627 - dev_dbg (&dev->dev, 1628 "adding %s (config #%d, interface %d)\n", 1629 intf->dev.bus_id, configuration, 1630 intf->cur_altsetting->desc.bInterfaceNumber); 1631 - ret = device_add (&intf->dev); 1632 if (ret != 0) { 1633 dev_err(&dev->dev, "device_add(%s) --> %d\n", 1634 intf->dev.bus_id, ret);
··· 39 * own interruptible routines. 40 */ 41 static int usb_start_wait_urb(struct urb *urb, int timeout, int *actual_length) 42 + { 43 struct api_context ctx; 44 unsigned long expire; 45 int retval; ··· 74 } 75 76 /*-------------------------------------------------------------------*/ 77 + /* returns status (negative) or length (positive) */ 78 static int usb_internal_control_msg(struct usb_device *usb_dev, 79 + unsigned int pipe, 80 struct usb_ctrlrequest *cmd, 81 void *data, int len, int timeout) 82 { ··· 87 urb = usb_alloc_urb(0, GFP_NOIO); 88 if (!urb) 89 return -ENOMEM; 90 + 91 usb_fill_control_urb(urb, usb_dev, pipe, (unsigned char *)cmd, data, 92 len, usb_api_blocking_completion, NULL); 93 ··· 99 } 100 101 /** 102 + * usb_control_msg - Builds a control urb, sends it off and waits for completion 103 + * @dev: pointer to the usb device to send the message to 104 + * @pipe: endpoint "pipe" to send the message to 105 + * @request: USB message request value 106 + * @requesttype: USB message request type value 107 + * @value: USB message value 108 + * @index: USB message index value 109 + * @data: pointer to the data to send 110 + * @size: length in bytes of the data to send 111 + * @timeout: time in msecs to wait for the message to complete before timing 112 + * out (if 0 the wait is forever) 113 * 114 + * Context: !in_interrupt () 115 * 116 + * This function sends a simple control message to a specified endpoint and 117 + * waits for the message to complete, or timeout. 118 + * 119 + * If successful, it returns the number of bytes transferred, otherwise a 120 + * negative error number. 121 + * 122 + * Don't use this function from within an interrupt context, like a bottom half 123 + * handler. If you need an asynchronous message, or need to send a message 124 + * from within interrupt context, use usb_submit_urb(). 125 + * If a thread in your driver uses this call, make sure your disconnect() 126 + * method can wait for it to complete. Since you don't have a handle on the 127 + * URB used, you can't cancel the request. 128 */ 129 + int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request, 130 + __u8 requesttype, __u16 value, __u16 index, void *data, 131 + __u16 size, int timeout) 132 { 133 + struct usb_ctrlrequest *dr; 134 int ret; 135 + 136 + dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_NOIO); 137 if (!dr) 138 return -ENOMEM; 139 140 + dr->bRequestType = requesttype; 141 dr->bRequest = request; 142 dr->wValue = cpu_to_le16p(&value); 143 dr->wIndex = cpu_to_le16p(&index); 144 dr->wLength = cpu_to_le16p(&size); 145 146 + /* dbg("usb_control_msg"); */ 147 148 ret = usb_internal_control_msg(dev, pipe, dr, data, size, timeout); 149 ··· 155 * @pipe: endpoint "pipe" to send the message to 156 * @data: pointer to the data to send 157 * @len: length in bytes of the data to send 158 + * @actual_length: pointer to a location to put the actual length transferred 159 + * in bytes 160 * @timeout: time in msecs to wait for the message to complete before 161 * timing out (if 0 the wait is forever) 162 + * 163 * Context: !in_interrupt () 164 * 165 * This function sends a simple interrupt message to a specified endpoint and ··· 181 EXPORT_SYMBOL_GPL(usb_interrupt_msg); 182 183 /** 184 + * usb_bulk_msg - Builds a bulk urb, sends it off and waits for completion 185 + * @usb_dev: pointer to the usb device to send the message to 186 + * @pipe: endpoint "pipe" to send the message to 187 + * @data: pointer to the data to send 188 + * @len: length in bytes of the data to send 189 + * @actual_length: pointer to a location to put the actual length transferred 190 + * in bytes 191 + * @timeout: time in msecs to wait for the message to complete before 192 + * timing out (if 0 the wait is forever) 193 * 194 + * Context: !in_interrupt () 195 * 196 + * This function sends a simple bulk message to a specified endpoint 197 + * and waits for the message to complete, or timeout. 198 * 199 + * If successful, it returns 0, otherwise a negative error number. The number 200 + * of actual bytes transferred will be stored in the actual_length paramater. 201 + * 202 + * Don't use this function from within an interrupt context, like a bottom half 203 + * handler. If you need an asynchronous message, or need to send a message 204 + * from within interrupt context, use usb_submit_urb() If a thread in your 205 + * driver uses this call, make sure your disconnect() method can wait for it to 206 + * complete. Since you don't have a handle on the URB used, you can't cancel 207 + * the request. 208 + * 209 + * Because there is no usb_interrupt_msg() and no USBDEVFS_INTERRUPT ioctl, 210 + * users are forced to abuse this routine by using it to submit URBs for 211 + * interrupt endpoints. We will take the liberty of creating an interrupt URB 212 + * (with the default interval) if the target is an interrupt endpoint. 213 */ 214 + int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe, 215 + void *data, int len, int *actual_length, int timeout) 216 { 217 struct urb *urb; 218 struct usb_host_endpoint *ep; ··· 242 243 /*-------------------------------------------------------------------*/ 244 245 + static void sg_clean(struct usb_sg_request *io) 246 { 247 if (io->urbs) { 248 while (io->entries--) 249 + usb_free_urb(io->urbs [io->entries]); 250 + kfree(io->urbs); 251 io->urbs = NULL; 252 } 253 if (io->dev->dev.dma_mask != NULL) 254 + usb_buffer_unmap_sg(io->dev, usb_pipein(io->pipe), 255 + io->sg, io->nents); 256 io->dev = NULL; 257 } 258 259 + static void sg_complete(struct urb *urb) 260 { 261 + struct usb_sg_request *io = urb->context; 262 int status = urb->status; 263 264 + spin_lock(&io->lock); 265 266 /* In 2.5 we require hcds' endpoint queues not to progress after fault 267 * reports, until the completion callback (this!) returns. That lets ··· 277 && (io->status != -ECONNRESET 278 || status != -ECONNRESET) 279 && urb->actual_length) { 280 + dev_err(io->dev->bus->controller, 281 "dev %s ep%d%s scatterlist error %d/%d\n", 282 io->dev->devpath, 283 usb_endpoint_num(&urb->ep->desc), 284 usb_urb_dir_in(urb) ? "in" : "out", 285 status, io->status); 286 + /* BUG (); */ 287 } 288 289 if (io->status == 0 && status && status != -ECONNRESET) { ··· 295 * unlink pending urbs so they won't rx/tx bad data. 296 * careful: unlink can sometimes be synchronous... 297 */ 298 + spin_unlock(&io->lock); 299 for (i = 0, found = 0; i < io->entries; i++) { 300 if (!io->urbs [i] || !io->urbs [i]->dev) 301 continue; 302 if (found) { 303 + retval = usb_unlink_urb(io->urbs [i]); 304 if (retval != -EINPROGRESS && 305 retval != -ENODEV && 306 retval != -EBUSY) 307 + dev_err(&io->dev->dev, 308 "%s, unlink --> %d\n", 309 __FUNCTION__, retval); 310 } else if (urb == io->urbs [i]) 311 found = 1; 312 } 313 + spin_lock(&io->lock); 314 } 315 urb->dev = NULL; 316 ··· 318 io->bytes += urb->actual_length; 319 io->count--; 320 if (!io->count) 321 + complete(&io->complete); 322 323 + spin_unlock(&io->lock); 324 } 325 326 ··· 349 * The request may be canceled with usb_sg_cancel(), either before or after 350 * usb_sg_wait() is called. 351 */ 352 + int usb_sg_init(struct usb_sg_request *io, struct usb_device *dev, 353 + unsigned pipe, unsigned period, struct scatterlist *sg, 354 + int nents, size_t length, gfp_t mem_flags) 355 { 356 + int i; 357 + int urb_flags; 358 + int dma; 359 360 if (!io || !dev || !sg 361 + || usb_pipecontrol(pipe) 362 + || usb_pipeisoc(pipe) 363 || nents <= 0) 364 return -EINVAL; 365 366 + spin_lock_init(&io->lock); 367 io->dev = dev; 368 io->pipe = pipe; 369 io->sg = sg; ··· 382 dma = (dev->dev.dma_mask != NULL); 383 if (dma) 384 io->entries = usb_buffer_map_sg(dev, usb_pipein(pipe), 385 + sg, nents); 386 else 387 io->entries = nents; 388 ··· 391 return io->entries; 392 393 io->count = io->entries; 394 + io->urbs = kmalloc(io->entries * sizeof *io->urbs, mem_flags); 395 if (!io->urbs) 396 goto nomem; 397 398 urb_flags = URB_NO_TRANSFER_DMA_MAP | URB_NO_INTERRUPT; 399 + if (usb_pipein(pipe)) 400 urb_flags |= URB_SHORT_NOT_OK; 401 402 for (i = 0; i < io->entries; i++) { 403 + unsigned len; 404 405 + io->urbs[i] = usb_alloc_urb(0, mem_flags); 406 + if (!io->urbs[i]) { 407 io->entries = i; 408 goto nomem; 409 } 410 411 + io->urbs[i]->dev = NULL; 412 + io->urbs[i]->pipe = pipe; 413 + io->urbs[i]->interval = period; 414 + io->urbs[i]->transfer_flags = urb_flags; 415 416 + io->urbs[i]->complete = sg_complete; 417 + io->urbs[i]->context = io; 418 419 /* 420 * Some systems need to revert to PIO when DMA is temporarily ··· 433 * to prevent stale pointers and to help spot bugs. 434 */ 435 if (dma) { 436 + io->urbs[i]->transfer_dma = sg_dma_address(sg + i); 437 + len = sg_dma_len(sg + i); 438 #if defined(CONFIG_HIGHMEM) || defined(CONFIG_GART_IOMMU) 439 io->urbs[i]->transfer_buffer = NULL; 440 #else ··· 442 #endif 443 } else { 444 /* hc may use _only_ transfer_buffer */ 445 + io->urbs[i]->transfer_buffer = sg_virt(&sg[i]); 446 + len = sg[i].length; 447 } 448 449 if (length) { 450 + len = min_t(unsigned, len, length); 451 length -= len; 452 if (length == 0) 453 io->entries = i + 1; 454 } 455 + io->urbs[i]->transfer_buffer_length = len; 456 } 457 + io->urbs[--i]->transfer_flags &= ~URB_NO_INTERRUPT; 458 459 /* transaction state */ 460 io->status = 0; 461 io->bytes = 0; 462 + init_completion(&io->complete); 463 return 0; 464 465 nomem: 466 + sg_clean(io); 467 return -ENOMEM; 468 } 469 EXPORT_SYMBOL_GPL(usb_sg_init); ··· 507 * speed interrupt endpoints, which allow at most one packet per millisecond, 508 * of at most 8 or 64 bytes (respectively). 509 */ 510 + void usb_sg_wait(struct usb_sg_request *io) 511 { 512 + int i; 513 + int entries = io->entries; 514 515 /* queue the urbs. */ 516 + spin_lock_irq(&io->lock); 517 i = 0; 518 while (i < entries && !io->status) { 519 + int retval; 520 521 + io->urbs[i]->dev = io->dev; 522 + retval = usb_submit_urb(io->urbs [i], GFP_ATOMIC); 523 524 /* after we submit, let completions or cancelations fire; 525 * we handshake using io->status. 526 */ 527 + spin_unlock_irq(&io->lock); 528 switch (retval) { 529 /* maybe we retrying will recover */ 530 + case -ENXIO: /* hc didn't queue this one */ 531 case -EAGAIN: 532 case -ENOMEM: 533 io->urbs[i]->dev = NULL; 534 retval = 0; 535 + yield(); 536 break; 537 538 /* no error? continue immediately. ··· 542 */ 543 case 0: 544 ++i; 545 + cpu_relax(); 546 break; 547 548 /* fail any uncompleted urbs */ 549 default: 550 + io->urbs[i]->dev = NULL; 551 + io->urbs[i]->status = retval; 552 + dev_dbg(&io->dev->dev, "%s, submit --> %d\n", 553 __FUNCTION__, retval); 554 + usb_sg_cancel(io); 555 } 556 + spin_lock_irq(&io->lock); 557 if (retval && (io->status == 0 || io->status == -ECONNRESET)) 558 io->status = retval; 559 } 560 io->count -= entries - i; 561 if (io->count == 0) 562 + complete(&io->complete); 563 + spin_unlock_irq(&io->lock); 564 565 /* OK, yes, this could be packaged as non-blocking. 566 * So could the submit loop above ... but it's easier to 567 * solve neither problem than to solve both! 568 */ 569 + wait_for_completion(&io->complete); 570 571 + sg_clean(io); 572 } 573 EXPORT_SYMBOL_GPL(usb_sg_wait); 574 ··· 580 * It can also prevents one initialized by usb_sg_init() from starting, 581 * so that call just frees resources allocated to the request. 582 */ 583 + void usb_sg_cancel(struct usb_sg_request *io) 584 { 585 + unsigned long flags; 586 587 + spin_lock_irqsave(&io->lock, flags); 588 589 /* shut everything down, if it didn't already */ 590 if (!io->status) { 591 + int i; 592 593 io->status = -ECONNRESET; 594 + spin_unlock(&io->lock); 595 for (i = 0; i < io->entries; i++) { 596 + int retval; 597 598 if (!io->urbs [i]->dev) 599 continue; 600 + retval = usb_unlink_urb(io->urbs [i]); 601 if (retval != -EINPROGRESS && retval != -EBUSY) 602 + dev_warn(&io->dev->dev, "%s, unlink --> %d\n", 603 __FUNCTION__, retval); 604 } 605 + spin_lock(&io->lock); 606 } 607 + spin_unlock_irqrestore(&io->lock, flags); 608 } 609 EXPORT_SYMBOL_GPL(usb_sg_cancel); 610 ··· 632 * Returns the number of bytes received on success, or else the status code 633 * returned by the underlying usb_control_msg() call. 634 */ 635 + int usb_get_descriptor(struct usb_device *dev, unsigned char type, 636 + unsigned char index, void *buf, int size) 637 { 638 int i; 639 int result; 640 + 641 + memset(buf, 0, size); /* Make sure we parse really received data */ 642 643 for (i = 0; i < 3; ++i) { 644 /* retry on length 0 or error; some devices are flakey */ ··· 712 } 713 714 static int usb_string_sub(struct usb_device *dev, unsigned int langid, 715 + unsigned int index, unsigned char *buf) 716 { 717 int rc; 718 ··· 755 * @buf: where to put the string 756 * @size: how big is "buf"? 757 * Context: !in_interrupt () 758 + * 759 * This converts the UTF-16LE encoded strings returned by devices, from 760 * usb_get_string_descriptor(), to null-terminated ISO-8859-1 encoded ones 761 * that are more usable in most kernel contexts. Note that all characters ··· 791 if (!dev->have_langid) { 792 err = usb_string_sub(dev, 0, 0, tbuf); 793 if (err < 0) { 794 + dev_err(&dev->dev, 795 "string descriptor 0 read error: %d\n", 796 err); 797 goto errout; 798 } else if (err < 4) { 799 + dev_err(&dev->dev, "string descriptor 0 too short\n"); 800 err = -EINVAL; 801 goto errout; 802 } else { 803 dev->have_langid = 1; 804 + dev->string_langid = tbuf[2] | (tbuf[3] << 8); 805 + /* always use the first langid listed */ 806 + dev_dbg(&dev->dev, "default language 0x%04x\n", 807 dev->string_langid); 808 } 809 } 810 + 811 err = usb_string_sub(dev, dev->string_langid, index, tbuf); 812 if (err < 0) 813 goto errout; ··· 825 err = idx; 826 827 if (tbuf[1] != USB_DT_STRING) 828 + dev_dbg(&dev->dev, 829 + "wrong descriptor type %02x for string %d (\"%s\")\n", 830 + tbuf[1], index, buf); 831 832 errout: 833 kfree(tbuf); ··· 847 char *smallbuf = NULL; 848 int len; 849 850 + if (index <= 0) 851 + return NULL; 852 + 853 + buf = kmalloc(256, GFP_KERNEL); 854 + if (buf) { 855 + len = usb_string(udev, index, buf, 256); 856 + if (len > 0) { 857 + smallbuf = kmalloc(++len, GFP_KERNEL); 858 + if (!smallbuf) 859 return buf; 860 memcpy(smallbuf, buf, len); 861 } ··· 888 return -ENOMEM; 889 890 ret = usb_get_descriptor(dev, USB_DT_DEVICE, 0, desc, size); 891 + if (ret >= 0) 892 memcpy(&dev->descriptor, desc, size); 893 kfree(desc); 894 return ret; ··· 961 { 962 int result; 963 int endp = usb_pipeendpoint(pipe); 964 + 965 + if (usb_pipein(pipe)) 966 endp |= USB_DIR_IN; 967 968 /* we don't care if it wasn't halted first. in fact some devices ··· 1045 } 1046 } 1047 1048 + /** 1049 * usb_disable_device - Disable all the endpoints for a USB device 1050 * @dev: the device whose endpoints are being disabled 1051 * @skip_ep0: 0 to disable endpoint 0, 1 to skip it. ··· 1060 int i; 1061 1062 dev_dbg(&dev->dev, "%s nuking %s URBs\n", __FUNCTION__, 1063 + skip_ep0 ? "non-ep0" : "all"); 1064 for (i = skip_ep0; i < 16; ++i) { 1065 usb_disable_endpoint(dev, i); 1066 usb_disable_endpoint(dev, i + USB_DIR_IN); ··· 1078 interface = dev->actconfig->interface[i]; 1079 if (!device_is_registered(&interface->dev)) 1080 continue; 1081 + dev_dbg(&dev->dev, "unregistering interface %s\n", 1082 interface->dev.bus_id); 1083 usb_remove_sysfs_intf_files(interface); 1084 + device_del(&interface->dev); 1085 } 1086 1087 /* Now that the interfaces are unbound, nobody should 1088 * try to access them. 1089 */ 1090 for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) { 1091 + put_device(&dev->actconfig->interface[i]->dev); 1092 dev->actconfig->interface[i] = NULL; 1093 } 1094 dev->actconfig = NULL; ··· 1097 } 1098 } 1099 1100 + /** 1101 * usb_enable_endpoint - Enable an endpoint for USB communications 1102 * @dev: the device whose interface is being enabled 1103 * @ep: the endpoint ··· 1123 ep->enabled = 1; 1124 } 1125 1126 + /** 1127 * usb_enable_interface - Enable all the endpoints for an interface 1128 * @dev: the device whose interface is being enabled 1129 * @intf: pointer to the interface descriptor ··· 1179 struct usb_host_interface *alt; 1180 int ret; 1181 int manual = 0; 1182 + unsigned int epaddr; 1183 + unsigned int pipe; 1184 1185 if (dev->state == USB_STATE_SUSPENDED) 1186 return -EHOSTUNREACH; ··· 1233 int i; 1234 1235 for (i = 0; i < alt->desc.bNumEndpoints; i++) { 1236 + epaddr = alt->endpoint[i].desc.bEndpointAddress; 1237 + pipe = __create_pipe(dev, 1238 + USB_ENDPOINT_NUMBER_MASK & epaddr) | 1239 + (usb_endpoint_out(epaddr) ? 1240 + USB_DIR_OUT : USB_DIR_IN); 1241 1242 usb_clear_halt(dev, pipe); 1243 } ··· 1366 return -ENOMEM; 1367 1368 if (add_uevent_var(env, 1369 + "MODALIAS=usb:" 1370 + "v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02Xic%02Xisc%02Xip%02X", 1371 le16_to_cpu(usb_dev->descriptor.idVendor), 1372 le16_to_cpu(usb_dev->descriptor.idProduct), 1373 le16_to_cpu(usb_dev->descriptor.bcdDevice), ··· 1396 }; 1397 1398 static struct usb_interface_assoc_descriptor *find_iad(struct usb_device *dev, 1399 + struct usb_host_config *config, 1400 + u8 inum) 1401 { 1402 struct usb_interface_assoc_descriptor *retval = NULL; 1403 struct usb_interface_assoc_descriptor *intf_assoc; ··· 1423 1424 return retval; 1425 } 1426 1427 /* 1428 * usb_set_configuration - Makes a particular device setting be current ··· 1542 * getting rid of old interfaces means unbinding their drivers. 1543 */ 1544 if (dev->state != USB_STATE_ADDRESS) 1545 + usb_disable_device(dev, 1); /* Skip ep0 */ 1546 1547 + ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 1548 + USB_REQ_SET_CONFIGURATION, 0, configuration, 0, 1549 + NULL, 0, USB_CTRL_SET_TIMEOUT); 1550 + if (ret < 0) { 1551 /* All the old state is gone, so what else can we do? 1552 * The device is probably useless now anyway. 1553 */ ··· 1594 intf->dev.bus = &usb_bus_type; 1595 intf->dev.type = &usb_if_device_type; 1596 intf->dev.dma_mask = dev->dev.dma_mask; 1597 + device_initialize(&intf->dev); 1598 mark_quiesced(intf); 1599 + sprintf(&intf->dev.bus_id[0], "%d-%s:%d.%d", 1600 + dev->bus->busnum, dev->devpath, 1601 + configuration, alt->desc.bInterfaceNumber); 1602 } 1603 kfree(new_interfaces); 1604 ··· 1614 for (i = 0; i < nintf; ++i) { 1615 struct usb_interface *intf = cp->interface[i]; 1616 1617 + dev_dbg(&dev->dev, 1618 "adding %s (config #%d, interface %d)\n", 1619 intf->dev.bus_id, configuration, 1620 intf->cur_altsetting->desc.bInterfaceNumber); 1621 + ret = device_add(&intf->dev); 1622 if (ret != 0) { 1623 dev_err(&dev->dev, "device_add(%s) --> %d\n", 1624 intf->dev.bus_id, ret);