usb: dwc3: gadget: Refactor loop to avoid NULL endpoints

[ Upstream commit eafba0205426091354f050381c32ad1567c35844 ]

Prepare the gadget driver to handle the reserved endpoints that will be
not allocated at the initialisation time.

While at it, add a warning where the NULL endpoint should never happen.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Tested-by: Ferry Toth <fntoth@gmail.com>
Acked-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Link: https://lore.kernel.org/r/20250212193116.2487289-3-andriy.shevchenko@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
Andy Shevchenko
2025-02-12 21:28:02 +02:00
committed by Greg Kroah-Hartman
parent db56636beb
commit e5aabc76d1

View File

@@ -548,6 +548,7 @@ static int dwc3_gadget_set_xfer_resource(struct dwc3_ep *dep)
int dwc3_gadget_start_config(struct dwc3 *dwc, unsigned int resource_index) int dwc3_gadget_start_config(struct dwc3 *dwc, unsigned int resource_index)
{ {
struct dwc3_gadget_ep_cmd_params params; struct dwc3_gadget_ep_cmd_params params;
struct dwc3_ep *dep;
u32 cmd; u32 cmd;
int i; int i;
int ret; int ret;
@@ -564,8 +565,13 @@ int dwc3_gadget_start_config(struct dwc3 *dwc, unsigned int resource_index)
return ret; return ret;
/* Reset resource allocation flags */ /* Reset resource allocation flags */
for (i = resource_index; i < dwc->num_eps && dwc->eps[i]; i++) for (i = resource_index; i < dwc->num_eps; i++) {
dwc->eps[i]->flags &= ~DWC3_EP_RESOURCE_ALLOCATED; dep = dwc->eps[i];
if (!dep)
continue;
dep->flags &= ~DWC3_EP_RESOURCE_ALLOCATED;
}
return 0; return 0;
} }
@@ -752,9 +758,11 @@ void dwc3_gadget_clear_tx_fifos(struct dwc3 *dwc)
dwc->last_fifo_depth = fifo_depth; dwc->last_fifo_depth = fifo_depth;
/* Clear existing TXFIFO for all IN eps except ep0 */ /* Clear existing TXFIFO for all IN eps except ep0 */
for (num = 3; num < min_t(int, dwc->num_eps, DWC3_ENDPOINTS_NUM); for (num = 3; num < min_t(int, dwc->num_eps, DWC3_ENDPOINTS_NUM); num += 2) {
num += 2) {
dep = dwc->eps[num]; dep = dwc->eps[num];
if (!dep)
continue;
/* Don't change TXFRAMNUM on usb31 version */ /* Don't change TXFRAMNUM on usb31 version */
size = DWC3_IP_IS(DWC3) ? 0 : size = DWC3_IP_IS(DWC3) ? 0 :
dwc3_readl(dwc->regs, DWC3_GTXFIFOSIZ(num >> 1)) & dwc3_readl(dwc->regs, DWC3_GTXFIFOSIZ(num >> 1)) &
@@ -3670,6 +3678,8 @@ out:
for (i = 0; i < DWC3_ENDPOINTS_NUM; i++) { for (i = 0; i < DWC3_ENDPOINTS_NUM; i++) {
dep = dwc->eps[i]; dep = dwc->eps[i];
if (!dep)
continue;
if (!(dep->flags & DWC3_EP_ENABLED)) if (!(dep->flags & DWC3_EP_ENABLED))
continue; continue;
@@ -3858,6 +3868,10 @@ static void dwc3_endpoint_interrupt(struct dwc3 *dwc,
u8 epnum = event->endpoint_number; u8 epnum = event->endpoint_number;
dep = dwc->eps[epnum]; dep = dwc->eps[epnum];
if (!dep) {
dev_warn(dwc->dev, "spurious event, endpoint %u is not allocated\n", epnum);
return;
}
if (!(dep->flags & DWC3_EP_ENABLED)) { if (!(dep->flags & DWC3_EP_ENABLED)) {
if ((epnum > 1) && !(dep->flags & DWC3_EP_TRANSFER_STARTED)) if ((epnum > 1) && !(dep->flags & DWC3_EP_TRANSFER_STARTED))