Skip to content

Commit 445e09e

Browse files
committed
Merge tag 'usb-5.12-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb
Pull USB/Thunderbolt fixes from Greg KH: "Here are a few small USB and Thunderbolt driver fixes for 5.12-rc7 for reported issues: - thunderbolt leaks and off-by-one fix - cdnsp deque fix - usbip fixes for syzbot-reported issues All have been in linux-next with no reported problems" * tag 'usb-5.12-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: usbip: synchronize event handler with sysfs code paths usbip: vudc synchronize sysfs code paths usbip: stub-dev synchronize sysfs code paths usbip: add sysfs_lock to synchronize sysfs code paths thunderbolt: Fix off by one in tb_port_find_retimer() thunderbolt: Fix a leak in tb_retimer_add() usb: cdnsp: Fixes issue with dequeuing requests after disabling endpoint
2 parents 12a0cf7 + bc2f3e4 commit 445e09e

File tree

9 files changed

+52
-9
lines changed

9 files changed

+52
-9
lines changed

drivers/thunderbolt/retimer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ static int tb_retimer_add(struct tb_port *port, u8 index, u32 auth_status)
347347
ret = tb_retimer_nvm_add(rt);
348348
if (ret) {
349349
dev_err(&rt->dev, "failed to add NVM devices: %d\n", ret);
350-
device_del(&rt->dev);
350+
device_unregister(&rt->dev);
351351
return ret;
352352
}
353353

@@ -406,7 +406,7 @@ static struct tb_retimer *tb_port_find_retimer(struct tb_port *port, u8 index)
406406
*/
407407
int tb_retimer_scan(struct tb_port *port)
408408
{
409-
u32 status[TB_MAX_RETIMER_INDEX] = {};
409+
u32 status[TB_MAX_RETIMER_INDEX + 1] = {};
410410
int ret, i, last_idx = 0;
411411

412412
if (!port->cap_usb4)

drivers/usb/cdns3/cdnsp-gadget.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,10 @@ static int cdnsp_gadget_ep_dequeue(struct usb_ep *ep,
11281128
return -ESHUTDOWN;
11291129
}
11301130

1131+
/* Requests has been dequeued during disabling endpoint. */
1132+
if (!(pep->ep_state & EP_ENABLED))
1133+
return 0;
1134+
11311135
spin_lock_irqsave(&pdev->lock, flags);
11321136
ret = cdnsp_ep_dequeue(pep, to_cdnsp_request(request));
11331137
spin_unlock_irqrestore(&pdev->lock, flags);

drivers/usb/usbip/stub_dev.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ static ssize_t usbip_sockfd_store(struct device *dev, struct device_attribute *a
6363

6464
dev_info(dev, "stub up\n");
6565

66+
mutex_lock(&sdev->ud.sysfs_lock);
6667
spin_lock_irq(&sdev->ud.lock);
6768

6869
if (sdev->ud.status != SDEV_ST_AVAILABLE) {
@@ -87,13 +88,13 @@ static ssize_t usbip_sockfd_store(struct device *dev, struct device_attribute *a
8788
tcp_rx = kthread_create(stub_rx_loop, &sdev->ud, "stub_rx");
8889
if (IS_ERR(tcp_rx)) {
8990
sockfd_put(socket);
90-
return -EINVAL;
91+
goto unlock_mutex;
9192
}
9293
tcp_tx = kthread_create(stub_tx_loop, &sdev->ud, "stub_tx");
9394
if (IS_ERR(tcp_tx)) {
9495
kthread_stop(tcp_rx);
9596
sockfd_put(socket);
96-
return -EINVAL;
97+
goto unlock_mutex;
9798
}
9899

99100
/* get task structs now */
@@ -112,6 +113,8 @@ static ssize_t usbip_sockfd_store(struct device *dev, struct device_attribute *a
112113
wake_up_process(sdev->ud.tcp_rx);
113114
wake_up_process(sdev->ud.tcp_tx);
114115

116+
mutex_unlock(&sdev->ud.sysfs_lock);
117+
115118
} else {
116119
dev_info(dev, "stub down\n");
117120

@@ -122,6 +125,7 @@ static ssize_t usbip_sockfd_store(struct device *dev, struct device_attribute *a
122125
spin_unlock_irq(&sdev->ud.lock);
123126

124127
usbip_event_add(&sdev->ud, SDEV_EVENT_DOWN);
128+
mutex_unlock(&sdev->ud.sysfs_lock);
125129
}
126130

127131
return count;
@@ -130,6 +134,8 @@ static ssize_t usbip_sockfd_store(struct device *dev, struct device_attribute *a
130134
sockfd_put(socket);
131135
err:
132136
spin_unlock_irq(&sdev->ud.lock);
137+
unlock_mutex:
138+
mutex_unlock(&sdev->ud.sysfs_lock);
133139
return -EINVAL;
134140
}
135141
static DEVICE_ATTR_WO(usbip_sockfd);
@@ -270,6 +276,7 @@ static struct stub_device *stub_device_alloc(struct usb_device *udev)
270276
sdev->ud.side = USBIP_STUB;
271277
sdev->ud.status = SDEV_ST_AVAILABLE;
272278
spin_lock_init(&sdev->ud.lock);
279+
mutex_init(&sdev->ud.sysfs_lock);
273280
sdev->ud.tcp_socket = NULL;
274281
sdev->ud.sockfd = -1;
275282

drivers/usb/usbip/usbip_common.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,9 @@ struct usbip_device {
263263
/* lock for status */
264264
spinlock_t lock;
265265

266+
/* mutex for synchronizing sysfs store paths */
267+
struct mutex sysfs_lock;
268+
266269
int sockfd;
267270
struct socket *tcp_socket;
268271

drivers/usb/usbip/usbip_event.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ static void event_handler(struct work_struct *work)
7070
while ((ud = get_event()) != NULL) {
7171
usbip_dbg_eh("pending event %lx\n", ud->event);
7272

73+
mutex_lock(&ud->sysfs_lock);
7374
/*
7475
* NOTE: shutdown must come first.
7576
* Shutdown the device.
@@ -90,6 +91,7 @@ static void event_handler(struct work_struct *work)
9091
ud->eh_ops.unusable(ud);
9192
unset_event(ud, USBIP_EH_UNUSABLE);
9293
}
94+
mutex_unlock(&ud->sysfs_lock);
9395

9496
wake_up(&ud->eh_waitq);
9597
}

drivers/usb/usbip/vhci_hcd.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,7 @@ static void vhci_device_init(struct vhci_device *vdev)
11011101
vdev->ud.side = USBIP_VHCI;
11021102
vdev->ud.status = VDEV_ST_NULL;
11031103
spin_lock_init(&vdev->ud.lock);
1104+
mutex_init(&vdev->ud.sysfs_lock);
11041105

11051106
INIT_LIST_HEAD(&vdev->priv_rx);
11061107
INIT_LIST_HEAD(&vdev->priv_tx);

drivers/usb/usbip/vhci_sysfs.c

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ static int vhci_port_disconnect(struct vhci_hcd *vhci_hcd, __u32 rhport)
185185

186186
usbip_dbg_vhci_sysfs("enter\n");
187187

188+
mutex_lock(&vdev->ud.sysfs_lock);
189+
188190
/* lock */
189191
spin_lock_irqsave(&vhci->lock, flags);
190192
spin_lock(&vdev->ud.lock);
@@ -195,6 +197,7 @@ static int vhci_port_disconnect(struct vhci_hcd *vhci_hcd, __u32 rhport)
195197
/* unlock */
196198
spin_unlock(&vdev->ud.lock);
197199
spin_unlock_irqrestore(&vhci->lock, flags);
200+
mutex_unlock(&vdev->ud.sysfs_lock);
198201

199202
return -EINVAL;
200203
}
@@ -205,6 +208,8 @@ static int vhci_port_disconnect(struct vhci_hcd *vhci_hcd, __u32 rhport)
205208

206209
usbip_event_add(&vdev->ud, VDEV_EVENT_DOWN);
207210

211+
mutex_unlock(&vdev->ud.sysfs_lock);
212+
208213
return 0;
209214
}
210215

@@ -349,30 +354,36 @@ static ssize_t attach_store(struct device *dev, struct device_attribute *attr,
349354
else
350355
vdev = &vhci->vhci_hcd_hs->vdev[rhport];
351356

357+
mutex_lock(&vdev->ud.sysfs_lock);
358+
352359
/* Extract socket from fd. */
353360
socket = sockfd_lookup(sockfd, &err);
354361
if (!socket) {
355362
dev_err(dev, "failed to lookup sock");
356-
return -EINVAL;
363+
err = -EINVAL;
364+
goto unlock_mutex;
357365
}
358366
if (socket->type != SOCK_STREAM) {
359367
dev_err(dev, "Expecting SOCK_STREAM - found %d",
360368
socket->type);
361369
sockfd_put(socket);
362-
return -EINVAL;
370+
err = -EINVAL;
371+
goto unlock_mutex;
363372
}
364373

365374
/* create threads before locking */
366375
tcp_rx = kthread_create(vhci_rx_loop, &vdev->ud, "vhci_rx");
367376
if (IS_ERR(tcp_rx)) {
368377
sockfd_put(socket);
369-
return -EINVAL;
378+
err = -EINVAL;
379+
goto unlock_mutex;
370380
}
371381
tcp_tx = kthread_create(vhci_tx_loop, &vdev->ud, "vhci_tx");
372382
if (IS_ERR(tcp_tx)) {
373383
kthread_stop(tcp_rx);
374384
sockfd_put(socket);
375-
return -EINVAL;
385+
err = -EINVAL;
386+
goto unlock_mutex;
376387
}
377388

378389
/* get task structs now */
@@ -397,7 +408,8 @@ static ssize_t attach_store(struct device *dev, struct device_attribute *attr,
397408
* Will be retried from userspace
398409
* if there's another free port.
399410
*/
400-
return -EBUSY;
411+
err = -EBUSY;
412+
goto unlock_mutex;
401413
}
402414

403415
dev_info(dev, "pdev(%u) rhport(%u) sockfd(%d)\n",
@@ -423,7 +435,15 @@ static ssize_t attach_store(struct device *dev, struct device_attribute *attr,
423435

424436
rh_port_connect(vdev, speed);
425437

438+
dev_info(dev, "Device attached\n");
439+
440+
mutex_unlock(&vdev->ud.sysfs_lock);
441+
426442
return count;
443+
444+
unlock_mutex:
445+
mutex_unlock(&vdev->ud.sysfs_lock);
446+
return err;
427447
}
428448
static DEVICE_ATTR_WO(attach);
429449

drivers/usb/usbip/vudc_dev.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,7 @@ static int init_vudc_hw(struct vudc *udc)
572572
init_waitqueue_head(&udc->tx_waitq);
573573

574574
spin_lock_init(&ud->lock);
575+
mutex_init(&ud->sysfs_lock);
575576
ud->status = SDEV_ST_AVAILABLE;
576577
ud->side = USBIP_VUDC;
577578

drivers/usb/usbip/vudc_sysfs.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ static ssize_t usbip_sockfd_store(struct device *dev,
112112
dev_err(dev, "no device");
113113
return -ENODEV;
114114
}
115+
mutex_lock(&udc->ud.sysfs_lock);
115116
spin_lock_irqsave(&udc->lock, flags);
116117
/* Don't export what we don't have */
117118
if (!udc->driver || !udc->pullup) {
@@ -187,6 +188,8 @@ static ssize_t usbip_sockfd_store(struct device *dev,
187188

188189
wake_up_process(udc->ud.tcp_rx);
189190
wake_up_process(udc->ud.tcp_tx);
191+
192+
mutex_unlock(&udc->ud.sysfs_lock);
190193
return count;
191194

192195
} else {
@@ -207,6 +210,7 @@ static ssize_t usbip_sockfd_store(struct device *dev,
207210
}
208211

209212
spin_unlock_irqrestore(&udc->lock, flags);
213+
mutex_unlock(&udc->ud.sysfs_lock);
210214

211215
return count;
212216

@@ -216,6 +220,7 @@ static ssize_t usbip_sockfd_store(struct device *dev,
216220
spin_unlock_irq(&udc->ud.lock);
217221
unlock:
218222
spin_unlock_irqrestore(&udc->lock, flags);
223+
mutex_unlock(&udc->ud.sysfs_lock);
219224

220225
return ret;
221226
}

0 commit comments

Comments
 (0)