drivers: udc_dwc2: Do not enable inactive endpoint

Fail TxFIFO write if the endpoint is not activated, because there is
essentially no fifo assigned. Writing to not activated endpoint is
possible, but it does tend to corrupt fifo number 0 which is used for
control transfers. USB stack should not really be attempting to write to
endpoints that have not been activated (ep_enable called).

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
This commit is contained in:
Tomasz Moń 2024-08-19 10:34:04 +02:00 committed by Carles Cufí
commit 0b242dea42

View file

@ -409,6 +409,15 @@ static int dwc2_tx_fifo_write(const struct device *dev,
}
diepctl = sys_read32(diepctl_reg);
if (!(diepctl & USB_DWC2_DEPCTL_USBACTEP)) {
/* Do not attempt to write data on inactive endpoint, because
* no fifo is assigned to inactive endpoint and therefore it is
* possible that the write will corrupt other endpoint fifo.
*/
irq_unlock(key);
return -ENOENT;
}
if (is_iso) {
if (priv->sof_num & 1) {
diepctl |= USB_DWC2_DEPCTL_SETODDFR;