Skip to content

Commit 359334c

Browse files
committed
Merge tag 'usb-5.3-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb
Pull USB fixes from Greg KH: "Here are number of small USB fixes for 5.3-rc5. Syzbot has been on a tear recently now that it has some good USB debugging hooks integrated, so there's a number of fixes in here found by those tools for some _very_ old bugs. Also a handful of gadget driver fixes for reported issues, some hopefully-final dma fixes for host controller drivers, and some new USB serial gadget driver ids. All of these have been in linux-next this week with no reported issues (the usb-serial ones were in linux-next in its own branch, but merged into mine on Friday)" * tag 'usb-5.3-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: usb: add a hcd_uses_dma helper usb: don't create dma pools for HCDs with a localmem_pool usb: chipidea: imx: fix EPROBE_DEFER support during driver probe usb: host: fotg2: restart hcd after port reset USB: CDC: fix sanity checks in CDC union parser usb: cdc-acm: make sure a refcount is taken early enough USB: serial: option: add the BroadMobi BM818 card USB: serial: option: Add Motorola modem UARTs USB: core: Fix races in character device registration and deregistraion usb: gadget: mass_storage: Fix races between fsg_disable and fsg_set_alt usb: gadget: composite: Clear "suspended" on reset/disconnect usb: gadget: udc: renesas_usb3: Fix sysfs interface of "role" USB: serial: option: add D-Link DWM-222 device ID USB: serial: option: Add support for ZTE MF871A
2 parents 8fde283 + 6a5f43d commit 359334c

File tree

14 files changed

+72
-42
lines changed

14 files changed

+72
-42
lines changed

drivers/usb/chipidea/ci_hdrc_imx.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -454,9 +454,11 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
454454
imx_disable_unprepare_clks(dev);
455455
disable_hsic_regulator:
456456
if (data->hsic_pad_regulator)
457-
ret = regulator_disable(data->hsic_pad_regulator);
457+
/* don't overwrite original ret (cf. EPROBE_DEFER) */
458+
regulator_disable(data->hsic_pad_regulator);
458459
if (pdata.flags & CI_HDRC_PMQOS)
459460
pm_qos_remove_request(&data->pm_qos_req);
461+
data->ci_pdev = NULL;
460462
return ret;
461463
}
462464

@@ -469,14 +471,17 @@ static int ci_hdrc_imx_remove(struct platform_device *pdev)
469471
pm_runtime_disable(&pdev->dev);
470472
pm_runtime_put_noidle(&pdev->dev);
471473
}
472-
ci_hdrc_remove_device(data->ci_pdev);
474+
if (data->ci_pdev)
475+
ci_hdrc_remove_device(data->ci_pdev);
473476
if (data->override_phy_control)
474477
usb_phy_shutdown(data->phy);
475-
imx_disable_unprepare_clks(&pdev->dev);
476-
if (data->plat_data->flags & CI_HDRC_PMQOS)
477-
pm_qos_remove_request(&data->pm_qos_req);
478-
if (data->hsic_pad_regulator)
479-
regulator_disable(data->hsic_pad_regulator);
478+
if (data->ci_pdev) {
479+
imx_disable_unprepare_clks(&pdev->dev);
480+
if (data->plat_data->flags & CI_HDRC_PMQOS)
481+
pm_qos_remove_request(&data->pm_qos_req);
482+
if (data->hsic_pad_regulator)
483+
regulator_disable(data->hsic_pad_regulator);
484+
}
480485

481486
return 0;
482487
}

drivers/usb/class/cdc-acm.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,17 +1301,20 @@ static int acm_probe(struct usb_interface *intf,
13011301
tty_port_init(&acm->port);
13021302
acm->port.ops = &acm_port_ops;
13031303

1304-
minor = acm_alloc_minor(acm);
1305-
if (minor < 0)
1306-
goto alloc_fail1;
1307-
13081304
ctrlsize = usb_endpoint_maxp(epctrl);
13091305
readsize = usb_endpoint_maxp(epread) *
13101306
(quirks == SINGLE_RX_URB ? 1 : 2);
13111307
acm->combined_interfaces = combined_interfaces;
13121308
acm->writesize = usb_endpoint_maxp(epwrite) * 20;
13131309
acm->control = control_interface;
13141310
acm->data = data_interface;
1311+
1312+
usb_get_intf(acm->control); /* undone in destruct() */
1313+
1314+
minor = acm_alloc_minor(acm);
1315+
if (minor < 0)
1316+
goto alloc_fail1;
1317+
13151318
acm->minor = minor;
13161319
acm->dev = usb_dev;
13171320
if (h.usb_cdc_acm_descriptor)
@@ -1458,7 +1461,6 @@ static int acm_probe(struct usb_interface *intf,
14581461
usb_driver_claim_interface(&acm_driver, data_interface, acm);
14591462
usb_set_intfdata(data_interface, acm);
14601463

1461-
usb_get_intf(control_interface);
14621464
tty_dev = tty_port_register_device(&acm->port, acm_tty_driver, minor,
14631465
&control_interface->dev);
14641466
if (IS_ERR(tty_dev)) {

drivers/usb/core/buffer.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ int hcd_buffer_create(struct usb_hcd *hcd)
6666
char name[16];
6767
int i, size;
6868

69-
if (!IS_ENABLED(CONFIG_HAS_DMA) ||
70-
(!is_device_dma_capable(hcd->self.sysdev) &&
71-
!hcd->localmem_pool))
69+
if (hcd->localmem_pool || !hcd_uses_dma(hcd))
7270
return 0;
7371

7472
for (i = 0; i < HCD_BUFFER_POOLS; i++) {
@@ -129,8 +127,7 @@ void *hcd_buffer_alloc(
129127
return gen_pool_dma_alloc(hcd->localmem_pool, size, dma);
130128

131129
/* some USB hosts just use PIO */
132-
if (!IS_ENABLED(CONFIG_HAS_DMA) ||
133-
!is_device_dma_capable(bus->sysdev)) {
130+
if (!hcd_uses_dma(hcd)) {
134131
*dma = ~(dma_addr_t) 0;
135132
return kmalloc(size, mem_flags);
136133
}
@@ -160,8 +157,7 @@ void hcd_buffer_free(
160157
return;
161158
}
162159

163-
if (!IS_ENABLED(CONFIG_HAS_DMA) ||
164-
!is_device_dma_capable(bus->sysdev)) {
160+
if (!hcd_uses_dma(hcd)) {
165161
kfree(addr);
166162
return;
167163
}

drivers/usb/core/file.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,22 +193,22 @@ int usb_register_dev(struct usb_interface *intf,
193193
intf->minor = minor;
194194
break;
195195
}
196-
up_write(&minor_rwsem);
197-
if (intf->minor < 0)
196+
if (intf->minor < 0) {
197+
up_write(&minor_rwsem);
198198
return -EXFULL;
199+
}
199200

200201
/* create a usb class device for this usb interface */
201202
snprintf(name, sizeof(name), class_driver->name, minor - minor_base);
202203
intf->usb_dev = device_create(usb_class->class, &intf->dev,
203204
MKDEV(USB_MAJOR, minor), class_driver,
204205
"%s", kbasename(name));
205206
if (IS_ERR(intf->usb_dev)) {
206-
down_write(&minor_rwsem);
207207
usb_minors[minor] = NULL;
208208
intf->minor = -1;
209-
up_write(&minor_rwsem);
210209
retval = PTR_ERR(intf->usb_dev);
211210
}
211+
up_write(&minor_rwsem);
212212
return retval;
213213
}
214214
EXPORT_SYMBOL_GPL(usb_register_dev);
@@ -234,12 +234,12 @@ void usb_deregister_dev(struct usb_interface *intf,
234234
return;
235235

236236
dev_dbg(&intf->dev, "removing %d minor\n", intf->minor);
237+
device_destroy(usb_class->class, MKDEV(USB_MAJOR, intf->minor));
237238

238239
down_write(&minor_rwsem);
239240
usb_minors[intf->minor] = NULL;
240241
up_write(&minor_rwsem);
241242

242-
device_destroy(usb_class->class, MKDEV(USB_MAJOR, intf->minor));
243243
intf->usb_dev = NULL;
244244
intf->minor = -1;
245245
destroy_usb_class();

drivers/usb/core/hcd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,7 +1412,7 @@ int usb_hcd_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
14121412
if (usb_endpoint_xfer_control(&urb->ep->desc)) {
14131413
if (hcd->self.uses_pio_for_control)
14141414
return ret;
1415-
if (IS_ENABLED(CONFIG_HAS_DMA) && hcd->self.uses_dma) {
1415+
if (hcd_uses_dma(hcd)) {
14161416
if (is_vmalloc_addr(urb->setup_packet)) {
14171417
WARN_ONCE(1, "setup packet is not dma capable\n");
14181418
return -EAGAIN;
@@ -1446,7 +1446,7 @@ int usb_hcd_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
14461446
dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
14471447
if (urb->transfer_buffer_length != 0
14481448
&& !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)) {
1449-
if (IS_ENABLED(CONFIG_HAS_DMA) && hcd->self.uses_dma) {
1449+
if (hcd_uses_dma(hcd)) {
14501450
if (urb->num_sgs) {
14511451
int n;
14521452

drivers/usb/core/message.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2218,14 +2218,14 @@ int cdc_parse_cdc_header(struct usb_cdc_parsed_header *hdr,
22182218
(struct usb_cdc_dmm_desc *)buffer;
22192219
break;
22202220
case USB_CDC_MDLM_TYPE:
2221-
if (elength < sizeof(struct usb_cdc_mdlm_desc *))
2221+
if (elength < sizeof(struct usb_cdc_mdlm_desc))
22222222
goto next_desc;
22232223
if (desc)
22242224
return -EINVAL;
22252225
desc = (struct usb_cdc_mdlm_desc *)buffer;
22262226
break;
22272227
case USB_CDC_MDLM_DETAIL_TYPE:
2228-
if (elength < sizeof(struct usb_cdc_mdlm_detail_desc *))
2228+
if (elength < sizeof(struct usb_cdc_mdlm_detail_desc))
22292229
goto next_desc;
22302230
if (detail)
22312231
return -EINVAL;

drivers/usb/dwc2/hcd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4608,7 +4608,7 @@ static int _dwc2_hcd_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
46084608

46094609
buf = urb->transfer_buffer;
46104610

4611-
if (hcd->self.uses_dma) {
4611+
if (hcd_uses_dma(hcd)) {
46124612
if (!buf && (urb->transfer_dma & 3)) {
46134613
dev_err(hsotg->dev,
46144614
"%s: unaligned transfer with no transfer_buffer",

drivers/usb/gadget/composite.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1976,6 +1976,7 @@ void composite_disconnect(struct usb_gadget *gadget)
19761976
* disconnect callbacks?
19771977
*/
19781978
spin_lock_irqsave(&cdev->lock, flags);
1979+
cdev->suspended = 0;
19791980
if (cdev->config)
19801981
reset_config(cdev);
19811982
if (cdev->driver->disconnect)

drivers/usb/gadget/function/f_mass_storage.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ struct fsg_common;
261261
struct fsg_common {
262262
struct usb_gadget *gadget;
263263
struct usb_composite_dev *cdev;
264-
struct fsg_dev *fsg, *new_fsg;
264+
struct fsg_dev *fsg;
265265
wait_queue_head_t io_wait;
266266
wait_queue_head_t fsg_wait;
267267

@@ -290,6 +290,7 @@ struct fsg_common {
290290
unsigned int bulk_out_maxpacket;
291291
enum fsg_state state; /* For exception handling */
292292
unsigned int exception_req_tag;
293+
void *exception_arg;
293294

294295
enum data_direction data_dir;
295296
u32 data_size;
@@ -391,7 +392,8 @@ static int fsg_set_halt(struct fsg_dev *fsg, struct usb_ep *ep)
391392

392393
/* These routines may be called in process context or in_irq */
393394

394-
static void raise_exception(struct fsg_common *common, enum fsg_state new_state)
395+
static void __raise_exception(struct fsg_common *common, enum fsg_state new_state,
396+
void *arg)
395397
{
396398
unsigned long flags;
397399

@@ -404,13 +406,18 @@ static void raise_exception(struct fsg_common *common, enum fsg_state new_state)
404406
if (common->state <= new_state) {
405407
common->exception_req_tag = common->ep0_req_tag;
406408
common->state = new_state;
409+
common->exception_arg = arg;
407410
if (common->thread_task)
408411
send_sig_info(SIGUSR1, SEND_SIG_PRIV,
409412
common->thread_task);
410413
}
411414
spin_unlock_irqrestore(&common->lock, flags);
412415
}
413416

417+
static void raise_exception(struct fsg_common *common, enum fsg_state new_state)
418+
{
419+
__raise_exception(common, new_state, NULL);
420+
}
414421

415422
/*-------------------------------------------------------------------------*/
416423

@@ -2285,16 +2292,16 @@ static int do_set_interface(struct fsg_common *common, struct fsg_dev *new_fsg)
22852292
static int fsg_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
22862293
{
22872294
struct fsg_dev *fsg = fsg_from_func(f);
2288-
fsg->common->new_fsg = fsg;
2289-
raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE);
2295+
2296+
__raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE, fsg);
22902297
return USB_GADGET_DELAYED_STATUS;
22912298
}
22922299

22932300
static void fsg_disable(struct usb_function *f)
22942301
{
22952302
struct fsg_dev *fsg = fsg_from_func(f);
2296-
fsg->common->new_fsg = NULL;
2297-
raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE);
2303+
2304+
__raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE, NULL);
22982305
}
22992306

23002307

@@ -2307,6 +2314,7 @@ static void handle_exception(struct fsg_common *common)
23072314
enum fsg_state old_state;
23082315
struct fsg_lun *curlun;
23092316
unsigned int exception_req_tag;
2317+
struct fsg_dev *new_fsg;
23102318

23112319
/*
23122320
* Clear the existing signals. Anything but SIGUSR1 is converted
@@ -2360,6 +2368,7 @@ static void handle_exception(struct fsg_common *common)
23602368
common->next_buffhd_to_fill = &common->buffhds[0];
23612369
common->next_buffhd_to_drain = &common->buffhds[0];
23622370
exception_req_tag = common->exception_req_tag;
2371+
new_fsg = common->exception_arg;
23632372
old_state = common->state;
23642373
common->state = FSG_STATE_NORMAL;
23652374

@@ -2413,8 +2422,8 @@ static void handle_exception(struct fsg_common *common)
24132422
break;
24142423

24152424
case FSG_STATE_CONFIG_CHANGE:
2416-
do_set_interface(common, common->new_fsg);
2417-
if (common->new_fsg)
2425+
do_set_interface(common, new_fsg);
2426+
if (new_fsg)
24182427
usb_composite_setup_continue(common->cdev);
24192428
break;
24202429

@@ -2989,8 +2998,7 @@ static void fsg_unbind(struct usb_configuration *c, struct usb_function *f)
29892998

29902999
DBG(fsg, "unbind\n");
29913000
if (fsg->common->fsg == fsg) {
2992-
fsg->common->new_fsg = NULL;
2993-
raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE);
3001+
__raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE, NULL);
29943002
/* FIXME: make interruptible or killable somehow? */
29953003
wait_event(common->fsg_wait, common->fsg != fsg);
29963004
}

drivers/usb/gadget/udc/renesas_usb3.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/pm_runtime.h>
2020
#include <linux/sizes.h>
2121
#include <linux/slab.h>
22+
#include <linux/string.h>
2223
#include <linux/sys_soc.h>
2324
#include <linux/uaccess.h>
2425
#include <linux/usb/ch9.h>
@@ -2450,9 +2451,9 @@ static ssize_t role_store(struct device *dev, struct device_attribute *attr,
24502451
if (usb3->forced_b_device)
24512452
return -EBUSY;
24522453

2453-
if (!strncmp(buf, "host", strlen("host")))
2454+
if (sysfs_streq(buf, "host"))
24542455
new_mode_is_host = true;
2455-
else if (!strncmp(buf, "peripheral", strlen("peripheral")))
2456+
else if (sysfs_streq(buf, "peripheral"))
24562457
new_mode_is_host = false;
24572458
else
24582459
return -EINVAL;

0 commit comments

Comments
 (0)