Merge tag 'usb-4.10-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb

Pull USB fixes from Greg KH:
"Here are a bunch of USB fixes for 4.10-rc3. Yeah, it's a lot, an
artifact of the holiday break I think.

Lots of gadget and the usual XHCI fixups for reported issues (one day
that driver will calm down...) Also included are a bunch of usb-serial
driver fixes, and for good measure, a number of much-reported MUSB
driver issues have finally been resolved.

All of these have been in linux-next with no reported issues"

* tag 'usb-4.10-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: (72 commits)
USB: fix problems with duplicate endpoint addresses
usb: ohci-at91: use descriptor-based gpio APIs correctly
usb: storage: unusual_uas: Add JMicron JMS56x to unusual device
usb: hub: Move hub_port_disable() to fix warning if PM is disabled
usb: musb: blackfin: add bfin_fifo_offset in bfin_ops
usb: musb: fix compilation warning on unused function
usb: musb: Fix trying to free already-free IRQ 4
usb: musb: dsps: implement clear_ep_rxintr() callback
usb: musb: core: add clear_ep_rxintr() to musb_platform_ops
USB: serial: ti_usb_3410_5052: fix NULL-deref at open
USB: serial: spcp8x5: fix NULL-deref at open
USB: serial: quatech2: fix sleep-while-atomic in close
USB: serial: pl2303: fix NULL-deref at open
USB: serial: oti6858: fix NULL-deref at open
USB: serial: omninet: fix NULL-derefs at open and disconnect
USB: serial: mos7840: fix misleading interrupt-URB comment
USB: serial: mos7840: remove unused write URB
USB: serial: mos7840: fix NULL-deref at open
USB: serial: mos7720: remove obsolete port initialisation
USB: serial: mos7720: fix parallel probe
...

+10
drivers/usb/core/config.c
··· 239 239 if (ifp->desc.bNumEndpoints >= num_ep) 240 240 goto skip_to_next_endpoint_or_interface_descriptor; 241 241 242 + /* Check for duplicate endpoint addresses */ 243 + for (i = 0; i < ifp->desc.bNumEndpoints; ++i) { 244 + if (ifp->endpoint[i].desc.bEndpointAddress == 245 + d->bEndpointAddress) { 246 + dev_warn(ddev, "config %d interface %d altsetting %d has a duplicate endpoint with address 0x%X, skipping\n", 247 + cfgno, inum, asnum, d->bEndpointAddress); 248 + goto skip_to_next_endpoint_or_interface_descriptor; 249 + } 250 + } 251 + 242 252 endpoint = &ifp->endpoint[ifp->desc.bNumEndpoints]; 243 253 ++ifp->desc.bNumEndpoints; 244 254
+29 -30
drivers/usb/core/hub.c
··· 103 103 104 104 static void hub_release(struct kref *kref); 105 105 static int usb_reset_and_verify_device(struct usb_device *udev); 106 - static void hub_usb3_port_prepare_disable(struct usb_hub *hub, 107 - struct usb_port *port_dev); 106 + static int hub_port_disable(struct usb_hub *hub, int port1, int set_state); 108 107 109 108 static inline char *portspeed(struct usb_hub *hub, int portstatus) 110 109 { ··· 899 900 return set_port_feature(hub->hdev, 900 901 port1 | (link_status << 3), 901 902 USB_PORT_FEAT_LINK_STATE); 902 - } 903 - 904 - /* 905 - * USB-3 does not have a similar link state as USB-2 that will avoid negotiating 906 - * a connection with a plugged-in cable but will signal the host when the cable 907 - * is unplugged. Disable remote wake and set link state to U3 for USB-3 devices 908 - */ 909 - static int hub_port_disable(struct usb_hub *hub, int port1, int set_state) 910 - { 911 - struct usb_port *port_dev = hub->ports[port1 - 1]; 912 - struct usb_device *hdev = hub->hdev; 913 - int ret = 0; 914 - 915 - if (!hub->error) { 916 - if (hub_is_superspeed(hub->hdev)) { 917 - hub_usb3_port_prepare_disable(hub, port_dev); 918 - ret = hub_set_port_link_state(hub, port_dev->portnum, 919 - USB_SS_PORT_LS_U3); 920 - } else { 921 - ret = usb_clear_port_feature(hdev, port1, 922 - USB_PORT_FEAT_ENABLE); 923 - } 924 - } 925 - if (port_dev->child && set_state) 926 - usb_set_device_state(port_dev->child, USB_STATE_NOTATTACHED); 927 - if (ret && ret != -ENODEV) 928 - dev_err(&port_dev->dev, "cannot disable (err = %d)\n", ret); 929 - return ret; 930 903 } 931 904 932 905 /* ··· 4132 4161 } 4133 4162 4134 4163 #endif /* CONFIG_PM */ 4164 + 4165 + /* 4166 + * USB-3 does not have a similar link state as USB-2 that will avoid negotiating 4167 + * a connection with a plugged-in cable but will signal the host when the cable 4168 + * is unplugged. Disable remote wake and set link state to U3 for USB-3 devices 4169 + */ 4170 + static int hub_port_disable(struct usb_hub *hub, int port1, int set_state) 4171 + { 4172 + struct usb_port *port_dev = hub->ports[port1 - 1]; 4173 + struct usb_device *hdev = hub->hdev; 4174 + int ret = 0; 4175 + 4176 + if (!hub->error) { 4177 + if (hub_is_superspeed(hub->hdev)) { 4178 + hub_usb3_port_prepare_disable(hub, port_dev); 4179 + ret = hub_set_port_link_state(hub, port_dev->portnum, 4180 + USB_SS_PORT_LS_U3); 4181 + } else { 4182 + ret = usb_clear_port_feature(hdev, port1, 4183 + USB_PORT_FEAT_ENABLE); 4184 + } 4185 + } 4186 + if (port_dev->child && set_state) 4187 + usb_set_device_state(port_dev->child, USB_STATE_NOTATTACHED); 4188 + if (ret && ret != -ENODEV) 4189 + dev_err(&port_dev->dev, "cannot disable (err = %d)\n", ret); 4190 + return ret; 4191 + } 4135 4192 4136 4193 4137 4194 /* USB 2.0 spec, 7.1.7.3 / fig 7-29:
+1 -1
drivers/usb/dwc2/gadget.c
··· 3753 3753 hs_ep->desc_list = dma_alloc_coherent(hsotg->dev, 3754 3754 MAX_DMA_DESC_NUM_GENERIC * 3755 3755 sizeof(struct dwc2_dma_desc), 3756 - &hs_ep->desc_list_dma, GFP_KERNEL); 3756 + &hs_ep->desc_list_dma, GFP_ATOMIC); 3757 3757 if (!hs_ep->desc_list) { 3758 3758 ret = -ENOMEM; 3759 3759 goto error2;
+9 -21
drivers/usb/dwc2/params.c
··· 247 247 static void dwc2_get_device_property(struct dwc2_hsotg *hsotg, 248 248 char *property, u8 size, u64 *value) 249 249 { 250 - u8 val8; 251 - u16 val16; 252 250 u32 val32; 253 251 254 252 switch (size) { ··· 254 256 *value = device_property_read_bool(hsotg->dev, property); 255 257 break; 256 258 case 1: 257 - if (device_property_read_u8(hsotg->dev, property, &val8)) 258 - return; 259 - 260 - *value = val8; 261 - break; 262 259 case 2: 263 - if (device_property_read_u16(hsotg->dev, property, &val16)) 264 - return; 265 - 266 - *value = val16; 267 - break; 268 260 case 4: 269 261 if (device_property_read_u32(hsotg->dev, property, &val32)) 270 262 return; ··· 1088 1100 /* Buffer DMA */ 1089 1101 dwc2_set_param_bool(hsotg, &p->g_dma, 1090 1102 false, "gadget-dma", 1091 - true, false, 1103 + dma_capable, false, 1092 1104 dma_capable); 1093 1105 1094 1106 /* DMA Descriptor */ 1095 1107 dwc2_set_param_bool(hsotg, &p->g_dma_desc, false, 1096 1108 "gadget-dma-desc", 1097 - p->g_dma, false, 1109 + !!hw->dma_desc_enable, false, 1098 1110 !!hw->dma_desc_enable); 1099 1111 } 1100 1112 ··· 1118 1130 1119 1131 dwc2_set_param_bool(hsotg, &p->host_dma, 1120 1132 false, "host-dma", 1121 - true, false, 1133 + dma_capable, false, 1122 1134 dma_capable); 1135 + dwc2_set_param_host_rx_fifo_size(hsotg, 1136 + params->host_rx_fifo_size); 1137 + dwc2_set_param_host_nperio_tx_fifo_size(hsotg, 1138 + params->host_nperio_tx_fifo_size); 1139 + dwc2_set_param_host_perio_tx_fifo_size(hsotg, 1140 + params->host_perio_tx_fifo_size); 1123 1141 } 1124 1142 dwc2_set_param_dma_desc_enable(hsotg, params->dma_desc_enable); 1125 1143 dwc2_set_param_dma_desc_fs_enable(hsotg, params->dma_desc_fs_enable); ··· 1134 1140 params->host_support_fs_ls_low_power); 1135 1141 dwc2_set_param_enable_dynamic_fifo(hsotg, 1136 1142 params->enable_dynamic_fifo); 1137 - dwc2_set_param_host_rx_fifo_size(hsotg, 1138 - params->host_rx_fifo_size); 1139 - dwc2_set_param_host_nperio_tx_fifo_size(hsotg, 1140 - params->host_nperio_tx_fifo_size); 1141 - dwc2_set_param_host_perio_tx_fifo_size(hsotg, 1142 - params->host_perio_tx_fifo_size); 1143 1143 dwc2_set_param_max_transfer_size(hsotg, 1144 1144 params->max_transfer_size); 1145 1145 dwc2_set_param_max_packet_count(hsotg,
+3 -7
drivers/usb/dwc3/core.h
··· 45 45 #define DWC3_XHCI_RESOURCES_NUM 2 46 46 47 47 #define DWC3_SCRATCHBUF_SIZE 4096 /* each buffer is assumed to be 4KiB */ 48 - #define DWC3_EVENT_SIZE 4 /* bytes */ 49 - #define DWC3_EVENT_MAX_NUM 64 /* 2 events/endpoint */ 50 - #define DWC3_EVENT_BUFFERS_SIZE (DWC3_EVENT_SIZE * DWC3_EVENT_MAX_NUM) 48 + #define DWC3_EVENT_BUFFERS_SIZE 4096 51 49 #define DWC3_EVENT_TYPE_MASK 0xfe 52 50 53 51 #define DWC3_EVENT_TYPE_DEV 0 ··· 309 311 #define DWC3_DCFG_SUPERSPEED_PLUS (5 << 0) /* DWC_usb31 only */ 310 312 #define DWC3_DCFG_SUPERSPEED (4 << 0) 311 313 #define DWC3_DCFG_HIGHSPEED (0 << 0) 312 - #define DWC3_DCFG_FULLSPEED2 (1 << 0) 314 + #define DWC3_DCFG_FULLSPEED (1 << 0) 313 315 #define DWC3_DCFG_LOWSPEED (2 << 0) 314 - #define DWC3_DCFG_FULLSPEED1 (3 << 0) 315 316 316 317 #define DWC3_DCFG_NUMP_SHIFT 17 317 318 #define DWC3_DCFG_NUMP(n) (((n) >> DWC3_DCFG_NUMP_SHIFT) & 0x1f) ··· 402 405 #define DWC3_DSTS_SUPERSPEED_PLUS (5 << 0) /* DWC_usb31 only */ 403 406 #define DWC3_DSTS_SUPERSPEED (4 << 0) 404 407 #define DWC3_DSTS_HIGHSPEED (0 << 0) 405 - #define DWC3_DSTS_FULLSPEED2 (1 << 0) 408 + #define DWC3_DSTS_FULLSPEED (1 << 0) 406 409 #define DWC3_DSTS_LOWSPEED (2 << 0) 407 - #define DWC3_DSTS_FULLSPEED1 (3 << 0) 408 410 409 411 /* Device Generic Command Register */ 410 412 #define DWC3_DGCMD_SET_LMP 0x01
+4 -2
drivers/usb/dwc3/dwc3-omap.c
··· 19 19 #include <linux/module.h> 20 20 #include <linux/kernel.h> 21 21 #include <linux/slab.h> 22 + #include <linux/irq.h> 22 23 #include <linux/interrupt.h> 23 24 #include <linux/platform_device.h> 24 25 #include <linux/platform_data/dwc3-omap.h> ··· 511 510 512 511 /* check the DMA Status */ 513 512 reg = dwc3_omap_readl(omap->base, USBOTGSS_SYSCONFIG); 514 - 513 + irq_set_status_flags(omap->irq, IRQ_NOAUTOEN); 515 514 ret = devm_request_threaded_irq(dev, omap->irq, dwc3_omap_interrupt, 516 515 dwc3_omap_interrupt_thread, IRQF_SHARED, 517 516 "dwc3-omap", omap); ··· 532 531 } 533 532 534 533 dwc3_omap_enable_irqs(omap); 535 - 534 + enable_irq(omap->irq); 536 535 return 0; 537 536 538 537 err2: ··· 553 552 extcon_unregister_notifier(omap->edev, EXTCON_USB, &omap->vbus_nb); 554 553 extcon_unregister_notifier(omap->edev, EXTCON_USB_HOST, &omap->id_nb); 555 554 dwc3_omap_disable_irqs(omap); 555 + disable_irq(omap->irq); 556 556 of_platform_depopulate(omap->dev); 557 557 pm_runtime_put_sync(&pdev->dev); 558 558 pm_runtime_disable(&pdev->dev);
+6 -11
drivers/usb/dwc3/dwc3-pci.c
··· 38 38 #define PCI_DEVICE_ID_INTEL_BXT_M 0x1aaa 39 39 #define PCI_DEVICE_ID_INTEL_APL 0x5aaa 40 40 #define PCI_DEVICE_ID_INTEL_KBP 0xa2b0 41 + #define PCI_DEVICE_ID_INTEL_GLK 0x31aa 41 42 42 43 #define PCI_INTEL_BXT_DSM_UUID "732b85d5-b7a7-4a1b-9ba0-4bbd00ffd511" 43 44 #define PCI_INTEL_BXT_FUNC_PMU_PWR 4 ··· 74 73 { 75 74 struct platform_device *dwc3 = dwc->dwc3; 76 75 struct pci_dev *pdev = dwc->pci; 77 - int ret; 78 - 79 - struct property_entry sysdev_property[] = { 80 - PROPERTY_ENTRY_BOOL("linux,sysdev_is_parent"), 81 - { }, 82 - }; 83 - 84 - ret = platform_device_add_properties(dwc3, sysdev_property); 85 - if (ret) 86 - return ret; 87 76 88 77 if (pdev->vendor == PCI_VENDOR_ID_AMD && 89 78 pdev->device == PCI_DEVICE_ID_AMD_NL_USB) { ··· 96 105 PROPERTY_ENTRY_BOOL("snps,disable_scramble_quirk"), 97 106 PROPERTY_ENTRY_BOOL("snps,dis_u3_susphy_quirk"), 98 107 PROPERTY_ENTRY_BOOL("snps,dis_u2_susphy_quirk"), 108 + PROPERTY_ENTRY_BOOL("linux,sysdev_is_parent"), 99 109 { }, 100 110 }; 101 111 ··· 107 115 int ret; 108 116 109 117 struct property_entry properties[] = { 110 - PROPERTY_ENTRY_STRING("dr-mode", "peripheral"), 118 + PROPERTY_ENTRY_STRING("dr_mode", "peripheral"), 119 + PROPERTY_ENTRY_BOOL("linux,sysdev_is_parent"), 111 120 { } 112 121 }; 113 122 ··· 160 167 PROPERTY_ENTRY_BOOL("snps,usb3_lpm_capable"), 161 168 PROPERTY_ENTRY_BOOL("snps,has-lpm-erratum"), 162 169 PROPERTY_ENTRY_BOOL("snps,dis_enblslpm_quirk"), 170 + PROPERTY_ENTRY_BOOL("linux,sysdev_is_parent"), 163 171 { }, 164 172 }; 165 173 ··· 268 274 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BXT_M), }, 269 275 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_APL), }, 270 276 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_KBP), }, 277 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_GLK), }, 271 278 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_NL_USB), }, 272 279 { } /* Terminating Entry */ 273 280 };
+27 -19
drivers/usb/dwc3/ep0.c
··· 39 39 static void __dwc3_ep0_do_control_data(struct dwc3 *dwc, 40 40 struct dwc3_ep *dep, struct dwc3_request *req); 41 41 42 - static int dwc3_ep0_start_trans(struct dwc3 *dwc, u8 epnum, dma_addr_t buf_dma, 43 - u32 len, u32 type, bool chain) 42 + static void dwc3_ep0_prepare_one_trb(struct dwc3 *dwc, u8 epnum, 43 + dma_addr_t buf_dma, u32 len, u32 type, bool chain) 44 44 { 45 - struct dwc3_gadget_ep_cmd_params params; 46 45 struct dwc3_trb *trb; 47 46 struct dwc3_ep *dep; 48 47 49 - int ret; 50 - 51 48 dep = dwc->eps[epnum]; 52 - if (dep->flags & DWC3_EP_BUSY) 53 - return 0; 54 49 55 50 trb = &dwc->ep0_trb[dep->trb_enqueue]; 56 51 ··· 66 71 trb->ctrl |= (DWC3_TRB_CTRL_IOC 67 72 | DWC3_TRB_CTRL_LST); 68 73 69 - if (chain) 74 + trace_dwc3_prepare_trb(dep, trb); 75 + } 76 + 77 + static int dwc3_ep0_start_trans(struct dwc3 *dwc, u8 epnum) 78 + { 79 + struct dwc3_gadget_ep_cmd_params params; 80 + struct dwc3_ep *dep; 81 + int ret; 82 + 83 + dep = dwc->eps[epnum]; 84 + if (dep->flags & DWC3_EP_BUSY) 70 85 return 0; 71 86 72 87 memset(&params, 0, sizeof(params)); 73 88 params.param0 = upper_32_bits(dwc->ep0_trb_addr); 74 89 params.param1 = lower_32_bits(dwc->ep0_trb_addr); 75 - 76 - trace_dwc3_prepare_trb(dep, trb); 77 90 78 91 ret = dwc3_send_gadget_ep_cmd(dep, DWC3_DEPCMD_STARTTRANSFER, &params); 79 92 if (ret < 0) ··· 283 280 284 281 complete(&dwc->ep0_in_setup); 285 282 286 - ret = dwc3_ep0_start_trans(dwc, 0, dwc->ctrl_req_addr, 8, 283 + dwc3_ep0_prepare_one_trb(dwc, 0, dwc->ctrl_req_addr, 8, 287 284 DWC3_TRBCTL_CONTROL_SETUP, false); 285 + ret = dwc3_ep0_start_trans(dwc, 0); 288 286 WARN_ON(ret < 0); 289 287 } 290 288 ··· 916 912 917 913 dwc->ep0_next_event = DWC3_EP0_COMPLETE; 918 914 919 - ret = dwc3_ep0_start_trans(dwc, epnum, 920 - dwc->ctrl_req_addr, 0, 921 - DWC3_TRBCTL_CONTROL_DATA, false); 915 + dwc3_ep0_prepare_one_trb(dwc, epnum, dwc->ctrl_req_addr, 916 + 0, DWC3_TRBCTL_CONTROL_DATA, false); 917 + ret = dwc3_ep0_start_trans(dwc, epnum); 922 918 WARN_ON(ret < 0); 923 919 } 924 920 } ··· 997 993 req->direction = !!dep->number; 998 994 999 995 if (req->request.length == 0) { 1000 - ret = dwc3_ep0_start_trans(dwc, dep->number, 996 + dwc3_ep0_prepare_one_trb(dwc, dep->number, 1001 997 dwc->ctrl_req_addr, 0, 1002 998 DWC3_TRBCTL_CONTROL_DATA, false); 999 + ret = dwc3_ep0_start_trans(dwc, dep->number); 1003 1000 } else if (!IS_ALIGNED(req->request.length, dep->endpoint.maxpacket) 1004 1001 && (dep->number == 0)) { 1005 1002 u32 transfer_size = 0; ··· 1016 1011 if (req->request.length > DWC3_EP0_BOUNCE_SIZE) { 1017 1012 transfer_size = ALIGN(req->request.length - maxpacket, 1018 1013 maxpacket); 1019 - ret = dwc3_ep0_start_trans(dwc, dep->number, 1014 + dwc3_ep0_prepare_one_trb(dwc, dep->number, 1020 1015 req->request.dma, 1021 1016 transfer_size, 1022 1017 DWC3_TRBCTL_CONTROL_DATA, ··· 1028 1023 1029 1024 dwc->ep0_bounced = true; 1030 1025 1031 - ret = dwc3_ep0_start_trans(dwc, dep->number, 1026 + dwc3_ep0_prepare_one_trb(dwc, dep->number, 1032 1027 dwc->ep0_bounce_addr, transfer_size, 1033 1028 DWC3_TRBCTL_CONTROL_DATA, false); 1029 + ret = dwc3_ep0_start_trans(dwc, dep->number); 1034 1030 } else { 1035 1031 ret = usb_gadget_map_request_by_dev(dwc->sysdev, 1036 1032 &req->request, dep->number); 1037 1033 if (ret) 1038 1034 return; 1039 1035 1040 - ret = dwc3_ep0_start_trans(dwc, dep->number, req->request.dma, 1036 + dwc3_ep0_prepare_one_trb(dwc, dep->number, req->request.dma, 1041 1037 req->request.length, DWC3_TRBCTL_CONTROL_DATA, 1042 1038 false); 1039 + ret = dwc3_ep0_start_trans(dwc, dep->number); 1043 1040 } 1044 1041 1045 1042 WARN_ON(ret < 0); ··· 1055 1048 type = dwc->three_stage_setup ? DWC3_TRBCTL_CONTROL_STATUS3 1056 1049 : DWC3_TRBCTL_CONTROL_STATUS2; 1057 1050 1058 - return dwc3_ep0_start_trans(dwc, dep->number, 1051 + dwc3_ep0_prepare_one_trb(dwc, dep->number, 1059 1052 dwc->ctrl_req_addr, 0, type, false); 1053 + return dwc3_ep0_start_trans(dwc, dep->number); 1060 1054 } 1061 1055 1062 1056 static void __dwc3_ep0_do_control_status(struct dwc3 *dwc, struct dwc3_ep *dep)
+14 -10
drivers/usb/dwc3/gadget.c
··· 180 180 if (req->request.status == -EINPROGRESS) 181 181 req->request.status = status; 182 182 183 - if (dwc->ep0_bounced && dep->number == 0) 183 + if (dwc->ep0_bounced && dep->number <= 1) 184 184 dwc->ep0_bounced = false; 185 - else 186 - usb_gadget_unmap_request_by_dev(dwc->sysdev, 187 - &req->request, req->direction); 185 + 186 + usb_gadget_unmap_request_by_dev(dwc->sysdev, 187 + &req->request, req->direction); 188 188 189 189 trace_dwc3_gadget_giveback(req); 190 190 ··· 1720 1720 reg |= DWC3_DCFG_LOWSPEED; 1721 1721 break; 1722 1722 case USB_SPEED_FULL: 1723 - reg |= DWC3_DCFG_FULLSPEED1; 1723 + reg |= DWC3_DCFG_FULLSPEED; 1724 1724 break; 1725 1725 case USB_SPEED_HIGH: 1726 1726 reg |= DWC3_DCFG_HIGHSPEED; ··· 2232 2232 2233 2233 dep = dwc->eps[epnum]; 2234 2234 2235 - if (!(dep->flags & DWC3_EP_ENABLED) && 2236 - !(dep->flags & DWC3_EP_END_TRANSFER_PENDING)) 2237 - return; 2235 + if (!(dep->flags & DWC3_EP_ENABLED)) { 2236 + if (!(dep->flags & DWC3_EP_END_TRANSFER_PENDING)) 2237 + return; 2238 + 2239 + /* Handle only EPCMDCMPLT when EP disabled */ 2240 + if (event->endpoint_event != DWC3_DEPEVT_EPCMDCMPLT) 2241 + return; 2242 + } 2238 2243 2239 2244 if (epnum == 0 || epnum == 1) { 2240 2245 dwc3_ep0_interrupt(dwc, event); ··· 2536 2531 dwc->gadget.ep0->maxpacket = 64; 2537 2532 dwc->gadget.speed = USB_SPEED_HIGH; 2538 2533 break; 2539 - case DWC3_DSTS_FULLSPEED2: 2540 - case DWC3_DSTS_FULLSPEED1: 2534 + case DWC3_DSTS_FULLSPEED: 2541 2535 dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(64); 2542 2536 dwc->gadget.ep0->maxpacket = 64; 2543 2537 dwc->gadget.speed = USB_SPEED_FULL;
+8 -4
drivers/usb/gadget/composite.c
··· 1694 1694 value = min(w_length, (u16) 1); 1695 1695 break; 1696 1696 1697 - /* function drivers must handle get/set altsetting; if there's 1698 - * no get() method, we know only altsetting zero works. 1699 - */ 1697 + /* function drivers must handle get/set altsetting */ 1700 1698 case USB_REQ_SET_INTERFACE: 1701 1699 if (ctrl->bRequestType != USB_RECIP_INTERFACE) 1702 1700 goto unknown; ··· 1703 1705 f = cdev->config->interface[intf]; 1704 1706 if (!f) 1705 1707 break; 1706 - if (w_value && !f->set_alt) 1708 + 1709 + /* 1710 + * If there's no get_alt() method, we know only altsetting zero 1711 + * works. There is no need to check if set_alt() is not NULL 1712 + * as we check this in usb_add_function(). 1713 + */ 1714 + if (w_value && !f->get_alt) 1707 1715 break; 1708 1716 value = f->set_alt(f, w_index, w_value); 1709 1717 if (value == USB_GADGET_DELAYED_STATUS) {
+9 -5
drivers/usb/gadget/function/f_fs.c
··· 2091 2091 2092 2092 case FFS_STRING: 2093 2093 /* 2094 - * Strings are indexed from 1 (0 is magic ;) reserved 2095 - * for languages list or some such) 2094 + * Strings are indexed from 1 (0 is reserved 2095 + * for languages list) 2096 2096 */ 2097 2097 if (*valuep > helper->ffs->strings_count) 2098 2098 helper->ffs->strings_count = *valuep; ··· 2252 2252 2253 2253 if (len < sizeof(*d) || 2254 2254 d->bFirstInterfaceNumber >= ffs->interfaces_count || 2255 - !d->Reserved1) 2255 + d->Reserved1) 2256 2256 return -EINVAL; 2257 2257 for (i = 0; i < ARRAY_SIZE(d->Reserved2); ++i) 2258 2258 if (d->Reserved2[i]) ··· 3666 3666 { 3667 3667 struct ffs_dev *ffs_obj; 3668 3668 struct f_fs_opts *opts; 3669 + struct config_item *ci; 3669 3670 3670 3671 ENTER(); 3671 3672 ffs_dev_lock(); ··· 3690 3689 || !atomic_read(&opts->func_inst.group.cg_item.ci_kref.refcount)) 3691 3690 goto done; 3692 3691 3693 - unregister_gadget_item(ffs_obj->opts-> 3694 - func_inst.group.cg_item.ci_parent->ci_parent); 3692 + ci = opts->func_inst.group.cg_item.ci_parent->ci_parent; 3693 + ffs_dev_unlock(); 3694 + 3695 + unregister_gadget_item(ci); 3696 + return; 3695 3697 done: 3696 3698 ffs_dev_unlock(); 3697 3699 }
+1 -1
drivers/usb/gadget/function/f_hid.c
··· 593 593 } 594 594 status = usb_ep_enable(hidg->out_ep); 595 595 if (status < 0) { 596 - ERROR(cdev, "Enable IN endpoint FAILED!\n"); 596 + ERROR(cdev, "Enable OUT endpoint FAILED!\n"); 597 597 goto fail; 598 598 } 599 599 hidg->out_ep->driver_data = hidg;
+12 -6
drivers/usb/gadget/legacy/inode.c
··· 1126 1126 /* data and/or status stage for control request */ 1127 1127 } else if (dev->state == STATE_DEV_SETUP) { 1128 1128 1129 - /* IN DATA+STATUS caller makes len <= wLength */ 1129 + len = min_t(size_t, len, dev->setup_wLength); 1130 1130 if (dev->setup_in) { 1131 1131 retval = setup_req (dev->gadget->ep0, dev->req, len); 1132 1132 if (retval == 0) { ··· 1734 1734 * such as configuration notifications. 1735 1735 */ 1736 1736 1737 - static int is_valid_config (struct usb_config_descriptor *config) 1737 + static int is_valid_config(struct usb_config_descriptor *config, 1738 + unsigned int total) 1738 1739 { 1739 1740 return config->bDescriptorType == USB_DT_CONFIG 1740 1741 && config->bLength == USB_DT_CONFIG_SIZE 1742 + && total >= USB_DT_CONFIG_SIZE 1741 1743 && config->bConfigurationValue != 0 1742 1744 && (config->bmAttributes & USB_CONFIG_ATT_ONE) != 0 1743 1745 && (config->bmAttributes & USB_CONFIG_ATT_WAKEUP) == 0; ··· 1764 1762 } 1765 1763 spin_unlock_irq(&dev->lock); 1766 1764 1767 - if (len < (USB_DT_CONFIG_SIZE + USB_DT_DEVICE_SIZE + 4)) 1765 + if ((len < (USB_DT_CONFIG_SIZE + USB_DT_DEVICE_SIZE + 4)) || 1766 + (len > PAGE_SIZE * 4)) 1768 1767 return -EINVAL; 1769 1768 1770 1769 /* we might need to change message format someday */ ··· 1789 1786 /* full or low speed config */ 1790 1787 dev->config = (void *) kbuf; 1791 1788 total = le16_to_cpu(dev->config->wTotalLength); 1792 - if (!is_valid_config (dev->config) || total >= length) 1789 + if (!is_valid_config(dev->config, total) || 1790 + total > length - USB_DT_DEVICE_SIZE) 1793 1791 goto fail; 1794 1792 kbuf += total; 1795 1793 length -= total; ··· 1799 1795 if (kbuf [1] == USB_DT_CONFIG) { 1800 1796 dev->hs_config = (void *) kbuf; 1801 1797 total = le16_to_cpu(dev->hs_config->wTotalLength); 1802 - if (!is_valid_config (dev->hs_config) || total >= length) 1798 + if (!is_valid_config(dev->hs_config, total) || 1799 + total > length - USB_DT_DEVICE_SIZE) 1803 1800 goto fail; 1804 1801 kbuf += total; 1805 1802 length -= total; 1803 + } else { 1804 + dev->hs_config = NULL; 1806 1805 } 1807 1806 1808 1807 /* could support multiple configs, using another encoding! */ ··· 1818 1811 || dev->dev->bDescriptorType != USB_DT_DEVICE 1819 1812 || dev->dev->bNumConfigurations != 1) 1820 1813 goto fail; 1821 - dev->dev->bNumConfigurations = 1; 1822 1814 dev->dev->bcdUSB = cpu_to_le16 (0x0200); 1823 1815 1824 1816 /* triggers gadgetfs_bind(); then we can enumerate. */
+5 -1
drivers/usb/gadget/udc/core.c
··· 1317 1317 if (!ret) 1318 1318 break; 1319 1319 } 1320 - if (!ret && !udc->driver) 1320 + if (ret) 1321 + ret = -ENODEV; 1322 + else if (udc->driver) 1323 + ret = -EBUSY; 1324 + else 1321 1325 goto found; 1322 1326 } else { 1323 1327 list_for_each_entry(udc, &udc_list, list) {
+3 -3
drivers/usb/gadget/udc/dummy_hcd.c
··· 330 330 /* caller must hold lock */ 331 331 static void stop_activity(struct dummy *dum) 332 332 { 333 - struct dummy_ep *ep; 333 + int i; 334 334 335 335 /* prevent any more requests */ 336 336 dum->address = 0; ··· 338 338 /* The timer is left running so that outstanding URBs can fail */ 339 339 340 340 /* nuke any pending requests first, so driver i/o is quiesced */ 341 - list_for_each_entry(ep, &dum->gadget.ep_list, ep.ep_list) 342 - nuke(dum, ep); 341 + for (i = 0; i < DUMMY_ENDPOINTS; ++i) 342 + nuke(dum, &dum->ep[i]); 343 343 344 344 /* driver now does any non-usb quiescing necessary */ 345 345 }
+10 -14
drivers/usb/host/ohci-at91.c
··· 43 43 struct gpio_desc *overcurrent_pin[AT91_MAX_USBH_PORTS]; 44 44 u8 ports; /* number of ports on root hub */ 45 45 u8 overcurrent_supported; 46 - u8 vbus_pin_active_low[AT91_MAX_USBH_PORTS]; 47 46 u8 overcurrent_status[AT91_MAX_USBH_PORTS]; 48 47 u8 overcurrent_changed[AT91_MAX_USBH_PORTS]; 49 48 }; ··· 265 266 if (!valid_port(port)) 266 267 return; 267 268 268 - gpiod_set_value(pdata->vbus_pin[port], 269 - pdata->vbus_pin_active_low[port] ^ enable); 269 + gpiod_set_value(pdata->vbus_pin[port], enable); 270 270 } 271 271 272 272 static int ohci_at91_usb_get_power(struct at91_usbh_data *pdata, int port) ··· 273 275 if (!valid_port(port)) 274 276 return -EINVAL; 275 277 276 - return gpiod_get_value(pdata->vbus_pin[port]) ^ 277 - pdata->vbus_pin_active_low[port]; 278 + return gpiod_get_value(pdata->vbus_pin[port]); 278 279 } 279 280 280 281 /* ··· 530 533 pdata->ports = ports; 531 534 532 535 at91_for_each_port(i) { 533 - pdata->vbus_pin[i] = devm_gpiod_get_optional(&pdev->dev, 534 - "atmel,vbus-gpio", 535 - GPIOD_IN); 536 + if (i >= pdata->ports) 537 + break; 538 + 539 + pdata->vbus_pin[i] = 540 + devm_gpiod_get_index_optional(&pdev->dev, "atmel,vbus", 541 + i, GPIOD_OUT_HIGH); 536 542 if (IS_ERR(pdata->vbus_pin[i])) { 537 543 err = PTR_ERR(pdata->vbus_pin[i]); 538 544 dev_err(&pdev->dev, "unable to claim gpio \"vbus\": %d\n", err); 539 545 continue; 540 546 } 541 - 542 - pdata->vbus_pin_active_low[i] = gpiod_get_value(pdata->vbus_pin[i]); 543 - 544 - ohci_at91_usb_set_power(pdata, i, 1); 545 547 } 546 548 547 549 at91_for_each_port(i) { ··· 548 552 break; 549 553 550 554 pdata->overcurrent_pin[i] = 551 - devm_gpiod_get_optional(&pdev->dev, 552 - "atmel,oc-gpio", GPIOD_IN); 555 + devm_gpiod_get_index_optional(&pdev->dev, "atmel,oc", 556 + i, GPIOD_IN); 553 557 if (IS_ERR(pdata->overcurrent_pin[i])) { 554 558 err = PTR_ERR(pdata->overcurrent_pin[i]); 555 559 dev_err(&pdev->dev, "unable to claim gpio \"overcurrent\": %d\n", err);
+40 -6
drivers/usb/host/xhci-mem.c
··· 979 979 xhci->devs[slot_id] = NULL; 980 980 } 981 981 982 + /* 983 + * Free a virt_device structure. 984 + * If the virt_device added a tt_info (a hub) and has children pointing to 985 + * that tt_info, then free the child first. Recursive. 986 + * We can't rely on udev at this point to find child-parent relationships. 987 + */ 988 + void xhci_free_virt_devices_depth_first(struct xhci_hcd *xhci, int slot_id) 989 + { 990 + struct xhci_virt_device *vdev; 991 + struct list_head *tt_list_head; 992 + struct xhci_tt_bw_info *tt_info, *next; 993 + int i; 994 + 995 + vdev = xhci->devs[slot_id]; 996 + if (!vdev) 997 + return; 998 + 999 + tt_list_head = &(xhci->rh_bw[vdev->real_port - 1].tts); 1000 + list_for_each_entry_safe(tt_info, next, tt_list_head, tt_list) { 1001 + /* is this a hub device that added a tt_info to the tts list */ 1002 + if (tt_info->slot_id == slot_id) { 1003 + /* are any devices using this tt_info? */ 1004 + for (i = 1; i < HCS_MAX_SLOTS(xhci->hcs_params1); i++) { 1005 + vdev = xhci->devs[i]; 1006 + if (vdev && (vdev->tt_info == tt_info)) 1007 + xhci_free_virt_devices_depth_first( 1008 + xhci, i); 1009 + } 1010 + } 1011 + } 1012 + /* we are now at a leaf device */ 1013 + xhci_free_virt_device(xhci, slot_id); 1014 + } 1015 + 982 1016 int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id, 983 1017 struct usb_device *udev, gfp_t flags) 984 1018 { ··· 1829 1795 int size; 1830 1796 int i, j, num_ports; 1831 1797 1832 - del_timer_sync(&xhci->cmd_timer); 1798 + cancel_delayed_work_sync(&xhci->cmd_timer); 1833 1799 1834 1800 /* Free the Event Ring Segment Table and the actual Event Ring */ 1835 1801 size = sizeof(struct xhci_erst_entry)*(xhci->erst.num_entries); ··· 1862 1828 } 1863 1829 } 1864 1830 1865 - for (i = 1; i < MAX_HC_SLOTS; ++i) 1866 - xhci_free_virt_device(xhci, i); 1831 + for (i = HCS_MAX_SLOTS(xhci->hcs_params1); i > 0; i--) 1832 + xhci_free_virt_devices_depth_first(xhci, i); 1867 1833 1868 1834 dma_pool_destroy(xhci->segment_pool); 1869 1835 xhci->segment_pool = NULL; ··· 2376 2342 2377 2343 INIT_LIST_HEAD(&xhci->cmd_list); 2378 2344 2379 - /* init command timeout timer */ 2380 - setup_timer(&xhci->cmd_timer, xhci_handle_command_timeout, 2381 - (unsigned long)xhci); 2345 + /* init command timeout work */ 2346 + INIT_DELAYED_WORK(&xhci->cmd_timer, xhci_handle_command_timeout); 2347 + init_completion(&xhci->cmd_ring_stop_completion); 2382 2348 2383 2349 page_size = readl(&xhci->op_regs->page_size); 2384 2350 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
+3 -1
drivers/usb/host/xhci-mtk.c
··· 579 579 goto disable_ldos; 580 580 581 581 irq = platform_get_irq(pdev, 0); 582 - if (irq < 0) 582 + if (irq < 0) { 583 + ret = irq; 583 584 goto disable_clk; 585 + } 584 586 585 587 /* Initialize dma_mask and coherent_dma_mask to 32-bits */ 586 588 ret = dma_set_coherent_mask(dev, DMA_BIT_MASK(32));
+2 -1
drivers/usb/host/xhci-pci.c
··· 165 165 pdev->device == PCI_DEVICE_ID_INTEL_SUNRISEPOINT_H_XHCI || 166 166 pdev->device == PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI || 167 167 pdev->device == PCI_DEVICE_ID_INTEL_BROXTON_M_XHCI || 168 - pdev->device == PCI_DEVICE_ID_INTEL_BROXTON_B_XHCI)) { 168 + pdev->device == PCI_DEVICE_ID_INTEL_BROXTON_B_XHCI || 169 + pdev->device == PCI_DEVICE_ID_INTEL_APL_XHCI)) { 169 170 xhci->quirks |= XHCI_PME_STUCK_QUIRK; 170 171 } 171 172 if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
+146 -105
drivers/usb/host/xhci-ring.c
··· 279 279 readl(&xhci->dba->doorbell[0]); 280 280 } 281 281 282 - static int xhci_abort_cmd_ring(struct xhci_hcd *xhci) 282 + static bool xhci_mod_cmd_timer(struct xhci_hcd *xhci, unsigned long delay) 283 + { 284 + return mod_delayed_work(system_wq, &xhci->cmd_timer, delay); 285 + } 286 + 287 + static struct xhci_command *xhci_next_queued_cmd(struct xhci_hcd *xhci) 288 + { 289 + return list_first_entry_or_null(&xhci->cmd_list, struct xhci_command, 290 + cmd_list); 291 + } 292 + 293 + /* 294 + * Turn all commands on command ring with status set to "aborted" to no-op trbs. 295 + * If there are other commands waiting then restart the ring and kick the timer. 296 + * This must be called with command ring stopped and xhci->lock held. 297 + */ 298 + static void xhci_handle_stopped_cmd_ring(struct xhci_hcd *xhci, 299 + struct xhci_command *cur_cmd) 300 + { 301 + struct xhci_command *i_cmd; 302 + u32 cycle_state; 303 + 304 + /* Turn all aborted commands in list to no-ops, then restart */ 305 + list_for_each_entry(i_cmd, &xhci->cmd_list, cmd_list) { 306 + 307 + if (i_cmd->status != COMP_CMD_ABORT) 308 + continue; 309 + 310 + i_cmd->status = COMP_CMD_STOP; 311 + 312 + xhci_dbg(xhci, "Turn aborted command %p to no-op\n", 313 + i_cmd->command_trb); 314 + /* get cycle state from the original cmd trb */ 315 + cycle_state = le32_to_cpu( 316 + i_cmd->command_trb->generic.field[3]) & TRB_CYCLE; 317 + /* modify the command trb to no-op command */ 318 + i_cmd->command_trb->generic.field[0] = 0; 319 + i_cmd->command_trb->generic.field[1] = 0; 320 + i_cmd->command_trb->generic.field[2] = 0; 321 + i_cmd->command_trb->generic.field[3] = cpu_to_le32( 322 + TRB_TYPE(TRB_CMD_NOOP) | cycle_state); 323 + 324 + /* 325 + * caller waiting for completion is called when command 326 + * completion event is received for these no-op commands 327 + */ 328 + } 329 + 330 + xhci->cmd_ring_state = CMD_RING_STATE_RUNNING; 331 + 332 + /* ring command ring doorbell to restart the command ring */ 333 + if ((xhci->cmd_ring->dequeue != xhci->cmd_ring->enqueue) && 334 + !(xhci->xhc_state & XHCI_STATE_DYING)) { 335 + xhci->current_cmd = cur_cmd; 336 + xhci_mod_cmd_timer(xhci, XHCI_CMD_DEFAULT_TIMEOUT); 337 + xhci_ring_cmd_db(xhci); 338 + } 339 + } 340 + 341 + /* Must be called with xhci->lock held, releases and aquires lock back */ 342 + static int xhci_abort_cmd_ring(struct xhci_hcd *xhci, unsigned long flags) 283 343 { 284 344 u64 temp_64; 285 345 int ret; 286 346 287 347 xhci_dbg(xhci, "Abort command ring\n"); 288 348 289 - temp_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); 290 - xhci->cmd_ring_state = CMD_RING_STATE_ABORTED; 349 + reinit_completion(&xhci->cmd_ring_stop_completion); 291 350 292 - /* 293 - * Writing the CMD_RING_ABORT bit should cause a cmd completion event, 294 - * however on some host hw the CMD_RING_RUNNING bit is correctly cleared 295 - * but the completion event in never sent. Use the cmd timeout timer to 296 - * handle those cases. Use twice the time to cover the bit polling retry 297 - */ 298 - mod_timer(&xhci->cmd_timer, jiffies + (2 * XHCI_CMD_DEFAULT_TIMEOUT)); 351 + temp_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); 299 352 xhci_write_64(xhci, temp_64 | CMD_RING_ABORT, 300 353 &xhci->op_regs->cmd_ring); 301 354 ··· 368 315 udelay(1000); 369 316 ret = xhci_handshake(&xhci->op_regs->cmd_ring, 370 317 CMD_RING_RUNNING, 0, 3 * 1000 * 1000); 371 - if (ret == 0) 372 - return 0; 373 - 374 - xhci_err(xhci, "Stopped the command ring failed, " 375 - "maybe the host is dead\n"); 376 - del_timer(&xhci->cmd_timer); 377 - xhci->xhc_state |= XHCI_STATE_DYING; 378 - xhci_halt(xhci); 379 - return -ESHUTDOWN; 318 + if (ret < 0) { 319 + xhci_err(xhci, "Stopped the command ring failed, " 320 + "maybe the host is dead\n"); 321 + xhci->xhc_state |= XHCI_STATE_DYING; 322 + xhci_halt(xhci); 323 + return -ESHUTDOWN; 324 + } 380 325 } 381 - 326 + /* 327 + * Writing the CMD_RING_ABORT bit should cause a cmd completion event, 328 + * however on some host hw the CMD_RING_RUNNING bit is correctly cleared 329 + * but the completion event in never sent. Wait 2 secs (arbitrary 330 + * number) to handle those cases after negation of CMD_RING_RUNNING. 331 + */ 332 + spin_unlock_irqrestore(&xhci->lock, flags); 333 + ret = wait_for_completion_timeout(&xhci->cmd_ring_stop_completion, 334 + msecs_to_jiffies(2000)); 335 + spin_lock_irqsave(&xhci->lock, flags); 336 + if (!ret) { 337 + xhci_dbg(xhci, "No stop event for abort, ring start fail?\n"); 338 + xhci_cleanup_command_queue(xhci); 339 + } else { 340 + xhci_handle_stopped_cmd_ring(xhci, xhci_next_queued_cmd(xhci)); 341 + } 382 342 return 0; 383 343 } 384 344 ··· 1273 1207 xhci_complete_del_and_free_cmd(cur_cmd, COMP_CMD_ABORT); 1274 1208 } 1275 1209 1276 - /* 1277 - * Turn all commands on command ring with status set to "aborted" to no-op trbs. 1278 - * If there are other commands waiting then restart the ring and kick the timer. 1279 - * This must be called with command ring stopped and xhci->lock held. 1280 - */ 1281 - static void xhci_handle_stopped_cmd_ring(struct xhci_hcd *xhci, 1282 - struct xhci_command *cur_cmd) 1283 - { 1284 - struct xhci_command *i_cmd, *tmp_cmd; 1285 - u32 cycle_state; 1286 - 1287 - /* Turn all aborted commands in list to no-ops, then restart */ 1288 - list_for_each_entry_safe(i_cmd, tmp_cmd, &xhci->cmd_list, 1289 - cmd_list) { 1290 - 1291 - if (i_cmd->status != COMP_CMD_ABORT) 1292 - continue; 1293 - 1294 - i_cmd->status = COMP_CMD_STOP; 1295 - 1296 - xhci_dbg(xhci, "Turn aborted command %p to no-op\n", 1297 - i_cmd->command_trb); 1298 - /* get cycle state from the original cmd trb */ 1299 - cycle_state = le32_to_cpu( 1300 - i_cmd->command_trb->generic.field[3]) & TRB_CYCLE; 1301 - /* modify the command trb to no-op command */ 1302 - i_cmd->command_trb->generic.field[0] = 0; 1303 - i_cmd->command_trb->generic.field[1] = 0; 1304 - i_cmd->command_trb->generic.field[2] = 0; 1305 - i_cmd->command_trb->generic.field[3] = cpu_to_le32( 1306 - TRB_TYPE(TRB_CMD_NOOP) | cycle_state); 1307 - 1308 - /* 1309 - * caller waiting for completion is called when command 1310 - * completion event is received for these no-op commands 1311 - */ 1312 - } 1313 - 1314 - xhci->cmd_ring_state = CMD_RING_STATE_RUNNING; 1315 - 1316 - /* ring command ring doorbell to restart the command ring */ 1317 - if ((xhci->cmd_ring->dequeue != xhci->cmd_ring->enqueue) && 1318 - !(xhci->xhc_state & XHCI_STATE_DYING)) { 1319 - xhci->current_cmd = cur_cmd; 1320 - mod_timer(&xhci->cmd_timer, jiffies + XHCI_CMD_DEFAULT_TIMEOUT); 1321 - xhci_ring_cmd_db(xhci); 1322 - } 1323 - return; 1324 - } 1325 - 1326 - 1327 - void xhci_handle_command_timeout(unsigned long data) 1210 + void xhci_handle_command_timeout(struct work_struct *work) 1328 1211 { 1329 1212 struct xhci_hcd *xhci; 1330 1213 int ret; 1331 1214 unsigned long flags; 1332 1215 u64 hw_ring_state; 1333 - bool second_timeout = false; 1334 - xhci = (struct xhci_hcd *) data; 1335 1216 1336 - /* mark this command to be cancelled */ 1217 + xhci = container_of(to_delayed_work(work), struct xhci_hcd, cmd_timer); 1218 + 1337 1219 spin_lock_irqsave(&xhci->lock, flags); 1338 - if (xhci->current_cmd) { 1339 - if (xhci->current_cmd->status == COMP_CMD_ABORT) 1340 - second_timeout = true; 1341 - xhci->current_cmd->status = COMP_CMD_ABORT; 1220 + 1221 + /* 1222 + * If timeout work is pending, or current_cmd is NULL, it means we 1223 + * raced with command completion. Command is handled so just return. 1224 + */ 1225 + if (!xhci->current_cmd || delayed_work_pending(&xhci->cmd_timer)) { 1226 + spin_unlock_irqrestore(&xhci->lock, flags); 1227 + return; 1342 1228 } 1229 + /* mark this command to be cancelled */ 1230 + xhci->current_cmd->status = COMP_CMD_ABORT; 1343 1231 1344 1232 /* Make sure command ring is running before aborting it */ 1345 1233 hw_ring_state = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); 1346 1234 if ((xhci->cmd_ring_state & CMD_RING_STATE_RUNNING) && 1347 1235 (hw_ring_state & CMD_RING_RUNNING)) { 1348 - spin_unlock_irqrestore(&xhci->lock, flags); 1236 + /* Prevent new doorbell, and start command abort */ 1237 + xhci->cmd_ring_state = CMD_RING_STATE_ABORTED; 1349 1238 xhci_dbg(xhci, "Command timeout\n"); 1350 - ret = xhci_abort_cmd_ring(xhci); 1239 + ret = xhci_abort_cmd_ring(xhci, flags); 1351 1240 if (unlikely(ret == -ESHUTDOWN)) { 1352 1241 xhci_err(xhci, "Abort command ring failed\n"); 1353 1242 xhci_cleanup_command_queue(xhci); 1243 + spin_unlock_irqrestore(&xhci->lock, flags); 1354 1244 usb_hc_died(xhci_to_hcd(xhci)->primary_hcd); 1355 1245 xhci_dbg(xhci, "xHCI host controller is dead.\n"); 1246 + 1247 + return; 1356 1248 } 1357 - return; 1249 + 1250 + goto time_out_completed; 1358 1251 } 1359 1252 1360 - /* command ring failed to restart, or host removed. Bail out */ 1361 - if (second_timeout || xhci->xhc_state & XHCI_STATE_REMOVING) { 1362 - spin_unlock_irqrestore(&xhci->lock, flags); 1363 - xhci_dbg(xhci, "command timed out twice, ring start fail?\n"); 1253 + /* host removed. Bail out */ 1254 + if (xhci->xhc_state & XHCI_STATE_REMOVING) { 1255 + xhci_dbg(xhci, "host removed, ring start fail?\n"); 1364 1256 xhci_cleanup_command_queue(xhci); 1365 - return; 1257 + 1258 + goto time_out_completed; 1366 1259 } 1367 1260 1368 1261 /* command timeout on stopped ring, ring can't be aborted */ 1369 1262 xhci_dbg(xhci, "Command timeout on stopped ring\n"); 1370 1263 xhci_handle_stopped_cmd_ring(xhci, xhci->current_cmd); 1264 + 1265 + time_out_completed: 1371 1266 spin_unlock_irqrestore(&xhci->lock, flags); 1372 1267 return; 1373 1268 } ··· 1360 1333 1361 1334 cmd = list_entry(xhci->cmd_list.next, struct xhci_command, cmd_list); 1362 1335 1363 - del_timer(&xhci->cmd_timer); 1336 + cancel_delayed_work(&xhci->cmd_timer); 1364 1337 1365 1338 trace_xhci_cmd_completion(cmd_trb, (struct xhci_generic_trb *) event); 1366 1339 ··· 1368 1341 1369 1342 /* If CMD ring stopped we own the trbs between enqueue and dequeue */ 1370 1343 if (cmd_comp_code == COMP_CMD_STOP) { 1371 - xhci_handle_stopped_cmd_ring(xhci, cmd); 1344 + complete_all(&xhci->cmd_ring_stop_completion); 1372 1345 return; 1373 1346 } 1374 1347 ··· 1386 1359 */ 1387 1360 if (cmd_comp_code == COMP_CMD_ABORT) { 1388 1361 xhci->cmd_ring_state = CMD_RING_STATE_STOPPED; 1389 - if (cmd->status == COMP_CMD_ABORT) 1362 + if (cmd->status == COMP_CMD_ABORT) { 1363 + if (xhci->current_cmd == cmd) 1364 + xhci->current_cmd = NULL; 1390 1365 goto event_handled; 1366 + } 1391 1367 } 1392 1368 1393 1369 cmd_type = TRB_FIELD_TO_TYPE(le32_to_cpu(cmd_trb->generic.field[3])); ··· 1451 1421 if (cmd->cmd_list.next != &xhci->cmd_list) { 1452 1422 xhci->current_cmd = list_entry(cmd->cmd_list.next, 1453 1423 struct xhci_command, cmd_list); 1454 - mod_timer(&xhci->cmd_timer, jiffies + XHCI_CMD_DEFAULT_TIMEOUT); 1424 + xhci_mod_cmd_timer(xhci, XHCI_CMD_DEFAULT_TIMEOUT); 1425 + } else if (xhci->current_cmd == cmd) { 1426 + xhci->current_cmd = NULL; 1455 1427 } 1456 1428 1457 1429 event_handled: ··· 1971 1939 struct xhci_ep_ctx *ep_ctx; 1972 1940 u32 trb_comp_code; 1973 1941 u32 remaining, requested; 1974 - bool on_data_stage; 1942 + u32 trb_type; 1975 1943 1944 + trb_type = TRB_FIELD_TO_TYPE(le32_to_cpu(ep_trb->generic.field[3])); 1976 1945 slot_id = TRB_TO_SLOT_ID(le32_to_cpu(event->flags)); 1977 1946 xdev = xhci->devs[slot_id]; 1978 1947 ep_index = TRB_TO_EP_ID(le32_to_cpu(event->flags)) - 1; ··· 1983 1950 requested = td->urb->transfer_buffer_length; 1984 1951 remaining = EVENT_TRB_LEN(le32_to_cpu(event->transfer_len)); 1985 1952 1986 - /* not setup (dequeue), or status stage means we are at data stage */ 1987 - on_data_stage = (ep_trb != ep_ring->dequeue && ep_trb != td->last_trb); 1988 - 1989 1953 switch (trb_comp_code) { 1990 1954 case COMP_SUCCESS: 1991 - if (ep_trb != td->last_trb) { 1955 + if (trb_type != TRB_STATUS) { 1992 1956 xhci_warn(xhci, "WARN: Success on ctrl %s TRB without IOC set?\n", 1993 - on_data_stage ? "data" : "setup"); 1957 + (trb_type == TRB_DATA) ? "data" : "setup"); 1994 1958 *status = -ESHUTDOWN; 1995 1959 break; 1996 1960 } ··· 1997 1967 *status = 0; 1998 1968 break; 1999 1969 case COMP_STOP_SHORT: 2000 - if (on_data_stage) 1970 + if (trb_type == TRB_DATA || trb_type == TRB_NORMAL) 2001 1971 td->urb->actual_length = remaining; 2002 1972 else 2003 1973 xhci_warn(xhci, "WARN: Stopped Short Packet on ctrl setup or status TRB\n"); 2004 1974 goto finish_td; 2005 1975 case COMP_STOP: 2006 - if (on_data_stage) 1976 + switch (trb_type) { 1977 + case TRB_SETUP: 1978 + td->urb->actual_length = 0; 1979 + goto finish_td; 1980 + case TRB_DATA: 1981 + case TRB_NORMAL: 2007 1982 td->urb->actual_length = requested - remaining; 2008 - goto finish_td; 1983 + goto finish_td; 1984 + default: 1985 + xhci_warn(xhci, "WARN: unexpected TRB Type %d\n", 1986 + trb_type); 1987 + goto finish_td; 1988 + } 2009 1989 case COMP_STOP_INVAL: 2010 1990 goto finish_td; 2011 1991 default: ··· 2027 1987 /* else fall through */ 2028 1988 case COMP_STALL: 2029 1989 /* Did we transfer part of the data (middle) phase? */ 2030 - if (on_data_stage) 1990 + if (trb_type == TRB_DATA || trb_type == TRB_NORMAL) 2031 1991 td->urb->actual_length = requested - remaining; 2032 1992 else if (!td->urb_length_set) 2033 1993 td->urb->actual_length = 0; ··· 2035 1995 } 2036 1996 2037 1997 /* stopped at setup stage, no data transferred */ 2038 - if (ep_trb == ep_ring->dequeue) 1998 + if (trb_type == TRB_SETUP) 2039 1999 goto finish_td; 2040 2000 2041 2001 /* 2042 2002 * if on data stage then update the actual_length of the URB and flag it 2043 2003 * as set, so it won't be overwritten in the event for the last TRB. 2044 2004 */ 2045 - if (on_data_stage) { 2005 + if (trb_type == TRB_DATA || 2006 + trb_type == TRB_NORMAL) { 2046 2007 td->urb_length_set = true; 2047 2008 td->urb->actual_length = requested - remaining; 2048 2009 xhci_dbg(xhci, "Waiting for status stage event\n"); ··· 3831 3790 3832 3791 /* if there are no other commands queued we start the timeout timer */ 3833 3792 if (xhci->cmd_list.next == &cmd->cmd_list && 3834 - !timer_pending(&xhci->cmd_timer)) { 3793 + !delayed_work_pending(&xhci->cmd_timer)) { 3835 3794 xhci->current_cmd = cmd; 3836 - mod_timer(&xhci->cmd_timer, jiffies + XHCI_CMD_DEFAULT_TIMEOUT); 3795 + xhci_mod_cmd_timer(xhci, XHCI_CMD_DEFAULT_TIMEOUT); 3837 3796 } 3838 3797 3839 3798 queue_trb(xhci, xhci->cmd_ring, false, field1, field2, field3,
+3 -1
drivers/usb/host/xhci.c
··· 3787 3787 3788 3788 mutex_lock(&xhci->mutex); 3789 3789 3790 - if (xhci->xhc_state) /* dying, removing or halted */ 3790 + if (xhci->xhc_state) { /* dying, removing or halted */ 3791 + ret = -ESHUTDOWN; 3791 3792 goto out; 3793 + } 3792 3794 3793 3795 if (!udev->slot_id) { 3794 3796 xhci_dbg_trace(xhci, trace_xhci_dbg_address,
+3 -2
drivers/usb/host/xhci.h
··· 1568 1568 #define CMD_RING_STATE_STOPPED (1 << 2) 1569 1569 struct list_head cmd_list; 1570 1570 unsigned int cmd_ring_reserved_trbs; 1571 - struct timer_list cmd_timer; 1571 + struct delayed_work cmd_timer; 1572 + struct completion cmd_ring_stop_completion; 1572 1573 struct xhci_command *current_cmd; 1573 1574 struct xhci_ring *event_ring; 1574 1575 struct xhci_erst erst; ··· 1935 1934 unsigned int slot_id, unsigned int ep_index, 1936 1935 struct xhci_dequeue_state *deq_state); 1937 1936 void xhci_stop_endpoint_command_watchdog(unsigned long arg); 1938 - void xhci_handle_command_timeout(unsigned long data); 1937 + void xhci_handle_command_timeout(struct work_struct *work); 1939 1938 1940 1939 void xhci_ring_ep_doorbell(struct xhci_hcd *xhci, unsigned int slot_id, 1941 1940 unsigned int ep_index, unsigned int stream_id);
+1
drivers/usb/musb/blackfin.c
··· 469 469 .init = bfin_musb_init, 470 470 .exit = bfin_musb_exit, 471 471 472 + .fifo_offset = bfin_fifo_offset, 472 473 .readb = bfin_readb, 473 474 .writeb = bfin_writeb, 474 475 .readw = bfin_readw,
+2
drivers/usb/musb/musb_core.c
··· 2050 2050 struct list_head node; 2051 2051 }; 2052 2052 2053 + #ifdef CONFIG_PM 2053 2054 /* 2054 2055 * Called from musb_runtime_resume(), musb_resume(), and 2055 2056 * musb_queue_resume_work(). Callers must take musb->lock. ··· 2078 2077 2079 2078 return error; 2080 2079 } 2080 + #endif 2081 2081 2082 2082 /* 2083 2083 * Called to run work if device is active or else queue the work to happen
+7
drivers/usb/musb/musb_core.h
··· 216 216 void (*pre_root_reset_end)(struct musb *musb); 217 217 void (*post_root_reset_end)(struct musb *musb); 218 218 int (*phy_callback)(enum musb_vbus_id_status status); 219 + void (*clear_ep_rxintr)(struct musb *musb, int epnum); 219 220 }; 220 221 221 222 /* ··· 625 624 { 626 625 if (musb->ops->post_root_reset_end) 627 626 musb->ops->post_root_reset_end(musb); 627 + } 628 + 629 + static inline void musb_platform_clear_ep_rxintr(struct musb *musb, int epnum) 630 + { 631 + if (musb->ops->clear_ep_rxintr) 632 + musb->ops->clear_ep_rxintr(musb, epnum); 628 633 } 629 634 630 635 /*
+12
drivers/usb/musb/musb_dsps.c
··· 267 267 pm_runtime_put_autosuspend(dev); 268 268 } 269 269 270 + void dsps_musb_clear_ep_rxintr(struct musb *musb, int epnum) 271 + { 272 + u32 epintr; 273 + struct dsps_glue *glue = dev_get_drvdata(musb->controller->parent); 274 + const struct dsps_musb_wrapper *wrp = glue->wrp; 275 + 276 + /* musb->lock might already been held */ 277 + epintr = (1 << epnum) << wrp->rxep_shift; 278 + musb_writel(musb->ctrl_base, wrp->epintr_status, epintr); 279 + } 280 + 270 281 static irqreturn_t dsps_interrupt(int irq, void *hci) 271 282 { 272 283 struct musb *musb = hci; ··· 633 622 634 623 .set_mode = dsps_musb_set_mode, 635 624 .recover = dsps_musb_recover, 625 + .clear_ep_rxintr = dsps_musb_clear_ep_rxintr, 636 626 }; 637 627 638 628 static u64 musb_dmamask = DMA_BIT_MASK(32);
+4 -6
drivers/usb/musb/musb_host.c
··· 2374 2374 int is_in = usb_pipein(urb->pipe); 2375 2375 int status = 0; 2376 2376 u16 csr; 2377 + struct dma_channel *dma = NULL; 2377 2378 2378 2379 musb_ep_select(regs, hw_end); 2379 2380 2380 2381 if (is_dma_capable()) { 2381 - struct dma_channel *dma; 2382 - 2383 2382 dma = is_in ? ep->rx_channel : ep->tx_channel; 2384 2383 if (dma) { 2385 2384 status = ep->musb->dma_controller->channel_abort(dma); ··· 2394 2395 /* giveback saves bulk toggle */ 2395 2396 csr = musb_h_flush_rxfifo(ep, 0); 2396 2397 2397 - /* REVISIT we still get an irq; should likely clear the 2398 - * endpoint's irq status here to avoid bogus irqs. 2399 - * clearing that status is platform-specific... 2400 - */ 2398 + /* clear the endpoint's irq status here to avoid bogus irqs */ 2399 + if (is_dma_capable() && dma) 2400 + musb_platform_clear_ep_rxintr(musb, ep->epnum); 2401 2401 } else if (ep->epnum) { 2402 2402 musb_h_tx_flush_fifo(ep); 2403 2403 csr = musb_readw(epio, MUSB_TXCSR);
+1 -1
drivers/usb/musb/musbhsdma.h
··· 157 157 void __iomem *base; 158 158 u8 channel_count; 159 159 u8 used_channels; 160 - u8 irq; 160 + int irq; 161 161 };
+10
drivers/usb/serial/cyberjack.c
··· 50 50 #define CYBERJACK_PRODUCT_ID 0x0100 51 51 52 52 /* Function prototypes */ 53 + static int cyberjack_attach(struct usb_serial *serial); 53 54 static int cyberjack_port_probe(struct usb_serial_port *port); 54 55 static int cyberjack_port_remove(struct usb_serial_port *port); 55 56 static int cyberjack_open(struct tty_struct *tty, ··· 78 77 .description = "Reiner SCT Cyberjack USB card reader", 79 78 .id_table = id_table, 80 79 .num_ports = 1, 80 + .attach = cyberjack_attach, 81 81 .port_probe = cyberjack_port_probe, 82 82 .port_remove = cyberjack_port_remove, 83 83 .open = cyberjack_open, ··· 101 99 short wrfilled; /* Overall data size we already got */ 102 100 short wrsent; /* Data already sent */ 103 101 }; 102 + 103 + static int cyberjack_attach(struct usb_serial *serial) 104 + { 105 + if (serial->num_bulk_out < serial->num_ports) 106 + return -ENODEV; 107 + 108 + return 0; 109 + } 104 110 105 111 static int cyberjack_port_probe(struct usb_serial_port *port) 106 112 {
+5 -3
drivers/usb/serial/f81534.c
··· 1237 1237 static int f81534_port_probe(struct usb_serial_port *port) 1238 1238 { 1239 1239 struct f81534_port_private *port_priv; 1240 + int ret; 1240 1241 1241 1242 port_priv = devm_kzalloc(&port->dev, sizeof(*port_priv), GFP_KERNEL); 1242 1243 if (!port_priv) ··· 1247 1246 mutex_init(&port_priv->mcr_mutex); 1248 1247 1249 1248 /* Assign logic-to-phy mapping */ 1250 - port_priv->phy_num = f81534_logic_to_phy_port(port->serial, port); 1251 - if (port_priv->phy_num < 0 || port_priv->phy_num >= F81534_NUM_PORT) 1252 - return -ENODEV; 1249 + ret = f81534_logic_to_phy_port(port->serial, port); 1250 + if (ret < 0) 1251 + return ret; 1253 1252 1253 + port_priv->phy_num = ret; 1254 1254 usb_set_serial_port_data(port, port_priv); 1255 1255 dev_dbg(&port->dev, "%s: port_number: %d, phy_num: %d\n", __func__, 1256 1256 port->port_number, port_priv->phy_num);
+1
drivers/usb/serial/garmin_gps.c
··· 1043 1043 "%s - usb_submit_urb(write bulk) failed with status = %d\n", 1044 1044 __func__, status); 1045 1045 count = status; 1046 + kfree(buffer); 1046 1047 } 1047 1048 1048 1049 /* we are done with this urb, so let the host driver
+5
drivers/usb/serial/io_edgeport.c
··· 2751 2751 EDGE_COMPATIBILITY_MASK1, 2752 2752 EDGE_COMPATIBILITY_MASK2 }; 2753 2753 2754 + if (serial->num_bulk_in < 1 || serial->num_interrupt_in < 1) { 2755 + dev_err(&serial->interface->dev, "missing endpoints\n"); 2756 + return -ENODEV; 2757 + } 2758 + 2754 2759 dev = serial->dev; 2755 2760 2756 2761 /* create our private serial structure */
+17 -5
drivers/usb/serial/io_ti.c
··· 1499 1499 1500 1500 dev_dbg(dev, "%s - Download successful -- Device rebooting...\n", __func__); 1501 1501 1502 - /* return an error on purpose */ 1503 - return -ENODEV; 1502 + return 1; 1504 1503 } 1505 1504 1506 1505 stayinbootmode: ··· 1507 1508 dev_dbg(dev, "%s - STAYING IN BOOT MODE\n", __func__); 1508 1509 serial->product_info.TiMode = TI_MODE_BOOT; 1509 1510 1510 - return 0; 1511 + return 1; 1511 1512 } 1512 1513 1513 1514 static int ti_do_config(struct edgeport_port *port, int feature, int on) ··· 2545 2546 int status; 2546 2547 u16 product_id; 2547 2548 2549 + /* Make sure we have the required endpoints when in download mode. */ 2550 + if (serial->interface->cur_altsetting->desc.bNumEndpoints > 1) { 2551 + if (serial->num_bulk_in < serial->num_ports || 2552 + serial->num_bulk_out < serial->num_ports) 2553 + return -ENODEV; 2554 + } 2555 + 2548 2556 /* create our private serial structure */ 2549 2557 edge_serial = kzalloc(sizeof(struct edgeport_serial), GFP_KERNEL); 2550 2558 if (!edge_serial) ··· 2559 2553 2560 2554 mutex_init(&edge_serial->es_lock); 2561 2555 edge_serial->serial = serial; 2556 + INIT_DELAYED_WORK(&edge_serial->heartbeat_work, edge_heartbeat_work); 2562 2557 usb_set_serial_data(serial, edge_serial); 2563 2558 2564 2559 status = download_fw(edge_serial); 2565 - if (status) { 2560 + if (status < 0) { 2566 2561 kfree(edge_serial); 2567 2562 return status; 2568 2563 } 2564 + 2565 + if (status > 0) 2566 + return 1; /* bind but do not register any ports */ 2569 2567 2570 2568 product_id = le16_to_cpu( 2571 2569 edge_serial->serial->dev->descriptor.idProduct); ··· 2582 2572 } 2583 2573 } 2584 2574 2585 - INIT_DELAYED_WORK(&edge_serial->heartbeat_work, edge_heartbeat_work); 2586 2575 edge_heartbeat_schedule(edge_serial); 2587 2576 2588 2577 return 0; ··· 2589 2580 2590 2581 static void edge_disconnect(struct usb_serial *serial) 2591 2582 { 2583 + struct edgeport_serial *edge_serial = usb_get_serial_data(serial); 2584 + 2585 + cancel_delayed_work_sync(&edge_serial->heartbeat_work); 2592 2586 } 2593 2587 2594 2588 static void edge_release(struct usb_serial *serial)
+11
drivers/usb/serial/iuu_phoenix.c
··· 68 68 u32 clk; 69 69 }; 70 70 71 + static int iuu_attach(struct usb_serial *serial) 72 + { 73 + unsigned char num_ports = serial->num_ports; 74 + 75 + if (serial->num_bulk_in < num_ports || serial->num_bulk_out < num_ports) 76 + return -ENODEV; 77 + 78 + return 0; 79 + } 80 + 71 81 static int iuu_port_probe(struct usb_serial_port *port) 72 82 { 73 83 struct iuu_private *priv; ··· 1206 1196 .tiocmset = iuu_tiocmset, 1207 1197 .set_termios = iuu_set_termios, 1208 1198 .init_termios = iuu_init_termios, 1199 + .attach = iuu_attach, 1209 1200 .port_probe = iuu_port_probe, 1210 1201 .port_remove = iuu_port_remove, 1211 1202 };
+14
drivers/usb/serial/keyspan_pda.c
··· 699 699 MODULE_FIRMWARE("keyspan_pda/xircom_pgs.fw"); 700 700 #endif 701 701 702 + static int keyspan_pda_attach(struct usb_serial *serial) 703 + { 704 + unsigned char num_ports = serial->num_ports; 705 + 706 + if (serial->num_bulk_out < num_ports || 707 + serial->num_interrupt_in < num_ports) { 708 + dev_err(&serial->interface->dev, "missing endpoints\n"); 709 + return -ENODEV; 710 + } 711 + 712 + return 0; 713 + } 714 + 702 715 static int keyspan_pda_port_probe(struct usb_serial_port *port) 703 716 { 704 717 ··· 789 776 .break_ctl = keyspan_pda_break_ctl, 790 777 .tiocmget = keyspan_pda_tiocmget, 791 778 .tiocmset = keyspan_pda_tiocmset, 779 + .attach = keyspan_pda_attach, 792 780 .port_probe = keyspan_pda_port_probe, 793 781 .port_remove = keyspan_pda_port_remove, 794 782 };
+12
drivers/usb/serial/kobil_sct.c
··· 51 51 52 52 53 53 /* Function prototypes */ 54 + static int kobil_attach(struct usb_serial *serial); 54 55 static int kobil_port_probe(struct usb_serial_port *probe); 55 56 static int kobil_port_remove(struct usb_serial_port *probe); 56 57 static int kobil_open(struct tty_struct *tty, struct usb_serial_port *port); ··· 87 86 .description = "KOBIL USB smart card terminal", 88 87 .id_table = id_table, 89 88 .num_ports = 1, 89 + .attach = kobil_attach, 90 90 .port_probe = kobil_port_probe, 91 91 .port_remove = kobil_port_remove, 92 92 .ioctl = kobil_ioctl, ··· 114 112 __u16 device_type; 115 113 }; 116 114 115 + 116 + static int kobil_attach(struct usb_serial *serial) 117 + { 118 + if (serial->num_interrupt_out < serial->num_ports) { 119 + dev_err(&serial->interface->dev, "missing interrupt-out endpoint\n"); 120 + return -ENODEV; 121 + } 122 + 123 + return 0; 124 + } 117 125 118 126 static int kobil_port_probe(struct usb_serial_port *port) 119 127 {
+21 -35
drivers/usb/serial/mos7720.c
··· 65 65 struct urb *write_urb_pool[NUM_URBS]; 66 66 }; 67 67 68 - static struct usb_serial_driver moschip7720_2port_driver; 69 - 70 68 #define USB_VENDOR_ID_MOSCHIP 0x9710 71 69 #define MOSCHIP_DEVICE_ID_7720 0x7720 72 70 #define MOSCHIP_DEVICE_ID_7715 0x7715 ··· 966 968 967 969 if (mos7720_port->open) 968 970 tty_port_tty_wakeup(&mos7720_port->port->port); 969 - } 970 - 971 - /* 972 - * mos77xx_probe 973 - * this function installs the appropriate read interrupt endpoint callback 974 - * depending on whether the device is a 7720 or 7715, thus avoiding costly 975 - * run-time checks in the high-frequency callback routine itself. 976 - */ 977 - static int mos77xx_probe(struct usb_serial *serial, 978 - const struct usb_device_id *id) 979 - { 980 - if (id->idProduct == MOSCHIP_DEVICE_ID_7715) 981 - moschip7720_2port_driver.read_int_callback = 982 - mos7715_interrupt_callback; 983 - else 984 - moschip7720_2port_driver.read_int_callback = 985 - mos7720_interrupt_callback; 986 - 987 - return 0; 988 971 } 989 972 990 973 static int mos77xx_calc_num_ports(struct usb_serial *serial) ··· 1896 1917 u16 product; 1897 1918 int ret_val; 1898 1919 1920 + if (serial->num_bulk_in < 2 || serial->num_bulk_out < 2) { 1921 + dev_err(&serial->interface->dev, "missing bulk endpoints\n"); 1922 + return -ENODEV; 1923 + } 1924 + 1899 1925 product = le16_to_cpu(serial->dev->descriptor.idProduct); 1900 1926 dev = serial->dev; 1901 1927 ··· 1925 1941 tmp->interrupt_in_endpointAddress; 1926 1942 serial->port[1]->interrupt_in_urb = NULL; 1927 1943 serial->port[1]->interrupt_in_buffer = NULL; 1944 + 1945 + if (serial->port[0]->interrupt_in_urb) { 1946 + struct urb *urb = serial->port[0]->interrupt_in_urb; 1947 + 1948 + urb->complete = mos7715_interrupt_callback; 1949 + } 1928 1950 } 1929 1951 1930 1952 /* setting configuration feature to one */ 1931 1953 usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 1932 1954 (__u8)0x03, 0x00, 0x01, 0x00, NULL, 0x00, 5000); 1933 - 1934 - /* start the interrupt urb */ 1935 - ret_val = usb_submit_urb(serial->port[0]->interrupt_in_urb, GFP_KERNEL); 1936 - if (ret_val) 1937 - dev_err(&dev->dev, 1938 - "%s - Error %d submitting control urb\n", 1939 - __func__, ret_val); 1940 1955 1941 1956 #ifdef CONFIG_USB_SERIAL_MOS7715_PARPORT 1942 1957 if (product == MOSCHIP_DEVICE_ID_7715) { ··· 1944 1961 return ret_val; 1945 1962 } 1946 1963 #endif 1964 + /* start the interrupt urb */ 1965 + ret_val = usb_submit_urb(serial->port[0]->interrupt_in_urb, GFP_KERNEL); 1966 + if (ret_val) { 1967 + dev_err(&dev->dev, "failed to submit interrupt urb: %d\n", 1968 + ret_val); 1969 + } 1970 + 1947 1971 /* LSR For Port 1 */ 1948 1972 read_mos_reg(serial, 0, MOS7720_LSR, &data); 1949 1973 dev_dbg(&dev->dev, "LSR:%x\n", data); ··· 1960 1970 1961 1971 static void mos7720_release(struct usb_serial *serial) 1962 1972 { 1973 + usb_kill_urb(serial->port[0]->interrupt_in_urb); 1974 + 1963 1975 #ifdef CONFIG_USB_SERIAL_MOS7715_PARPORT 1964 1976 /* close the parallel port */ 1965 1977 ··· 2011 2019 if (!mos7720_port) 2012 2020 return -ENOMEM; 2013 2021 2014 - /* Initialize all port interrupt end point to port 0 int endpoint. 2015 - * Our device has only one interrupt endpoint common to all ports. 2016 - */ 2017 - port->interrupt_in_endpointAddress = 2018 - port->serial->port[0]->interrupt_in_endpointAddress; 2019 2022 mos7720_port->port = port; 2020 2023 2021 2024 usb_set_serial_port_data(port, mos7720_port); ··· 2040 2053 .close = mos7720_close, 2041 2054 .throttle = mos7720_throttle, 2042 2055 .unthrottle = mos7720_unthrottle, 2043 - .probe = mos77xx_probe, 2044 2056 .attach = mos7720_startup, 2045 2057 .release = mos7720_release, 2046 2058 .port_probe = mos7720_port_probe, ··· 2053 2067 .chars_in_buffer = mos7720_chars_in_buffer, 2054 2068 .break_ctl = mos7720_break, 2055 2069 .read_bulk_callback = mos7720_bulk_in_callback, 2056 - .read_int_callback = NULL /* dynamically assigned in probe() */ 2070 + .read_int_callback = mos7720_interrupt_callback, 2057 2071 }; 2058 2072 2059 2073 static struct usb_serial_driver * const serial_drivers[] = {
+13 -11
drivers/usb/serial/mos7840.c
··· 214 214 215 215 struct moschip_port { 216 216 int port_num; /*Actual port number in the device(1,2,etc) */ 217 - struct urb *write_urb; /* write URB for this port */ 218 217 struct urb *read_urb; /* read URB for this port */ 219 218 __u8 shadowLCR; /* last LCR value received */ 220 219 __u8 shadowMCR; /* last MCR value received */ ··· 1036 1037 serial, 1037 1038 serial->port[0]->interrupt_in_urb->interval); 1038 1039 1039 - /* start interrupt read for mos7840 * 1040 - * will continue as long as mos7840 is connected */ 1041 - 1040 + /* start interrupt read for mos7840 */ 1042 1041 response = 1043 1042 usb_submit_urb(serial->port[0]->interrupt_in_urb, 1044 1043 GFP_KERNEL); ··· 1183 1186 } 1184 1187 } 1185 1188 1186 - usb_kill_urb(mos7840_port->write_urb); 1187 1189 usb_kill_urb(mos7840_port->read_urb); 1188 1190 mos7840_port->read_urb_busy = false; 1189 1191 ··· 1193 1197 dev_dbg(&port->dev, "Shutdown interrupt_in_urb\n"); 1194 1198 usb_kill_urb(serial->port[0]->interrupt_in_urb); 1195 1199 } 1196 - } 1197 - 1198 - if (mos7840_port->write_urb) { 1199 - /* if this urb had a transfer buffer already (old tx) free it */ 1200 - kfree(mos7840_port->write_urb->transfer_buffer); 1201 - usb_free_urb(mos7840_port->write_urb); 1202 1200 } 1203 1201 1204 1202 Data = 0x0; ··· 2103 2113 return mos7840_num_ports; 2104 2114 } 2105 2115 2116 + static int mos7840_attach(struct usb_serial *serial) 2117 + { 2118 + if (serial->num_bulk_in < serial->num_ports || 2119 + serial->num_bulk_out < serial->num_ports) { 2120 + dev_err(&serial->interface->dev, "missing endpoints\n"); 2121 + return -ENODEV; 2122 + } 2123 + 2124 + return 0; 2125 + } 2126 + 2106 2127 static int mos7840_port_probe(struct usb_serial_port *port) 2107 2128 { 2108 2129 struct usb_serial *serial = port->serial; ··· 2389 2388 .tiocmset = mos7840_tiocmset, 2390 2389 .tiocmiwait = usb_serial_generic_tiocmiwait, 2391 2390 .get_icount = usb_serial_generic_get_icount, 2391 + .attach = mos7840_attach, 2392 2392 .port_probe = mos7840_port_probe, 2393 2393 .port_remove = mos7840_port_remove, 2394 2394 .read_bulk_callback = mos7840_bulk_in_callback,
+13
drivers/usb/serial/omninet.c
··· 38 38 const unsigned char *buf, int count); 39 39 static int omninet_write_room(struct tty_struct *tty); 40 40 static void omninet_disconnect(struct usb_serial *serial); 41 + static int omninet_attach(struct usb_serial *serial); 41 42 static int omninet_port_probe(struct usb_serial_port *port); 42 43 static int omninet_port_remove(struct usb_serial_port *port); 43 44 ··· 57 56 .description = "ZyXEL - omni.net lcd plus usb", 58 57 .id_table = id_table, 59 58 .num_ports = 1, 59 + .attach = omninet_attach, 60 60 .port_probe = omninet_port_probe, 61 61 .port_remove = omninet_port_remove, 62 62 .open = omninet_open, ··· 105 103 struct omninet_data { 106 104 __u8 od_outseq; /* Sequence number for bulk_out URBs */ 107 105 }; 106 + 107 + static int omninet_attach(struct usb_serial *serial) 108 + { 109 + /* The second bulk-out endpoint is used for writing. */ 110 + if (serial->num_bulk_out < 2) { 111 + dev_err(&serial->interface->dev, "missing endpoints\n"); 112 + return -ENODEV; 113 + } 114 + 115 + return 0; 116 + } 108 117 109 118 static int omninet_port_probe(struct usb_serial_port *port) 110 119 {
+16
drivers/usb/serial/oti6858.c
··· 134 134 static int oti6858_tiocmget(struct tty_struct *tty); 135 135 static int oti6858_tiocmset(struct tty_struct *tty, 136 136 unsigned int set, unsigned int clear); 137 + static int oti6858_attach(struct usb_serial *serial); 137 138 static int oti6858_port_probe(struct usb_serial_port *port); 138 139 static int oti6858_port_remove(struct usb_serial_port *port); 139 140 ··· 159 158 .write_bulk_callback = oti6858_write_bulk_callback, 160 159 .write_room = oti6858_write_room, 161 160 .chars_in_buffer = oti6858_chars_in_buffer, 161 + .attach = oti6858_attach, 162 162 .port_probe = oti6858_port_probe, 163 163 .port_remove = oti6858_port_remove, 164 164 }; ··· 324 322 } 325 323 326 324 usb_serial_port_softint(port); 325 + } 326 + 327 + static int oti6858_attach(struct usb_serial *serial) 328 + { 329 + unsigned char num_ports = serial->num_ports; 330 + 331 + if (serial->num_bulk_in < num_ports || 332 + serial->num_bulk_out < num_ports || 333 + serial->num_interrupt_in < num_ports) { 334 + dev_err(&serial->interface->dev, "missing endpoints\n"); 335 + return -ENODEV; 336 + } 337 + 338 + return 0; 327 339 } 328 340 329 341 static int oti6858_port_probe(struct usb_serial_port *port)
+8
drivers/usb/serial/pl2303.c
··· 220 220 static int pl2303_startup(struct usb_serial *serial) 221 221 { 222 222 struct pl2303_serial_private *spriv; 223 + unsigned char num_ports = serial->num_ports; 223 224 enum pl2303_type type = TYPE_01; 224 225 unsigned char *buf; 226 + 227 + if (serial->num_bulk_in < num_ports || 228 + serial->num_bulk_out < num_ports || 229 + serial->num_interrupt_in < num_ports) { 230 + dev_err(&serial->interface->dev, "missing endpoints\n"); 231 + return -ENODEV; 232 + } 225 233 226 234 spriv = kzalloc(sizeof(*spriv), GFP_KERNEL); 227 235 if (!spriv)
-4
drivers/usb/serial/quatech2.c
··· 408 408 { 409 409 struct usb_serial *serial; 410 410 struct qt2_port_private *port_priv; 411 - unsigned long flags; 412 411 int i; 413 412 414 413 serial = port->serial; 415 414 port_priv = usb_get_serial_port_data(port); 416 415 417 - spin_lock_irqsave(&port_priv->urb_lock, flags); 418 416 usb_kill_urb(port_priv->write_urb); 419 - port_priv->urb_in_use = false; 420 - spin_unlock_irqrestore(&port_priv->urb_lock, flags); 421 417 422 418 /* flush the port transmit buffer */ 423 419 i = usb_control_msg(serial->dev,
+14
drivers/usb/serial/spcp8x5.c
··· 154 154 return 0; 155 155 } 156 156 157 + static int spcp8x5_attach(struct usb_serial *serial) 158 + { 159 + unsigned char num_ports = serial->num_ports; 160 + 161 + if (serial->num_bulk_in < num_ports || 162 + serial->num_bulk_out < num_ports) { 163 + dev_err(&serial->interface->dev, "missing endpoints\n"); 164 + return -ENODEV; 165 + } 166 + 167 + return 0; 168 + } 169 + 157 170 static int spcp8x5_port_probe(struct usb_serial_port *port) 158 171 { 159 172 const struct usb_device_id *id = usb_get_serial_data(port->serial); ··· 490 477 .tiocmget = spcp8x5_tiocmget, 491 478 .tiocmset = spcp8x5_tiocmset, 492 479 .probe = spcp8x5_probe, 480 + .attach = spcp8x5_attach, 493 481 .port_probe = spcp8x5_port_probe, 494 482 .port_remove = spcp8x5_port_remove, 495 483 };
+7
drivers/usb/serial/ti_usb_3410_5052.c
··· 579 579 goto free_tdev; 580 580 } 581 581 582 + if (serial->num_bulk_in < serial->num_ports || 583 + serial->num_bulk_out < serial->num_ports) { 584 + dev_err(&serial->interface->dev, "missing endpoints\n"); 585 + status = -ENODEV; 586 + goto free_tdev; 587 + } 588 + 582 589 return 0; 583 590 584 591 free_tdev:
+7
drivers/usb/storage/unusual_devs.h
··· 2109 2109 USB_SC_DEVICE, USB_PR_DEVICE, NULL, 2110 2110 US_FL_BROKEN_FUA ), 2111 2111 2112 + /* Reported-by George Cherian <george.cherian@cavium.com> */ 2113 + UNUSUAL_DEV(0x152d, 0x9561, 0x0000, 0x9999, 2114 + "JMicron", 2115 + "JMS56x", 2116 + USB_SC_DEVICE, USB_PR_DEVICE, NULL, 2117 + US_FL_NO_REPORT_OPCODES), 2118 + 2112 2119 /* 2113 2120 * Entrega Technologies U1-SC25 (later Xircom PortGear PGSCSI) 2114 2121 * and Mac USB Dock USB-SCSI */
+1
include/uapi/linux/usb/functionfs.h
··· 93 93 * | 0 | magic | LE32 | FUNCTIONFS_DESCRIPTORS_MAGIC_V2 | 94 94 * | 4 | length | LE32 | length of the whole data chunk | 95 95 * | 8 | flags | LE32 | combination of functionfs_flags | 96 + * | | eventfd | LE32 | eventfd file descriptor | 96 97 * | | fs_count | LE32 | number of full-speed descriptors | 97 98 * | | hs_count | LE32 | number of high-speed descriptors | 98 99 * | | ss_count | LE32 | number of super-speed descriptors |