Skip to content

Commit 22c0d01

Browse files
Kari Hulkkonashif
authored andcommitted
usb: fix for parallel transfer deadlock with usb_transfer_sync()
Parallel transfer to same endpoint is not supported and may cause a deadlock. Adding a check to prevent starting the transfer if tranfer is already ongoing on same endpoint. Transfer status was not checked when accessing to transfer from endpoint callback. Adding status check, to prevent a double completion. Fixes #30736 Signed-off-by: Kari Hulkko <[email protected]>
1 parent 7786103 commit 22c0d01

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

subsys/usb/usb_transfer.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static struct usb_transfer_data ut_data[CONFIG_USB_MAX_NUM_TRANSFERS];
4949
static struct usb_transfer_data *usb_ep_get_transfer(uint8_t ep)
5050
{
5151
for (int i = 0; i < ARRAY_SIZE(ut_data); i++) {
52-
if (ut_data[i].ep == ep) {
52+
if (ut_data[i].ep == ep && ut_data[i].status != 0) {
5353
return &ut_data[i];
5454
}
5555
}
@@ -198,6 +198,11 @@ int usb_transfer(uint8_t ep, uint8_t *data, size_t dlen, unsigned int flags,
198198
struct usb_transfer_data *trans = NULL;
199199
int i, key, ret = 0;
200200

201+
/* Parallel transfer to same endpoint is not supported. */
202+
if (usb_transfer_is_busy(ep)) {
203+
return -EBUSY;
204+
}
205+
201206
LOG_DBG("Transfer start, ep 0x%02x, data %p, dlen %zd",
202207
ep, data, dlen);
203208

0 commit comments

Comments
 (0)