Re: [PATCH 3/3] usb: dwc3: gadget: Simplify logic in dwc3_needs_extra_trb()

From: Thinh Nguyen
Date: Mon Jun 23 2025 - 18:32:29 EST


On Sat, Jun 21, 2025, Johannes Schneider wrote:
> The existing logic in dwc3_needs_extra_trb() checks multiple conditions
> in a compound expression to determine whether an extra TRB is needed,
> either for a ZLP or to handle short OUT transfers.
>
> This commit simplifies the logic without changing behavior:
> - Returns false early for isochronous endpoints
> - Separates the conditions for IN vs OUT transfers
> - Makes intent and flow easier to read and reason about
>
> No functional changes intended.
>
> Signed-off-by: Johannes Schneider <johannes.schneider@xxxxxxxxxxxxxxxxxxxx>
> ---
> drivers/usb/dwc3/gadget.c | 11 ++++++-----
> 1 file changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
> index a4a2bf273f943fa112f49979297023a732e0af2e..32d0fb090f4c2ffab61ae6eee29a02efd32ed032 100644
> --- a/drivers/usb/dwc3/gadget.c
> +++ b/drivers/usb/dwc3/gadget.c
> @@ -1420,12 +1420,13 @@ static bool dwc3_needs_extra_trb(struct dwc3_ep *dep, struct dwc3_request *req)
> unsigned int maxp = usb_endpoint_maxp(dep->endpoint.desc);
> unsigned int rem = req->request.length % maxp;
>
> - if ((req->request.length && req->request.zero && !rem &&
> - !usb_endpoint_xfer_isoc(dep->endpoint.desc)) ||
> - (!req->direction && rem))
> - return true;
> + if (usb_endpoint_xfer_isoc(dep->endpoint.desc))
> + return false;

I know the current flow is unsightly, but this is not the same logic.
Please help fix it.

Thanks,
Thinh

> +
> + if (!req->direction) /* OUT transfers */
> + return rem != 0;
>
> - return false;
> + return rem == 0;
> }
>
> /**
>
> --
> 2.34.1
>