Skip to content

Commit bfb0e9b

Browse files
committed
Merge tag 'usb-4.19-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb
I wrote: "USB fixes for 4.19-rc6 Here are some small USB core and driver fixes for reported issues for 4.19-rc6. The most visible is the oops fix for when the USB core is built into the kernel that is present in 4.18. Turns out not many people actually do that so it went unnoticed for a while. The rest is some tiny typec, musb, and other core fixes. All have been in linux-next with no reported issues." * tag 'usb-4.19-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: usb: typec: mux: Take care of driver module reference counting usb: core: safely deal with the dynamic quirk lists usb: roles: Take care of driver module reference counting USB: handle NULL config in usb_find_alt_setting() USB: fix error handling in usb_driver_claim_interface() USB: remove LPM management from usb_driver_claim_interface() USB: usbdevfs: restore warning for nonsensical flags USB: usbdevfs: sanitize flags more Revert "usb: cdc-wdm: Fix a sleep-in-atomic-context bug in service_outstanding_interrupt()" usb: musb: dsps: do not disable CPPI41 irq in driver teardown
2 parents ccf791e + 3e3b819 commit bfb0e9b

File tree

8 files changed

+66
-37
lines changed

8 files changed

+66
-37
lines changed

drivers/usb/class/cdc-wdm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ static int service_outstanding_interrupt(struct wdm_device *desc)
460460

461461
set_bit(WDM_RESPONDING, &desc->flags);
462462
spin_unlock_irq(&desc->iuspin);
463-
rv = usb_submit_urb(desc->response, GFP_ATOMIC);
463+
rv = usb_submit_urb(desc->response, GFP_KERNEL);
464464
spin_lock_irq(&desc->iuspin);
465465
if (rv) {
466466
dev_err(&desc->intf->dev,

drivers/usb/common/roles.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,15 @@ static void *usb_role_switch_match(struct device_connection *con, int ep,
109109
*/
110110
struct usb_role_switch *usb_role_switch_get(struct device *dev)
111111
{
112-
return device_connection_find_match(dev, "usb-role-switch", NULL,
113-
usb_role_switch_match);
112+
struct usb_role_switch *sw;
113+
114+
sw = device_connection_find_match(dev, "usb-role-switch", NULL,
115+
usb_role_switch_match);
116+
117+
if (!IS_ERR_OR_NULL(sw))
118+
WARN_ON(!try_module_get(sw->dev.parent->driver->owner));
119+
120+
return sw;
114121
}
115122
EXPORT_SYMBOL_GPL(usb_role_switch_get);
116123

@@ -122,8 +129,10 @@ EXPORT_SYMBOL_GPL(usb_role_switch_get);
122129
*/
123130
void usb_role_switch_put(struct usb_role_switch *sw)
124131
{
125-
if (!IS_ERR_OR_NULL(sw))
132+
if (!IS_ERR_OR_NULL(sw)) {
126133
put_device(&sw->dev);
134+
module_put(sw->dev.parent->driver->owner);
135+
}
127136
}
128137
EXPORT_SYMBOL_GPL(usb_role_switch_put);
129138

drivers/usb/core/devio.c

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,10 +1434,13 @@ static int proc_do_submiturb(struct usb_dev_state *ps, struct usbdevfs_urb *uurb
14341434
struct async *as = NULL;
14351435
struct usb_ctrlrequest *dr = NULL;
14361436
unsigned int u, totlen, isofrmlen;
1437-
int i, ret, is_in, num_sgs = 0, ifnum = -1;
1437+
int i, ret, num_sgs = 0, ifnum = -1;
14381438
int number_of_packets = 0;
14391439
unsigned int stream_id = 0;
14401440
void *buf;
1441+
bool is_in;
1442+
bool allow_short = false;
1443+
bool allow_zero = false;
14411444
unsigned long mask = USBDEVFS_URB_SHORT_NOT_OK |
14421445
USBDEVFS_URB_BULK_CONTINUATION |
14431446
USBDEVFS_URB_NO_FSBR |
@@ -1471,6 +1474,8 @@ static int proc_do_submiturb(struct usb_dev_state *ps, struct usbdevfs_urb *uurb
14711474
u = 0;
14721475
switch (uurb->type) {
14731476
case USBDEVFS_URB_TYPE_CONTROL:
1477+
if (is_in)
1478+
allow_short = true;
14741479
if (!usb_endpoint_xfer_control(&ep->desc))
14751480
return -EINVAL;
14761481
/* min 8 byte setup packet */
@@ -1511,6 +1516,10 @@ static int proc_do_submiturb(struct usb_dev_state *ps, struct usbdevfs_urb *uurb
15111516
break;
15121517

15131518
case USBDEVFS_URB_TYPE_BULK:
1519+
if (!is_in)
1520+
allow_zero = true;
1521+
else
1522+
allow_short = true;
15141523
switch (usb_endpoint_type(&ep->desc)) {
15151524
case USB_ENDPOINT_XFER_CONTROL:
15161525
case USB_ENDPOINT_XFER_ISOC:
@@ -1531,6 +1540,10 @@ static int proc_do_submiturb(struct usb_dev_state *ps, struct usbdevfs_urb *uurb
15311540
if (!usb_endpoint_xfer_int(&ep->desc))
15321541
return -EINVAL;
15331542
interrupt_urb:
1543+
if (!is_in)
1544+
allow_zero = true;
1545+
else
1546+
allow_short = true;
15341547
break;
15351548

15361549
case USBDEVFS_URB_TYPE_ISO:
@@ -1676,14 +1689,19 @@ static int proc_do_submiturb(struct usb_dev_state *ps, struct usbdevfs_urb *uurb
16761689
u = (is_in ? URB_DIR_IN : URB_DIR_OUT);
16771690
if (uurb->flags & USBDEVFS_URB_ISO_ASAP)
16781691
u |= URB_ISO_ASAP;
1679-
if (uurb->flags & USBDEVFS_URB_SHORT_NOT_OK && is_in)
1692+
if (allow_short && uurb->flags & USBDEVFS_URB_SHORT_NOT_OK)
16801693
u |= URB_SHORT_NOT_OK;
1681-
if (uurb->flags & USBDEVFS_URB_ZERO_PACKET)
1694+
if (allow_zero && uurb->flags & USBDEVFS_URB_ZERO_PACKET)
16821695
u |= URB_ZERO_PACKET;
16831696
if (uurb->flags & USBDEVFS_URB_NO_INTERRUPT)
16841697
u |= URB_NO_INTERRUPT;
16851698
as->urb->transfer_flags = u;
16861699

1700+
if (!allow_short && uurb->flags & USBDEVFS_URB_SHORT_NOT_OK)
1701+
dev_warn(&ps->dev->dev, "Requested nonsensical USBDEVFS_URB_SHORT_NOT_OK.\n");
1702+
if (!allow_zero && uurb->flags & USBDEVFS_URB_ZERO_PACKET)
1703+
dev_warn(&ps->dev->dev, "Requested nonsensical USBDEVFS_URB_ZERO_PACKET.\n");
1704+
16871705
as->urb->transfer_buffer_length = uurb->buffer_length;
16881706
as->urb->setup_packet = (unsigned char *)dr;
16891707
dr = NULL;

drivers/usb/core/driver.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,6 @@ int usb_driver_claim_interface(struct usb_driver *driver,
512512
struct device *dev;
513513
struct usb_device *udev;
514514
int retval = 0;
515-
int lpm_disable_error = -ENODEV;
516515

517516
if (!iface)
518517
return -ENODEV;
@@ -533,16 +532,6 @@ int usb_driver_claim_interface(struct usb_driver *driver,
533532

534533
iface->condition = USB_INTERFACE_BOUND;
535534

536-
/* See the comment about disabling LPM in usb_probe_interface(). */
537-
if (driver->disable_hub_initiated_lpm) {
538-
lpm_disable_error = usb_unlocked_disable_lpm(udev);
539-
if (lpm_disable_error) {
540-
dev_err(&iface->dev, "%s Failed to disable LPM for driver %s\n",
541-
__func__, driver->name);
542-
return -ENOMEM;
543-
}
544-
}
545-
546535
/* Claimed interfaces are initially inactive (suspended) and
547536
* runtime-PM-enabled, but only if the driver has autosuspend
548537
* support. Otherwise they are marked active, to prevent the
@@ -561,9 +550,20 @@ int usb_driver_claim_interface(struct usb_driver *driver,
561550
if (device_is_registered(dev))
562551
retval = device_bind_driver(dev);
563552

564-
/* Attempt to re-enable USB3 LPM, if the disable was successful. */
565-
if (!lpm_disable_error)
566-
usb_unlocked_enable_lpm(udev);
553+
if (retval) {
554+
dev->driver = NULL;
555+
usb_set_intfdata(iface, NULL);
556+
iface->needs_remote_wakeup = 0;
557+
iface->condition = USB_INTERFACE_UNBOUND;
558+
559+
/*
560+
* Unbound interfaces are always runtime-PM-disabled
561+
* and runtime-PM-suspended
562+
*/
563+
if (driver->supports_autosuspend)
564+
pm_runtime_disable(dev);
565+
pm_runtime_set_suspended(dev);
566+
}
567567

568568
return retval;
569569
}

drivers/usb/core/quirks.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ static int quirks_param_set(const char *val, const struct kernel_param *kp)
5858
quirk_list = kcalloc(quirk_count, sizeof(struct quirk_entry),
5959
GFP_KERNEL);
6060
if (!quirk_list) {
61+
quirk_count = 0;
6162
mutex_unlock(&quirk_mutex);
6263
return -ENOMEM;
6364
}
@@ -154,7 +155,7 @@ static struct kparam_string quirks_param_string = {
154155
.string = quirks_param,
155156
};
156157

157-
module_param_cb(quirks, &quirks_param_ops, &quirks_param_string, 0644);
158+
device_param_cb(quirks, &quirks_param_ops, &quirks_param_string, 0644);
158159
MODULE_PARM_DESC(quirks, "Add/modify USB quirks by specifying quirks=vendorID:productID:quirks");
159160

160161
/* Lists of quirky USB devices, split in device quirks and interface quirks.

drivers/usb/core/usb.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ struct usb_host_interface *usb_find_alt_setting(
228228
struct usb_interface_cache *intf_cache = NULL;
229229
int i;
230230

231+
if (!config)
232+
return NULL;
231233
for (i = 0; i < config->desc.bNumInterfaces; i++) {
232234
if (config->intf_cache[i]->altsetting[0].desc.bInterfaceNumber
233235
== iface_num) {

drivers/usb/musb/musb_dsps.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -658,16 +658,6 @@ dsps_dma_controller_create(struct musb *musb, void __iomem *base)
658658
return controller;
659659
}
660660

661-
static void dsps_dma_controller_destroy(struct dma_controller *c)
662-
{
663-
struct musb *musb = c->musb;
664-
struct dsps_glue *glue = dev_get_drvdata(musb->controller->parent);
665-
void __iomem *usbss_base = glue->usbss_base;
666-
667-
musb_writel(usbss_base, USBSS_IRQ_CLEARR, USBSS_IRQ_PD_COMP);
668-
cppi41_dma_controller_destroy(c);
669-
}
670-
671661
#ifdef CONFIG_PM_SLEEP
672662
static void dsps_dma_controller_suspend(struct dsps_glue *glue)
673663
{
@@ -697,7 +687,7 @@ static struct musb_platform_ops dsps_ops = {
697687

698688
#ifdef CONFIG_USB_TI_CPPI41_DMA
699689
.dma_init = dsps_dma_controller_create,
700-
.dma_exit = dsps_dma_controller_destroy,
690+
.dma_exit = cppi41_dma_controller_destroy,
701691
#endif
702692
.enable = dsps_musb_enable,
703693
.disable = dsps_musb_disable,

drivers/usb/typec/mux.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <linux/device.h>
1111
#include <linux/list.h>
12+
#include <linux/module.h>
1213
#include <linux/mutex.h>
1314
#include <linux/usb/typec_mux.h>
1415

@@ -49,8 +50,10 @@ struct typec_switch *typec_switch_get(struct device *dev)
4950
mutex_lock(&switch_lock);
5051
sw = device_connection_find_match(dev, "typec-switch", NULL,
5152
typec_switch_match);
52-
if (!IS_ERR_OR_NULL(sw))
53+
if (!IS_ERR_OR_NULL(sw)) {
54+
WARN_ON(!try_module_get(sw->dev->driver->owner));
5355
get_device(sw->dev);
56+
}
5457
mutex_unlock(&switch_lock);
5558

5659
return sw;
@@ -65,8 +68,10 @@ EXPORT_SYMBOL_GPL(typec_switch_get);
6568
*/
6669
void typec_switch_put(struct typec_switch *sw)
6770
{
68-
if (!IS_ERR_OR_NULL(sw))
71+
if (!IS_ERR_OR_NULL(sw)) {
72+
module_put(sw->dev->driver->owner);
6973
put_device(sw->dev);
74+
}
7075
}
7176
EXPORT_SYMBOL_GPL(typec_switch_put);
7277

@@ -136,8 +141,10 @@ struct typec_mux *typec_mux_get(struct device *dev, const char *name)
136141

137142
mutex_lock(&mux_lock);
138143
mux = device_connection_find_match(dev, name, NULL, typec_mux_match);
139-
if (!IS_ERR_OR_NULL(mux))
144+
if (!IS_ERR_OR_NULL(mux)) {
145+
WARN_ON(!try_module_get(mux->dev->driver->owner));
140146
get_device(mux->dev);
147+
}
141148
mutex_unlock(&mux_lock);
142149

143150
return mux;
@@ -152,8 +159,10 @@ EXPORT_SYMBOL_GPL(typec_mux_get);
152159
*/
153160
void typec_mux_put(struct typec_mux *mux)
154161
{
155-
if (!IS_ERR_OR_NULL(mux))
162+
if (!IS_ERR_OR_NULL(mux)) {
163+
module_put(mux->dev->driver->owner);
156164
put_device(mux->dev);
165+
}
157166
}
158167
EXPORT_SYMBOL_GPL(typec_mux_put);
159168

0 commit comments

Comments
 (0)