Skip to content

Commit fb27bc0

Browse files
committed
Merge tag 'usb-5.7-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb
Pull USB fixes from Greg KH: "Here are a number of USB fixes for 5.7-rc6 The "largest" in here is a bunch of raw-gadget fixes and api changes as the driver just showed up in -rc1 and work has been done to fix up some uapi issues found with the original submission, before it shows up in a -final release. Other than that, a bunch of other small USB gadget fixes, xhci fixes, some quirks, andother tiny fixes for reported issues. All of these have been in linux-next with no reported issues" * tag 'usb-5.7-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: (26 commits) USB: gadget: fix illegal array access in binding with UDC usb: core: hub: limit HUB_QUIRK_DISABLE_AUTOSUSPEND to USB5534B USB: usbfs: fix mmap dma mismatch usb: host: xhci-plat: keep runtime active when removing host usb: xhci: Fix NULL pointer dereference when enqueuing trbs from urb sg list usb: cdns3: gadget: make a bunch of functions static usb: mtu3: constify struct debugfs_reg32 usb: gadget: udc: atmel: Make some symbols static usb: raw-gadget: fix null-ptr-deref when reenabling endpoints usb: raw-gadget: documentation updates usb: raw-gadget: support stalling/halting/wedging endpoints usb: raw-gadget: fix gadget endpoint selection usb: raw-gadget: improve uapi headers comments usb: typec: mux: intel: Fix DP_HPD_LVL bit field usb: raw-gadget: fix return value of ep read ioctls usb: dwc3: select USB_ROLE_SWITCH usb: gadget: legacy: fix error return code in gncm_bind() usb: gadget: legacy: fix error return code in cdc_bind() usb: gadget: legacy: fix redundant initialization warnings usb: gadget: tegra-xudc: Fix idle suspend/resume ...
2 parents b48397c + 1575358 commit fb27bc0

File tree

22 files changed

+448
-123
lines changed

22 files changed

+448
-123
lines changed

Documentation/usb/raw-gadget.rst

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ differences are:
2727
3. Raw Gadget provides a way to select a UDC device/driver to bind to,
2828
while GadgetFS currently binds to the first available UDC.
2929

30-
4. Raw Gadget uses predictable endpoint names (handles) across different
31-
UDCs (as long as UDCs have enough endpoints of each required transfer
32-
type).
30+
4. Raw Gadget explicitly exposes information about endpoints addresses and
31+
capabilities allowing a user to write UDC-agnostic gadgets.
3332

3433
5. Raw Gadget has ioctl-based interface instead of a filesystem-based one.
3534

@@ -50,12 +49,36 @@ The typical usage of Raw Gadget looks like:
5049
Raw Gadget and react to those depending on what kind of USB device
5150
needs to be emulated.
5251

52+
Note, that some UDC drivers have fixed addresses assigned to endpoints, and
53+
therefore arbitrary endpoint addresses can't be used in the descriptors.
54+
Nevertheles, Raw Gadget provides a UDC-agnostic way to write USB gadgets.
55+
Once a USB_RAW_EVENT_CONNECT event is received via USB_RAW_IOCTL_EVENT_FETCH,
56+
the USB_RAW_IOCTL_EPS_INFO ioctl can be used to find out information about
57+
endpoints that the UDC driver has. Based on that information, the user must
58+
chose UDC endpoints that will be used for the gadget being emulated, and
59+
properly assign addresses in endpoint descriptors.
60+
61+
You can find usage examples (along with a test suite) here:
62+
63+
https://github.com/xairy/raw-gadget
64+
65+
Internal details
66+
~~~~~~~~~~~~~~~~
67+
68+
Currently every endpoint read/write ioctl submits a USB request and waits until
69+
its completion. This is the desired mode for coverage-guided fuzzing (as we'd
70+
like all USB request processing happen during the lifetime of a syscall),
71+
and must be kept in the implementation. (This might be slow for real world
72+
applications, thus the O_NONBLOCK improvement suggestion below.)
73+
5374
Potential future improvements
5475
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5576

56-
- Implement ioctl's for setting/clearing halt status on endpoints.
57-
58-
- Reporting more events (suspend, resume, etc.) through
59-
USB_RAW_IOCTL_EVENT_FETCH.
77+
- Report more events (suspend, resume, etc.) through USB_RAW_IOCTL_EVENT_FETCH.
6078

6179
- Support O_NONBLOCK I/O.
80+
81+
- Support USB 3 features (accept SS endpoint companion descriptor when
82+
enabling endpoints; allow providing stream_id for bulk transfers).
83+
84+
- Support ISO transfer features (expose frame_number for completed requests).

drivers/usb/cdns3/gadget.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ static int cdns3_ep_run_stream_transfer(struct cdns3_endpoint *priv_ep,
8282
* @ptr: address of device controller register to be read and changed
8383
* @mask: bits requested to clar
8484
*/
85-
void cdns3_clear_register_bit(void __iomem *ptr, u32 mask)
85+
static void cdns3_clear_register_bit(void __iomem *ptr, u32 mask)
8686
{
8787
mask = readl(ptr) & ~mask;
8888
writel(mask, ptr);
@@ -137,7 +137,7 @@ struct usb_request *cdns3_next_request(struct list_head *list)
137137
*
138138
* Returns buffer or NULL if no buffers in list
139139
*/
140-
struct cdns3_aligned_buf *cdns3_next_align_buf(struct list_head *list)
140+
static struct cdns3_aligned_buf *cdns3_next_align_buf(struct list_head *list)
141141
{
142142
return list_first_entry_or_null(list, struct cdns3_aligned_buf, list);
143143
}
@@ -148,7 +148,7 @@ struct cdns3_aligned_buf *cdns3_next_align_buf(struct list_head *list)
148148
*
149149
* Returns request or NULL if no requests in list
150150
*/
151-
struct cdns3_request *cdns3_next_priv_request(struct list_head *list)
151+
static struct cdns3_request *cdns3_next_priv_request(struct list_head *list)
152152
{
153153
return list_first_entry_or_null(list, struct cdns3_request, list);
154154
}
@@ -190,7 +190,7 @@ dma_addr_t cdns3_trb_virt_to_dma(struct cdns3_endpoint *priv_ep,
190190
return priv_ep->trb_pool_dma + offset;
191191
}
192192

193-
int cdns3_ring_size(struct cdns3_endpoint *priv_ep)
193+
static int cdns3_ring_size(struct cdns3_endpoint *priv_ep)
194194
{
195195
switch (priv_ep->type) {
196196
case USB_ENDPOINT_XFER_ISOC:
@@ -345,7 +345,7 @@ static void cdns3_ep_inc_deq(struct cdns3_endpoint *priv_ep)
345345
cdns3_ep_inc_trb(&priv_ep->dequeue, &priv_ep->ccs, priv_ep->num_trbs);
346346
}
347347

348-
void cdns3_move_deq_to_next_trb(struct cdns3_request *priv_req)
348+
static void cdns3_move_deq_to_next_trb(struct cdns3_request *priv_req)
349349
{
350350
struct cdns3_endpoint *priv_ep = priv_req->priv_ep;
351351
int current_trb = priv_req->start_trb;
@@ -511,7 +511,7 @@ static void cdns3_wa2_descmiss_copy_data(struct cdns3_endpoint *priv_ep,
511511
}
512512
}
513513

514-
struct usb_request *cdns3_wa2_gadget_giveback(struct cdns3_device *priv_dev,
514+
static struct usb_request *cdns3_wa2_gadget_giveback(struct cdns3_device *priv_dev,
515515
struct cdns3_endpoint *priv_ep,
516516
struct cdns3_request *priv_req)
517517
{
@@ -551,7 +551,7 @@ struct usb_request *cdns3_wa2_gadget_giveback(struct cdns3_device *priv_dev,
551551
return &priv_req->request;
552552
}
553553

554-
int cdns3_wa2_gadget_ep_queue(struct cdns3_device *priv_dev,
554+
static int cdns3_wa2_gadget_ep_queue(struct cdns3_device *priv_dev,
555555
struct cdns3_endpoint *priv_ep,
556556
struct cdns3_request *priv_req)
557557
{
@@ -836,7 +836,7 @@ void cdns3_gadget_giveback(struct cdns3_endpoint *priv_ep,
836836
cdns3_gadget_ep_free_request(&priv_ep->endpoint, request);
837837
}
838838

839-
void cdns3_wa1_restore_cycle_bit(struct cdns3_endpoint *priv_ep)
839+
static void cdns3_wa1_restore_cycle_bit(struct cdns3_endpoint *priv_ep)
840840
{
841841
/* Work around for stale data address in TRB*/
842842
if (priv_ep->wa1_set) {
@@ -1904,7 +1904,7 @@ static int cdns3_ep_onchip_buffer_reserve(struct cdns3_device *priv_dev,
19041904
return 0;
19051905
}
19061906

1907-
void cdns3_stream_ep_reconfig(struct cdns3_device *priv_dev,
1907+
static void cdns3_stream_ep_reconfig(struct cdns3_device *priv_dev,
19081908
struct cdns3_endpoint *priv_ep)
19091909
{
19101910
if (!priv_ep->use_streams || priv_dev->gadget.speed < USB_SPEED_SUPER)
@@ -1925,7 +1925,7 @@ void cdns3_stream_ep_reconfig(struct cdns3_device *priv_dev,
19251925
EP_CFG_TDL_CHK | EP_CFG_SID_CHK);
19261926
}
19271927

1928-
void cdns3_configure_dmult(struct cdns3_device *priv_dev,
1928+
static void cdns3_configure_dmult(struct cdns3_device *priv_dev,
19291929
struct cdns3_endpoint *priv_ep)
19301930
{
19311931
struct cdns3_usb_regs __iomem *regs = priv_dev->regs;
@@ -2548,7 +2548,7 @@ int cdns3_gadget_ep_dequeue(struct usb_ep *ep,
25482548
link_trb = priv_req->trb;
25492549

25502550
/* Update ring only if removed request is on pending_req_list list */
2551-
if (req_on_hw_ring) {
2551+
if (req_on_hw_ring && link_trb) {
25522552
link_trb->buffer = TRB_BUFFER(priv_ep->trb_pool_dma +
25532553
((priv_req->end_trb + 1) * TRB_SIZE));
25542554
link_trb->control = (link_trb->control & TRB_CYCLE) |

drivers/usb/core/devio.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,19 @@ static int usbdev_mmap(struct file *file, struct vm_area_struct *vma)
251251
usbm->vma_use_count = 1;
252252
INIT_LIST_HEAD(&usbm->memlist);
253253

254-
if (dma_mmap_coherent(hcd->self.sysdev, vma, mem, dma_handle, size)) {
255-
dec_usb_memory_use_count(usbm, &usbm->vma_use_count);
256-
return -EAGAIN;
254+
if (hcd->localmem_pool || !hcd_uses_dma(hcd)) {
255+
if (remap_pfn_range(vma, vma->vm_start,
256+
virt_to_phys(usbm->mem) >> PAGE_SHIFT,
257+
size, vma->vm_page_prot) < 0) {
258+
dec_usb_memory_use_count(usbm, &usbm->vma_use_count);
259+
return -EAGAIN;
260+
}
261+
} else {
262+
if (dma_mmap_coherent(hcd->self.sysdev, vma, mem, dma_handle,
263+
size)) {
264+
dec_usb_memory_use_count(usbm, &usbm->vma_use_count);
265+
return -EAGAIN;
266+
}
257267
}
258268

259269
vma->vm_flags |= VM_IO;

drivers/usb/core/hub.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
#define USB_VENDOR_GENESYS_LOGIC 0x05e3
4141
#define USB_VENDOR_SMSC 0x0424
42+
#define USB_PRODUCT_USB5534B 0x5534
4243
#define HUB_QUIRK_CHECK_PORT_AUTOSUSPEND 0x01
4344
#define HUB_QUIRK_DISABLE_AUTOSUSPEND 0x02
4445

@@ -5621,8 +5622,11 @@ static void hub_event(struct work_struct *work)
56215622
}
56225623

56235624
static const struct usb_device_id hub_id_table[] = {
5624-
{ .match_flags = USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_INT_CLASS,
5625+
{ .match_flags = USB_DEVICE_ID_MATCH_VENDOR
5626+
| USB_DEVICE_ID_MATCH_PRODUCT
5627+
| USB_DEVICE_ID_MATCH_INT_CLASS,
56255628
.idVendor = USB_VENDOR_SMSC,
5629+
.idProduct = USB_PRODUCT_USB5534B,
56265630
.bInterfaceClass = USB_CLASS_HUB,
56275631
.driver_info = HUB_QUIRK_DISABLE_AUTOSUSPEND},
56285632
{ .match_flags = USB_DEVICE_ID_MATCH_VENDOR

drivers/usb/dwc3/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ config USB_DWC3
44
tristate "DesignWare USB3 DRD Core Support"
55
depends on (USB || USB_GADGET) && HAS_DMA
66
select USB_XHCI_PLATFORM if USB_XHCI_HCD
7+
select USB_ROLE_SWITCH if USB_DWC3_DUAL_ROLE
78
help
89
Say Y or M here if your system has a Dual Role SuperSpeed
910
USB controller based on the DesignWare USB3 IP Core.

drivers/usb/dwc3/dwc3-pci.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ static const struct property_entry dwc3_pci_intel_properties[] = {
114114

115115
static const struct property_entry dwc3_pci_mrfld_properties[] = {
116116
PROPERTY_ENTRY_STRING("dr_mode", "otg"),
117+
PROPERTY_ENTRY_STRING("linux,extcon-name", "mrfld_bcove_pwrsrc"),
117118
PROPERTY_ENTRY_BOOL("linux,sysdev_is_parent"),
118119
{}
119120
};

drivers/usb/dwc3/gadget.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2483,9 +2483,6 @@ static int dwc3_gadget_ep_reclaim_trb_sg(struct dwc3_ep *dep,
24832483
for_each_sg(sg, s, pending, i) {
24842484
trb = &dep->trb_pool[dep->trb_dequeue];
24852485

2486-
if (trb->ctrl & DWC3_TRB_CTRL_HWO)
2487-
break;
2488-
24892486
req->sg = sg_next(s);
24902487
req->num_pending_sgs--;
24912488

drivers/usb/gadget/configfs.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ static ssize_t gadget_dev_desc_UDC_store(struct config_item *item,
260260
char *name;
261261
int ret;
262262

263+
if (strlen(page) < len)
264+
return -EOVERFLOW;
265+
263266
name = kstrdup(page, GFP_KERNEL);
264267
if (!name)
265268
return -ENOMEM;

drivers/usb/gadget/legacy/audio.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,10 @@ static int audio_bind(struct usb_composite_dev *cdev)
300300
struct usb_descriptor_header *usb_desc;
301301

302302
usb_desc = usb_otg_descriptor_alloc(cdev->gadget);
303-
if (!usb_desc)
303+
if (!usb_desc) {
304+
status = -ENOMEM;
304305
goto fail;
306+
}
305307
usb_otg_descriptor_init(cdev->gadget, usb_desc);
306308
otg_desc[0] = usb_desc;
307309
otg_desc[1] = NULL;

drivers/usb/gadget/legacy/cdc2.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,10 @@ static int cdc_bind(struct usb_composite_dev *cdev)
179179
struct usb_descriptor_header *usb_desc;
180180

181181
usb_desc = usb_otg_descriptor_alloc(gadget);
182-
if (!usb_desc)
182+
if (!usb_desc) {
183+
status = -ENOMEM;
183184
goto fail1;
185+
}
184186
usb_otg_descriptor_init(gadget, usb_desc);
185187
otg_desc[0] = usb_desc;
186188
otg_desc[1] = NULL;

0 commit comments

Comments
 (0)