aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/usb/core/config.c4
-rw-r--r--drivers/usb/dwc2/core.h4
-rw-r--r--drivers/usb/dwc2/gadget.c42
-rw-r--r--drivers/usb/dwc2/params.c29
-rw-r--r--drivers/usb/dwc3/dwc3-of-simple.c5
-rw-r--r--drivers/usb/dwc3/gadget.c4
-rw-r--r--drivers/usb/gadget/Kconfig4
-rw-r--r--drivers/usb/gadget/legacy/Kconfig12
-rw-r--r--drivers/usb/host/xhci-mem.c15
-rw-r--r--drivers/usb/host/xhci-ring.c6
-rw-r--r--drivers/usb/musb/da8xx.c10
-rw-r--r--drivers/usb/storage/unusual_devs.h7
-rw-r--r--drivers/usb/storage/unusual_uas.h7
-rw-r--r--drivers/usb/usbip/stub_rx.c51
-rw-r--r--drivers/usb/usbip/stub_tx.c7
-rw-r--r--drivers/usb/usbip/usbip_common.h1
-rw-r--r--drivers/usb/usbip/vhci_sysfs.c25
-rw-r--r--tools/usb/usbip/libsrc/vhci_driver.c10
18 files changed, 144 insertions, 99 deletions
diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c
index 55b198ba629b..78e92d29f8d9 100644
--- a/drivers/usb/core/config.c
+++ b/drivers/usb/core/config.c
@@ -555,6 +555,9 @@ static int usb_parse_configuration(struct usb_device *dev, int cfgidx,
555 unsigned iad_num = 0; 555 unsigned iad_num = 0;
556 556
557 memcpy(&config->desc, buffer, USB_DT_CONFIG_SIZE); 557 memcpy(&config->desc, buffer, USB_DT_CONFIG_SIZE);
558 nintf = nintf_orig = config->desc.bNumInterfaces;
559 config->desc.bNumInterfaces = 0; // Adjusted later
560
558 if (config->desc.bDescriptorType != USB_DT_CONFIG || 561 if (config->desc.bDescriptorType != USB_DT_CONFIG ||
559 config->desc.bLength < USB_DT_CONFIG_SIZE || 562 config->desc.bLength < USB_DT_CONFIG_SIZE ||
560 config->desc.bLength > size) { 563 config->desc.bLength > size) {
@@ -568,7 +571,6 @@ static int usb_parse_configuration(struct usb_device *dev, int cfgidx,
568 buffer += config->desc.bLength; 571 buffer += config->desc.bLength;
569 size -= config->desc.bLength; 572 size -= config->desc.bLength;
570 573
571 nintf = nintf_orig = config->desc.bNumInterfaces;
572 if (nintf > USB_MAXINTERFACES) { 574 if (nintf > USB_MAXINTERFACES) {
573 dev_warn(ddev, "config %d has too many interfaces: %d, " 575 dev_warn(ddev, "config %d has too many interfaces: %d, "
574 "using maximum allowed: %d\n", 576 "using maximum allowed: %d\n",
diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
index f66c94130cac..31749c79045f 100644
--- a/drivers/usb/dwc2/core.h
+++ b/drivers/usb/dwc2/core.h
@@ -537,6 +537,7 @@ struct dwc2_core_params {
537 * 2 - Internal DMA 537 * 2 - Internal DMA
538 * @power_optimized Are power optimizations enabled? 538 * @power_optimized Are power optimizations enabled?
539 * @num_dev_ep Number of device endpoints available 539 * @num_dev_ep Number of device endpoints available
540 * @num_dev_in_eps Number of device IN endpoints available
540 * @num_dev_perio_in_ep Number of device periodic IN endpoints 541 * @num_dev_perio_in_ep Number of device periodic IN endpoints
541 * available 542 * available
542 * @dev_token_q_depth Device Mode IN Token Sequence Learning Queue 543 * @dev_token_q_depth Device Mode IN Token Sequence Learning Queue
@@ -565,6 +566,7 @@ struct dwc2_core_params {
565 * 2 - 8 or 16 bits 566 * 2 - 8 or 16 bits
566 * @snpsid: Value from SNPSID register 567 * @snpsid: Value from SNPSID register
567 * @dev_ep_dirs: Direction of device endpoints (GHWCFG1) 568 * @dev_ep_dirs: Direction of device endpoints (GHWCFG1)
569 * @g_tx_fifo_size[] Power-on values of TxFIFO sizes
568 */ 570 */
569struct dwc2_hw_params { 571struct dwc2_hw_params {
570 unsigned op_mode:3; 572 unsigned op_mode:3;
@@ -586,12 +588,14 @@ struct dwc2_hw_params {
586 unsigned fs_phy_type:2; 588 unsigned fs_phy_type:2;
587 unsigned i2c_enable:1; 589 unsigned i2c_enable:1;
588 unsigned num_dev_ep:4; 590 unsigned num_dev_ep:4;
591 unsigned num_dev_in_eps : 4;
589 unsigned num_dev_perio_in_ep:4; 592 unsigned num_dev_perio_in_ep:4;
590 unsigned total_fifo_size:16; 593 unsigned total_fifo_size:16;
591 unsigned power_optimized:1; 594 unsigned power_optimized:1;
592 unsigned utmi_phy_data_width:2; 595 unsigned utmi_phy_data_width:2;
593 u32 snpsid; 596 u32 snpsid;
594 u32 dev_ep_dirs; 597 u32 dev_ep_dirs;
598 u32 g_tx_fifo_size[MAX_EPS_CHANNELS];
595}; 599};
596 600
597/* Size of control and EP0 buffers */ 601/* Size of control and EP0 buffers */
diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 88529d092503..e4c3ce0de5de 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -195,55 +195,18 @@ int dwc2_hsotg_tx_fifo_count(struct dwc2_hsotg *hsotg)
195{ 195{
196 if (hsotg->hw_params.en_multiple_tx_fifo) 196 if (hsotg->hw_params.en_multiple_tx_fifo)
197 /* In dedicated FIFO mode we need count of IN EPs */ 197 /* In dedicated FIFO mode we need count of IN EPs */
198 return (dwc2_readl(hsotg->regs + GHWCFG4) & 198 return hsotg->hw_params.num_dev_in_eps;
199 GHWCFG4_NUM_IN_EPS_MASK) >> GHWCFG4_NUM_IN_EPS_SHIFT;
200 else 199 else
201 /* In shared FIFO mode we need count of Periodic IN EPs */ 200 /* In shared FIFO mode we need count of Periodic IN EPs */
202 return hsotg->hw_params.num_dev_perio_in_ep; 201 return hsotg->hw_params.num_dev_perio_in_ep;
203} 202}
204 203
205/** 204/**
206 * dwc2_hsotg_ep_info_size - return Endpoint Info Control block size in DWORDs
207 */
208static int dwc2_hsotg_ep_info_size(struct dwc2_hsotg *hsotg)
209{
210 int val = 0;
211 int i;
212 u32 ep_dirs;
213
214 /*
215 * Don't need additional space for ep info control registers in
216 * slave mode.
217 */
218 if (!using_dma(hsotg)) {
219 dev_dbg(hsotg->dev, "Buffer DMA ep info size 0\n");
220 return 0;
221 }
222
223 /*
224 * Buffer DMA mode - 1 location per endpoit
225 * Descriptor DMA mode - 4 locations per endpoint
226 */
227 ep_dirs = hsotg->hw_params.dev_ep_dirs;
228
229 for (i = 0; i <= hsotg->hw_params.num_dev_ep; i++) {
230 val += ep_dirs & 3 ? 1 : 2;
231 ep_dirs >>= 2;
232 }
233
234 if (using_desc_dma(hsotg))
235 val = val * 4;
236
237 return val;
238}
239
240/**
241 * dwc2_hsotg_tx_fifo_total_depth - return total FIFO depth available for 205 * dwc2_hsotg_tx_fifo_total_depth - return total FIFO depth available for
242 * device mode TX FIFOs 206 * device mode TX FIFOs
243 */ 207 */
244int dwc2_hsotg_tx_fifo_total_depth(struct dwc2_hsotg *hsotg) 208int dwc2_hsotg_tx_fifo_total_depth(struct dwc2_hsotg *hsotg)
245{ 209{
246 int ep_info_size;
247 int addr; 210 int addr;
248 int tx_addr_max; 211 int tx_addr_max;
249 u32 np_tx_fifo_size; 212 u32 np_tx_fifo_size;
@@ -252,8 +215,7 @@ int dwc2_hsotg_tx_fifo_total_depth(struct dwc2_hsotg *hsotg)
252 hsotg->params.g_np_tx_fifo_size); 215 hsotg->params.g_np_tx_fifo_size);
253 216
254 /* Get Endpoint Info Control block size in DWORDs. */ 217 /* Get Endpoint Info Control block size in DWORDs. */
255 ep_info_size = dwc2_hsotg_ep_info_size(hsotg); 218 tx_addr_max = hsotg->hw_params.total_fifo_size;
256 tx_addr_max = hsotg->hw_params.total_fifo_size - ep_info_size;
257 219
258 addr = hsotg->params.g_rx_fifo_size + np_tx_fifo_size; 220 addr = hsotg->params.g_rx_fifo_size + np_tx_fifo_size;
259 if (tx_addr_max <= addr) 221 if (tx_addr_max <= addr)
diff --git a/drivers/usb/dwc2/params.c b/drivers/usb/dwc2/params.c
index ef73af6e03a9..03fd20f0b496 100644
--- a/drivers/usb/dwc2/params.c
+++ b/drivers/usb/dwc2/params.c
@@ -484,8 +484,7 @@ static void dwc2_check_param_tx_fifo_sizes(struct dwc2_hsotg *hsotg)
484 } 484 }
485 485
486 for (fifo = 1; fifo <= fifo_count; fifo++) { 486 for (fifo = 1; fifo <= fifo_count; fifo++) {
487 dptxfszn = (dwc2_readl(hsotg->regs + DPTXFSIZN(fifo)) & 487 dptxfszn = hsotg->hw_params.g_tx_fifo_size[fifo];
488 FIFOSIZE_DEPTH_MASK) >> FIFOSIZE_DEPTH_SHIFT;
489 488
490 if (hsotg->params.g_tx_fifo_size[fifo] < min || 489 if (hsotg->params.g_tx_fifo_size[fifo] < min ||
491 hsotg->params.g_tx_fifo_size[fifo] > dptxfszn) { 490 hsotg->params.g_tx_fifo_size[fifo] > dptxfszn) {
@@ -609,6 +608,7 @@ static void dwc2_get_dev_hwparams(struct dwc2_hsotg *hsotg)
609 struct dwc2_hw_params *hw = &hsotg->hw_params; 608 struct dwc2_hw_params *hw = &hsotg->hw_params;
610 bool forced; 609 bool forced;
611 u32 gnptxfsiz; 610 u32 gnptxfsiz;
611 int fifo, fifo_count;
612 612
613 if (hsotg->dr_mode == USB_DR_MODE_HOST) 613 if (hsotg->dr_mode == USB_DR_MODE_HOST)
614 return; 614 return;
@@ -617,6 +617,14 @@ static void dwc2_get_dev_hwparams(struct dwc2_hsotg *hsotg)
617 617
618 gnptxfsiz = dwc2_readl(hsotg->regs + GNPTXFSIZ); 618 gnptxfsiz = dwc2_readl(hsotg->regs + GNPTXFSIZ);
619 619
620 fifo_count = dwc2_hsotg_tx_fifo_count(hsotg);
621
622 for (fifo = 1; fifo <= fifo_count; fifo++) {
623 hw->g_tx_fifo_size[fifo] =
624 (dwc2_readl(hsotg->regs + DPTXFSIZN(fifo)) &
625 FIFOSIZE_DEPTH_MASK) >> FIFOSIZE_DEPTH_SHIFT;
626 }
627
620 if (forced) 628 if (forced)
621 dwc2_clear_force_mode(hsotg); 629 dwc2_clear_force_mode(hsotg);
622 630
@@ -661,14 +669,6 @@ int dwc2_get_hwparams(struct dwc2_hsotg *hsotg)
661 hwcfg4 = dwc2_readl(hsotg->regs + GHWCFG4); 669 hwcfg4 = dwc2_readl(hsotg->regs + GHWCFG4);
662 grxfsiz = dwc2_readl(hsotg->regs + GRXFSIZ); 670 grxfsiz = dwc2_readl(hsotg->regs + GRXFSIZ);
663 671
664 /*
665 * Host specific hardware parameters. Reading these parameters
666 * requires the controller to be in host mode. The mode will
667 * be forced, if necessary, to read these values.
668 */
669 dwc2_get_host_hwparams(hsotg);
670 dwc2_get_dev_hwparams(hsotg);
671
672 /* hwcfg1 */ 672 /* hwcfg1 */
673 hw->dev_ep_dirs = hwcfg1; 673 hw->dev_ep_dirs = hwcfg1;
674 674
@@ -711,6 +711,8 @@ int dwc2_get_hwparams(struct dwc2_hsotg *hsotg)
711 hw->en_multiple_tx_fifo = !!(hwcfg4 & GHWCFG4_DED_FIFO_EN); 711 hw->en_multiple_tx_fifo = !!(hwcfg4 & GHWCFG4_DED_FIFO_EN);
712 hw->num_dev_perio_in_ep = (hwcfg4 & GHWCFG4_NUM_DEV_PERIO_IN_EP_MASK) >> 712 hw->num_dev_perio_in_ep = (hwcfg4 & GHWCFG4_NUM_DEV_PERIO_IN_EP_MASK) >>
713 GHWCFG4_NUM_DEV_PERIO_IN_EP_SHIFT; 713 GHWCFG4_NUM_DEV_PERIO_IN_EP_SHIFT;
714 hw->num_dev_in_eps = (hwcfg4 & GHWCFG4_NUM_IN_EPS_MASK) >>
715 GHWCFG4_NUM_IN_EPS_SHIFT;
714 hw->dma_desc_enable = !!(hwcfg4 & GHWCFG4_DESC_DMA); 716 hw->dma_desc_enable = !!(hwcfg4 & GHWCFG4_DESC_DMA);
715 hw->power_optimized = !!(hwcfg4 & GHWCFG4_POWER_OPTIMIZ); 717 hw->power_optimized = !!(hwcfg4 & GHWCFG4_POWER_OPTIMIZ);
716 hw->utmi_phy_data_width = (hwcfg4 & GHWCFG4_UTMI_PHY_DATA_WIDTH_MASK) >> 718 hw->utmi_phy_data_width = (hwcfg4 & GHWCFG4_UTMI_PHY_DATA_WIDTH_MASK) >>
@@ -719,6 +721,13 @@ int dwc2_get_hwparams(struct dwc2_hsotg *hsotg)
719 /* fifo sizes */ 721 /* fifo sizes */
720 hw->rx_fifo_size = (grxfsiz & GRXFSIZ_DEPTH_MASK) >> 722 hw->rx_fifo_size = (grxfsiz & GRXFSIZ_DEPTH_MASK) >>
721 GRXFSIZ_DEPTH_SHIFT; 723 GRXFSIZ_DEPTH_SHIFT;
724 /*
725 * Host specific hardware parameters. Reading these parameters
726 * requires the controller to be in host mode. The mode will
727 * be forced, if necessary, to read these values.
728 */
729 dwc2_get_host_hwparams(hsotg);
730 dwc2_get_dev_hwparams(hsotg);
722 731
723 return 0; 732 return 0;
724} 733}
diff --git a/drivers/usb/dwc3/dwc3-of-simple.c b/drivers/usb/dwc3/dwc3-of-simple.c
index c4a4d7bd2766..7ae0eefc7cc7 100644
--- a/drivers/usb/dwc3/dwc3-of-simple.c
+++ b/drivers/usb/dwc3/dwc3-of-simple.c
@@ -51,8 +51,10 @@ static int dwc3_of_simple_clk_init(struct dwc3_of_simple *simple, int count)
51 51
52 clk = of_clk_get(np, i); 52 clk = of_clk_get(np, i);
53 if (IS_ERR(clk)) { 53 if (IS_ERR(clk)) {
54 while (--i >= 0) 54 while (--i >= 0) {
55 clk_disable_unprepare(simple->clks[i]);
55 clk_put(simple->clks[i]); 56 clk_put(simple->clks[i]);
57 }
56 return PTR_ERR(clk); 58 return PTR_ERR(clk);
57 } 59 }
58 60
@@ -203,6 +205,7 @@ static struct platform_driver dwc3_of_simple_driver = {
203 .driver = { 205 .driver = {
204 .name = "dwc3-of-simple", 206 .name = "dwc3-of-simple",
205 .of_match_table = of_dwc3_simple_match, 207 .of_match_table = of_dwc3_simple_match,
208 .pm = &dwc3_of_simple_dev_pm_ops,
206 }, 209 },
207}; 210};
208 211
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 981fd986cf82..639dd1b163a0 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -259,7 +259,7 @@ int dwc3_send_gadget_ep_cmd(struct dwc3_ep *dep, unsigned cmd,
259{ 259{
260 const struct usb_endpoint_descriptor *desc = dep->endpoint.desc; 260 const struct usb_endpoint_descriptor *desc = dep->endpoint.desc;
261 struct dwc3 *dwc = dep->dwc; 261 struct dwc3 *dwc = dep->dwc;
262 u32 timeout = 500; 262 u32 timeout = 1000;
263 u32 reg; 263 u32 reg;
264 264
265 int cmd_status = 0; 265 int cmd_status = 0;
@@ -912,7 +912,7 @@ static void __dwc3_prepare_one_trb(struct dwc3_ep *dep, struct dwc3_trb *trb,
912 */ 912 */
913 if (speed == USB_SPEED_HIGH) { 913 if (speed == USB_SPEED_HIGH) {
914 struct usb_ep *ep = &dep->endpoint; 914 struct usb_ep *ep = &dep->endpoint;
915 unsigned int mult = ep->mult - 1; 915 unsigned int mult = 2;
916 unsigned int maxp = usb_endpoint_maxp(ep->desc); 916 unsigned int maxp = usb_endpoint_maxp(ep->desc);
917 917
918 if (length <= (2 * maxp)) 918 if (length <= (2 * maxp))
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 0a19a76645ad..31cce7805eb2 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -508,8 +508,8 @@ choice
508 controller, and the relevant drivers for each function declared 508 controller, and the relevant drivers for each function declared
509 by the device. 509 by the device.
510 510
511endchoice
512
513source "drivers/usb/gadget/legacy/Kconfig" 511source "drivers/usb/gadget/legacy/Kconfig"
514 512
513endchoice
514
515endif # USB_GADGET 515endif # USB_GADGET
diff --git a/drivers/usb/gadget/legacy/Kconfig b/drivers/usb/gadget/legacy/Kconfig
index 9570bbeced4f..784bf86dad4f 100644
--- a/drivers/usb/gadget/legacy/Kconfig
+++ b/drivers/usb/gadget/legacy/Kconfig
@@ -13,14 +13,6 @@
13# both kinds of controller can also support "USB On-the-Go" (CONFIG_USB_OTG). 13# both kinds of controller can also support "USB On-the-Go" (CONFIG_USB_OTG).
14# 14#
15 15
16menuconfig USB_GADGET_LEGACY
17 bool "Legacy USB Gadget Support"
18 help
19 Legacy USB gadgets are USB gadgets that do not use the USB gadget
20 configfs interface.
21
22if USB_GADGET_LEGACY
23
24config USB_ZERO 16config USB_ZERO
25 tristate "Gadget Zero (DEVELOPMENT)" 17 tristate "Gadget Zero (DEVELOPMENT)"
26 select USB_LIBCOMPOSITE 18 select USB_LIBCOMPOSITE
@@ -487,7 +479,7 @@ endif
487# or video class gadget drivers), or specific hardware, here. 479# or video class gadget drivers), or specific hardware, here.
488config USB_G_WEBCAM 480config USB_G_WEBCAM
489 tristate "USB Webcam Gadget" 481 tristate "USB Webcam Gadget"
490 depends on VIDEO_DEV 482 depends on VIDEO_V4L2
491 select USB_LIBCOMPOSITE 483 select USB_LIBCOMPOSITE
492 select VIDEOBUF2_VMALLOC 484 select VIDEOBUF2_VMALLOC
493 select USB_F_UVC 485 select USB_F_UVC
@@ -498,5 +490,3 @@ config USB_G_WEBCAM
498 490
499 Say "y" to link the driver statically, or "m" to build a 491 Say "y" to link the driver statically, or "m" to build a
500 dynamically linked module called "g_webcam". 492 dynamically linked module called "g_webcam".
501
502endif
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 15f7d422885f..3a29b32a3bd0 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -971,10 +971,9 @@ int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id,
971 return 0; 971 return 0;
972 } 972 }
973 973
974 xhci->devs[slot_id] = kzalloc(sizeof(*xhci->devs[slot_id]), flags); 974 dev = kzalloc(sizeof(*dev), flags);
975 if (!xhci->devs[slot_id]) 975 if (!dev)
976 return 0; 976 return 0;
977 dev = xhci->devs[slot_id];
978 977
979 /* Allocate the (output) device context that will be used in the HC. */ 978 /* Allocate the (output) device context that will be used in the HC. */
980 dev->out_ctx = xhci_alloc_container_ctx(xhci, XHCI_CTX_TYPE_DEVICE, flags); 979 dev->out_ctx = xhci_alloc_container_ctx(xhci, XHCI_CTX_TYPE_DEVICE, flags);
@@ -1015,9 +1014,17 @@ int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id,
1015 1014
1016 trace_xhci_alloc_virt_device(dev); 1015 trace_xhci_alloc_virt_device(dev);
1017 1016
1017 xhci->devs[slot_id] = dev;
1018
1018 return 1; 1019 return 1;
1019fail: 1020fail:
1020 xhci_free_virt_device(xhci, slot_id); 1021
1022 if (dev->in_ctx)
1023 xhci_free_container_ctx(xhci, dev->in_ctx);
1024 if (dev->out_ctx)
1025 xhci_free_container_ctx(xhci, dev->out_ctx);
1026 kfree(dev);
1027
1021 return 0; 1028 return 0;
1022} 1029}
1023 1030
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 6eb87c6e4d24..c5cbc685c691 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -3112,7 +3112,7 @@ static u32 xhci_td_remainder(struct xhci_hcd *xhci, int transferred,
3112{ 3112{
3113 u32 maxp, total_packet_count; 3113 u32 maxp, total_packet_count;
3114 3114
3115 /* MTK xHCI is mostly 0.97 but contains some features from 1.0 */ 3115 /* MTK xHCI 0.96 contains some features from 1.0 */
3116 if (xhci->hci_version < 0x100 && !(xhci->quirks & XHCI_MTK_HOST)) 3116 if (xhci->hci_version < 0x100 && !(xhci->quirks & XHCI_MTK_HOST))
3117 return ((td_total_len - transferred) >> 10); 3117 return ((td_total_len - transferred) >> 10);
3118 3118
@@ -3121,8 +3121,8 @@ static u32 xhci_td_remainder(struct xhci_hcd *xhci, int transferred,
3121 trb_buff_len == td_total_len) 3121 trb_buff_len == td_total_len)
3122 return 0; 3122 return 0;
3123 3123
3124 /* for MTK xHCI, TD size doesn't include this TRB */ 3124 /* for MTK xHCI 0.96, TD size include this TRB, but not in 1.x */
3125 if (xhci->quirks & XHCI_MTK_HOST) 3125 if ((xhci->quirks & XHCI_MTK_HOST) && (xhci->hci_version < 0x100))
3126 trb_buff_len = 0; 3126 trb_buff_len = 0;
3127 3127
3128 maxp = usb_endpoint_maxp(&urb->ep->desc); 3128 maxp = usb_endpoint_maxp(&urb->ep->desc);
diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
index 0397606a211b..6c036de63272 100644
--- a/drivers/usb/musb/da8xx.c
+++ b/drivers/usb/musb/da8xx.c
@@ -284,7 +284,15 @@ static irqreturn_t da8xx_musb_interrupt(int irq, void *hci)
284 musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE; 284 musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE;
285 portstate(musb->port1_status |= USB_PORT_STAT_POWER); 285 portstate(musb->port1_status |= USB_PORT_STAT_POWER);
286 del_timer(&musb->dev_timer); 286 del_timer(&musb->dev_timer);
287 } else { 287 } else if (!(musb->int_usb & MUSB_INTR_BABBLE)) {
288 /*
289 * When babble condition happens, drvvbus interrupt
290 * is also generated. Ignore this drvvbus interrupt
291 * and let babble interrupt handler recovers the
292 * controller; otherwise, the host-mode flag is lost
293 * due to the MUSB_DEV_MODE() call below and babble
294 * recovery logic will not be called.
295 */
288 musb->is_active = 0; 296 musb->is_active = 0;
289 MUSB_DEV_MODE(musb); 297 MUSB_DEV_MODE(musb);
290 otg->default_a = 0; 298 otg->default_a = 0;
diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h
index 2968046e7c05..f72d045ee9ef 100644
--- a/drivers/usb/storage/unusual_devs.h
+++ b/drivers/usb/storage/unusual_devs.h
@@ -2100,6 +2100,13 @@ UNUSUAL_DEV( 0x152d, 0x0567, 0x0114, 0x0116,
2100 USB_SC_DEVICE, USB_PR_DEVICE, NULL, 2100 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
2101 US_FL_BROKEN_FUA ), 2101 US_FL_BROKEN_FUA ),
2102 2102
2103/* Reported by David Kozub <zub@linux.fjfi.cvut.cz> */
2104UNUSUAL_DEV(0x152d, 0x0578, 0x0000, 0x9999,
2105 "JMicron",
2106 "JMS567",
2107 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
2108 US_FL_BROKEN_FUA),
2109
2103/* 2110/*
2104 * Reported by Alexandre Oliva <oliva@lsd.ic.unicamp.br> 2111 * Reported by Alexandre Oliva <oliva@lsd.ic.unicamp.br>
2105 * JMicron responds to USN and several other SCSI ioctls with a 2112 * JMicron responds to USN and several other SCSI ioctls with a
diff --git a/drivers/usb/storage/unusual_uas.h b/drivers/usb/storage/unusual_uas.h
index d520374a824e..e6127fb21c12 100644
--- a/drivers/usb/storage/unusual_uas.h
+++ b/drivers/usb/storage/unusual_uas.h
@@ -129,6 +129,13 @@ UNUSUAL_DEV(0x152d, 0x0567, 0x0000, 0x9999,
129 USB_SC_DEVICE, USB_PR_DEVICE, NULL, 129 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
130 US_FL_BROKEN_FUA | US_FL_NO_REPORT_OPCODES), 130 US_FL_BROKEN_FUA | US_FL_NO_REPORT_OPCODES),
131 131
132/* Reported-by: David Kozub <zub@linux.fjfi.cvut.cz> */
133UNUSUAL_DEV(0x152d, 0x0578, 0x0000, 0x9999,
134 "JMicron",
135 "JMS567",
136 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
137 US_FL_BROKEN_FUA),
138
132/* Reported-by: Hans de Goede <hdegoede@redhat.com> */ 139/* Reported-by: Hans de Goede <hdegoede@redhat.com> */
133UNUSUAL_DEV(0x2109, 0x0711, 0x0000, 0x9999, 140UNUSUAL_DEV(0x2109, 0x0711, 0x0000, 0x9999,
134 "VIA", 141 "VIA",
diff --git a/drivers/usb/usbip/stub_rx.c b/drivers/usb/usbip/stub_rx.c
index 536e037f541f..493ac2928391 100644
--- a/drivers/usb/usbip/stub_rx.c
+++ b/drivers/usb/usbip/stub_rx.c
@@ -322,23 +322,34 @@ static struct stub_priv *stub_priv_alloc(struct stub_device *sdev,
322 return priv; 322 return priv;
323} 323}
324 324
325static int get_pipe(struct stub_device *sdev, int epnum, int dir) 325static int get_pipe(struct stub_device *sdev, struct usbip_header *pdu)
326{ 326{
327 struct usb_device *udev = sdev->udev; 327 struct usb_device *udev = sdev->udev;
328 struct usb_host_endpoint *ep; 328 struct usb_host_endpoint *ep;
329 struct usb_endpoint_descriptor *epd = NULL; 329 struct usb_endpoint_descriptor *epd = NULL;
330 int epnum = pdu->base.ep;
331 int dir = pdu->base.direction;
332
333 if (epnum < 0 || epnum > 15)
334 goto err_ret;
330 335
331 if (dir == USBIP_DIR_IN) 336 if (dir == USBIP_DIR_IN)
332 ep = udev->ep_in[epnum & 0x7f]; 337 ep = udev->ep_in[epnum & 0x7f];
333 else 338 else
334 ep = udev->ep_out[epnum & 0x7f]; 339 ep = udev->ep_out[epnum & 0x7f];
335 if (!ep) { 340 if (!ep)
336 dev_err(&sdev->udev->dev, "no such endpoint?, %d\n", 341 goto err_ret;
337 epnum);
338 BUG();
339 }
340 342
341 epd = &ep->desc; 343 epd = &ep->desc;
344
345 /* validate transfer_buffer_length */
346 if (pdu->u.cmd_submit.transfer_buffer_length > INT_MAX) {
347 dev_err(&sdev->udev->dev,
348 "CMD_SUBMIT: -EMSGSIZE transfer_buffer_length %d\n",
349 pdu->u.cmd_submit.transfer_buffer_length);
350 return -1;
351 }
352
342 if (usb_endpoint_xfer_control(epd)) { 353 if (usb_endpoint_xfer_control(epd)) {
343 if (dir == USBIP_DIR_OUT) 354 if (dir == USBIP_DIR_OUT)
344 return usb_sndctrlpipe(udev, epnum); 355 return usb_sndctrlpipe(udev, epnum);
@@ -361,15 +372,31 @@ static int get_pipe(struct stub_device *sdev, int epnum, int dir)
361 } 372 }
362 373
363 if (usb_endpoint_xfer_isoc(epd)) { 374 if (usb_endpoint_xfer_isoc(epd)) {
375 /* validate packet size and number of packets */
376 unsigned int maxp, packets, bytes;
377
378 maxp = usb_endpoint_maxp(epd);
379 maxp *= usb_endpoint_maxp_mult(epd);
380 bytes = pdu->u.cmd_submit.transfer_buffer_length;
381 packets = DIV_ROUND_UP(bytes, maxp);
382
383 if (pdu->u.cmd_submit.number_of_packets < 0 ||
384 pdu->u.cmd_submit.number_of_packets > packets) {
385 dev_err(&sdev->udev->dev,
386 "CMD_SUBMIT: isoc invalid num packets %d\n",
387 pdu->u.cmd_submit.number_of_packets);
388 return -1;
389 }
364 if (dir == USBIP_DIR_OUT) 390 if (dir == USBIP_DIR_OUT)
365 return usb_sndisocpipe(udev, epnum); 391 return usb_sndisocpipe(udev, epnum);
366 else 392 else
367 return usb_rcvisocpipe(udev, epnum); 393 return usb_rcvisocpipe(udev, epnum);
368 } 394 }
369 395
396err_ret:
370 /* NOT REACHED */ 397 /* NOT REACHED */
371 dev_err(&sdev->udev->dev, "get pipe, epnum %d\n", epnum); 398 dev_err(&sdev->udev->dev, "CMD_SUBMIT: invalid epnum %d\n", epnum);
372 return 0; 399 return -1;
373} 400}
374 401
375static void masking_bogus_flags(struct urb *urb) 402static void masking_bogus_flags(struct urb *urb)
@@ -433,7 +460,10 @@ static void stub_recv_cmd_submit(struct stub_device *sdev,
433 struct stub_priv *priv; 460 struct stub_priv *priv;
434 struct usbip_device *ud = &sdev->ud; 461 struct usbip_device *ud = &sdev->ud;
435 struct usb_device *udev = sdev->udev; 462 struct usb_device *udev = sdev->udev;
436 int pipe = get_pipe(sdev, pdu->base.ep, pdu->base.direction); 463 int pipe = get_pipe(sdev, pdu);
464
465 if (pipe == -1)
466 return;
437 467
438 priv = stub_priv_alloc(sdev, pdu); 468 priv = stub_priv_alloc(sdev, pdu);
439 if (!priv) 469 if (!priv)
@@ -452,7 +482,8 @@ static void stub_recv_cmd_submit(struct stub_device *sdev,
452 } 482 }
453 483
454 /* allocate urb transfer buffer, if needed */ 484 /* allocate urb transfer buffer, if needed */
455 if (pdu->u.cmd_submit.transfer_buffer_length > 0) { 485 if (pdu->u.cmd_submit.transfer_buffer_length > 0 &&
486 pdu->u.cmd_submit.transfer_buffer_length <= INT_MAX) {
456 priv->urb->transfer_buffer = 487 priv->urb->transfer_buffer =
457 kzalloc(pdu->u.cmd_submit.transfer_buffer_length, 488 kzalloc(pdu->u.cmd_submit.transfer_buffer_length,
458 GFP_KERNEL); 489 GFP_KERNEL);
diff --git a/drivers/usb/usbip/stub_tx.c b/drivers/usb/usbip/stub_tx.c
index b18bce96c212..53172b1f6257 100644
--- a/drivers/usb/usbip/stub_tx.c
+++ b/drivers/usb/usbip/stub_tx.c
@@ -167,6 +167,13 @@ static int stub_send_ret_submit(struct stub_device *sdev)
167 memset(&pdu_header, 0, sizeof(pdu_header)); 167 memset(&pdu_header, 0, sizeof(pdu_header));
168 memset(&msg, 0, sizeof(msg)); 168 memset(&msg, 0, sizeof(msg));
169 169
170 if (urb->actual_length > 0 && !urb->transfer_buffer) {
171 dev_err(&sdev->udev->dev,
172 "urb: actual_length %d transfer_buffer null\n",
173 urb->actual_length);
174 return -1;
175 }
176
170 if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) 177 if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS)
171 iovnum = 2 + urb->number_of_packets; 178 iovnum = 2 + urb->number_of_packets;
172 else 179 else
diff --git a/drivers/usb/usbip/usbip_common.h b/drivers/usb/usbip/usbip_common.h
index e5de35c8c505..473fb8a87289 100644
--- a/drivers/usb/usbip/usbip_common.h
+++ b/drivers/usb/usbip/usbip_common.h
@@ -256,6 +256,7 @@ struct usbip_device {
256 /* lock for status */ 256 /* lock for status */
257 spinlock_t lock; 257 spinlock_t lock;
258 258
259 int sockfd;
259 struct socket *tcp_socket; 260 struct socket *tcp_socket;
260 261
261 struct task_struct *tcp_rx; 262 struct task_struct *tcp_rx;
diff --git a/drivers/usb/usbip/vhci_sysfs.c b/drivers/usb/usbip/vhci_sysfs.c
index e78f7472cac4..091f76b7196d 100644
--- a/drivers/usb/usbip/vhci_sysfs.c
+++ b/drivers/usb/usbip/vhci_sysfs.c
@@ -17,15 +17,20 @@
17 17
18/* 18/*
19 * output example: 19 * output example:
20 * hub port sta spd dev socket local_busid 20 * hub port sta spd dev sockfd local_busid
21 * hs 0000 004 000 00000000 c5a7bb80 1-2.3 21 * hs 0000 004 000 00000000 3 1-2.3
22 * ................................................ 22 * ................................................
23 * ss 0008 004 000 00000000 d8cee980 2-3.4 23 * ss 0008 004 000 00000000 4 2-3.4
24 * ................................................ 24 * ................................................
25 * 25 *
26 * IP address can be retrieved from a socket pointer address by looking 26 * Output includes socket fd instead of socket pointer address to avoid
27 * up /proc/net/{tcp,tcp6}. Also, a userland program may remember a 27 * leaking kernel memory address in:
28 * port number and its peer IP address. 28 * /sys/devices/platform/vhci_hcd.0/status and in debug output.
29 * The socket pointer address is not used at the moment and it was made
30 * visible as a convenient way to find IP address from socket pointer
31 * address by looking up /proc/net/{tcp,tcp6}. As this opens a security
32 * hole, the change is made to use sockfd instead.
33 *
29 */ 34 */
30static void port_show_vhci(char **out, int hub, int port, struct vhci_device *vdev) 35static void port_show_vhci(char **out, int hub, int port, struct vhci_device *vdev)
31{ 36{
@@ -39,8 +44,8 @@ static void port_show_vhci(char **out, int hub, int port, struct vhci_device *vd
39 if (vdev->ud.status == VDEV_ST_USED) { 44 if (vdev->ud.status == VDEV_ST_USED) {
40 *out += sprintf(*out, "%03u %08x ", 45 *out += sprintf(*out, "%03u %08x ",
41 vdev->speed, vdev->devid); 46 vdev->speed, vdev->devid);
42 *out += sprintf(*out, "%16p %s", 47 *out += sprintf(*out, "%u %s",
43 vdev->ud.tcp_socket, 48 vdev->ud.sockfd,
44 dev_name(&vdev->udev->dev)); 49 dev_name(&vdev->udev->dev));
45 50
46 } else { 51 } else {
@@ -160,7 +165,8 @@ static ssize_t nports_show(struct device *dev, struct device_attribute *attr,
160 char *s = out; 165 char *s = out;
161 166
162 /* 167 /*
163 * Half the ports are for SPEED_HIGH and half for SPEED_SUPER, thus the * 2. 168 * Half the ports are for SPEED_HIGH and half for SPEED_SUPER,
169 * thus the * 2.
164 */ 170 */
165 out += sprintf(out, "%d\n", VHCI_PORTS * vhci_num_controllers); 171 out += sprintf(out, "%d\n", VHCI_PORTS * vhci_num_controllers);
166 return out - s; 172 return out - s;
@@ -366,6 +372,7 @@ static ssize_t store_attach(struct device *dev, struct device_attribute *attr,
366 372
367 vdev->devid = devid; 373 vdev->devid = devid;
368 vdev->speed = speed; 374 vdev->speed = speed;
375 vdev->ud.sockfd = sockfd;
369 vdev->ud.tcp_socket = socket; 376 vdev->ud.tcp_socket = socket;
370 vdev->ud.status = VDEV_ST_NOTASSIGNED; 377 vdev->ud.status = VDEV_ST_NOTASSIGNED;
371 378
diff --git a/tools/usb/usbip/libsrc/vhci_driver.c b/tools/usb/usbip/libsrc/vhci_driver.c
index 8a1cd1616de4..c9c81614a66a 100644
--- a/tools/usb/usbip/libsrc/vhci_driver.c
+++ b/tools/usb/usbip/libsrc/vhci_driver.c
@@ -50,14 +50,14 @@ static int parse_status(const char *value)
50 50
51 while (*c != '\0') { 51 while (*c != '\0') {
52 int port, status, speed, devid; 52 int port, status, speed, devid;
53 unsigned long socket; 53 int sockfd;
54 char lbusid[SYSFS_BUS_ID_SIZE]; 54 char lbusid[SYSFS_BUS_ID_SIZE];
55 struct usbip_imported_device *idev; 55 struct usbip_imported_device *idev;
56 char hub[3]; 56 char hub[3];
57 57
58 ret = sscanf(c, "%2s %d %d %d %x %lx %31s\n", 58 ret = sscanf(c, "%2s %d %d %d %x %u %31s\n",
59 hub, &port, &status, &speed, 59 hub, &port, &status, &speed,
60 &devid, &socket, lbusid); 60 &devid, &sockfd, lbusid);
61 61
62 if (ret < 5) { 62 if (ret < 5) {
63 dbg("sscanf failed: %d", ret); 63 dbg("sscanf failed: %d", ret);
@@ -66,7 +66,7 @@ static int parse_status(const char *value)
66 66
67 dbg("hub %s port %d status %d speed %d devid %x", 67 dbg("hub %s port %d status %d speed %d devid %x",
68 hub, port, status, speed, devid); 68 hub, port, status, speed, devid);
69 dbg("socket %lx lbusid %s", socket, lbusid); 69 dbg("sockfd %u lbusid %s", sockfd, lbusid);
70 70
71 /* if a device is connected, look at it */ 71 /* if a device is connected, look at it */
72 idev = &vhci_driver->idev[port]; 72 idev = &vhci_driver->idev[port];
@@ -106,7 +106,7 @@ static int parse_status(const char *value)
106 return 0; 106 return 0;
107} 107}
108 108
109#define MAX_STATUS_NAME 16 109#define MAX_STATUS_NAME 18
110 110
111static int refresh_imported_device_list(void) 111static int refresh_imported_device_list(void)
112{ 112{