usb: device_next: Do not leak memory on set address

USB stack did leak memory on every SET ADDRESS request. UDC control
allocator could cope with up to 13 leaked allocations. Therefore,
issuing bus reset 13 times in a row (in addition to automatic reset
after connecting the USB cable) was enough to exhaust memory and
thus drive USB stack inoperable.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
This commit is contained in:
Tomasz Moń 2023-01-23 10:49:30 +01:00 committed by Carles Cufí
commit 7608f54433

View file

@ -811,6 +811,8 @@ int usbd_handle_ctrl_xfer(struct usbd_contex *const uds_ctx,
}
if (bi->status && bi->ep == USB_CONTROL_EP_IN) {
net_buf_unref(buf);
if (ch9_get_ctrl_type(uds_ctx) == CTRL_AWAIT_STATUS_STAGE) {
LOG_INF("s-(out)-status finished");
if (unlikely(uds_ctx->ch9_data.new_address)) {
@ -820,8 +822,6 @@ int usbd_handle_ctrl_xfer(struct usbd_contex *const uds_ctx,
LOG_WRN("Awaited s-(out)-status not finished");
}
net_buf_unref(buf);
return ret;
}