Module Name: src
Committed By: manu
Date: Fri Oct 10 12:08:54 UTC 2025
Modified Files:
src/sys/dev/usb: ucom.c
Log Message:
Fix ucom input queue corruption on open-after-close
When closing ucom(4) while a transfer was in progress, ucomreadcb()
is called with USBD_CANCELLED. Previously, the ucom_buffer was not
removed from sc->sc_ibuff_empty, leading to queue corruption when
reopening the device: ucomopen() calls ucomsubmitread(), which
queues the ucom_buffer again.
We fix this by making sure the ucom_buffer is removed from queue
on USBD_CANCELLED or USBD_IOERROR.
Approved by Nick Hudson, who rewrote the comment.
Thanks, this looks good!
I think it would also benefit from an assertion, just in case we ever
expand UCOM_IN_BUFFS beyond 1:
ub = SIMPLEQ_FIRST(&sc->sc_ibuff_empty);
SIMPLEQ_REMOVE_HEAD(&sc->sc_ibuff_empty, ub_link);
+ KASSERT(xfer == ub->ub_xfer);