Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Petar Stepanovic" <pstepanovic@axiado.com>
Cc: linux-usb@vger.kernel.org, devicetree@vger.kernel.org,
	robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v6 5/6] usb: gadget: udc: crg: Add gadget and endpoint operations
Date: Tue, 24 Nov 2026 13:47:31 +0000	[thread overview]
Message-ID: <sashiko-outbox-231251@kernel.org> (raw)
In-Reply-To: <20261124-axiado-ax3000-usb-device-controller-v6-5-b991f9b27111@axiado.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] usb: gadget: crg: crg_udc_ep_dequeue() returns -ESHUTDOWN for
  queued requests
- [Medium] usb: gadget: crg: stale tran_ring_full after dequeue in
  crg_udc_skip_td()
- [Medium] usb: gadget: crg: useless chained IOC events in
  crg_udc_queue_trbs()
--

commit 940c56f180e03034ba3d28364b31f4362309e9df
Author: Petar Stepanovic <pstepanovic@axiado.com>

usb: gadget: udc: crg: Add gadget and endpoint operations

This commit implements the USB gadget and endpoint operations for the
Axiado AX3000/AX3005 UDC driver.

> diff --git a/drivers/usb/gadget/udc/crg/crg-udc-gadget.c b/drivers/usb/gadget/udc/crg/crg-udc-gadget.c
> new file mode 100644
> index 0000000000000..8a730b5167d9b
> --- /dev/null
> +++ b/drivers/usb/gadget/udc/crg/crg-udc-gadget.c

[ ... ]

> +static int crg_udc_skip_td(struct crg_udc_ep *ep, struct crg_udc_request *req)
> +{
> +	struct crg_transfer_trb *next = req->last_trb + 1;
> +	u8 cycle;
> +	int ret;
> +
> +	if (next == ep->last_trb)
> +		next = ep->first_trb;
> +	cycle = next > ep->enq_pt ? ep->pcs ^ 1 : ep->pcs;
> +	ret = crg_udc_epcx_set_dqptr(ep, next, cycle);
> +	if (ret)
> +		return ret;
> +
> +	crg_udc_defer_trb_reuse(ep);
> +
> +	/* Earlier TDs may still have completion events to process. */
> +	if (list_is_first(&req->queue, &ep->queue))
> +		crg_udc_advance_dequeue_pt(ep);
> +	return 0;
> +}

[Severity: Medium]
Can crg_udc_skip_td() leave ep->tran_ring_full set to true after freeing
ring space?

If a transfer ring fills up and the endpoint is halted at High-Speed or
Full-Speed (where crg_udc_ep_halt() retains queued requests on the ring),
dequeuing the request at pause_pt runs crg_udc_skip_td().  Unlike
crg_udc_squeeze_xfer_ring(), crg_udc_skip_td() does not clear
ep->tran_ring_full, and crg_udc_ep_dequeue() skips
crg_udc_resume_paused_ep() because old_ep_state is EP_STATE_HALTED.  When
the endpoint is later unhalted in crg_udc_ep_halt(), it transitions to
EP_STATE_RUNNING without recomputing tran_ring_full via
crg_udc_retry_pending_trbs().  If no unscheduled requests remain in
ep->queue, tran_ring_full stays true and subsequent crg_udc_ep_queue()
calls enqueue requests without building TRBs or ringing the doorbell.

> +
> +static int crg_udc_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
> +{
> +	struct crg_udc_ep *udc_ep_ptr;
> +	struct crg_gadget_dev *crg_udc;
> +	struct crg_uccr __iomem *uccr;
> +	struct crg_udc_request *udc_req = NULL;
> +	struct crg_udc_request *iter;
> +	struct crg_transfer_trb *pause_pt;
> +	enum crg_ep_state old_ep_state;
> +	u32 tmp;
> +	u8 dci, cycle;
> +	u32 generation;
> +	unsigned long flags;
> +	u32 event_generation;
> +	int ret;
> +
> +	if (!_ep || !_req)
> +		return -EINVAL;
> +
> +	udc_ep_ptr = container_of(_ep, struct crg_udc_ep, usb_ep);
> +	crg_udc = udc_ep_ptr->crg_udc;
> +	uccr = crg_udc->uccr;
> +	dci = udc_ep_ptr->dci;
> +
> +	spin_lock_irqsave(&crg_udc->udc_lock, flags);
> +	list_for_each_entry(iter, &udc_ep_ptr->queue, queue) {
> +		if (&iter->usb_req == _req) {
> +			udc_req = iter;
> +			break;
> +		}
> +	}
> +
> +	if (!udc_req) {
> +		ret = -EINVAL;
> +		goto out;
> +	}
> +	if (crg_udc->shutting_down || crg_udc->suspended) {
> +		ret = -ESHUTDOWN;
> +		goto out;
> +	}
> +	if (crg_udc->resetting || crg_udc->controller_recovering ||
> +	    crg_udc->gadget_stopping || crg_udc->endpoint_recovery_pending ||
> +	    crg_udc->deferred_system_error ||
> +	    udc_ep_ptr->nuking || udc_ep_ptr->ep_state == EP_STATE_DISABLED) {
> +		/* The pending teardown will give back this queued request. */
> +		ret = 0;
> +		goto out;
> +	}

[Severity: High]
Should crg_udc_ep_dequeue() return 0 instead of -ESHUTDOWN when
udc_req is still on udc_ep_ptr->queue during shutting_down or suspended?

In crg_udc_remove() and crg_udc_suspend(), shutting_down or suspended is
set before the endpoint queues are drained by crg_udc_ep_nuke().
Returning -ESHUTDOWN while leaving udc_req queued tells callers such as
u_audio's free_ep() that the request is no longer active, so they free
req->buf and call usb_ep_free_request(); crg_udc_free_request() then leaks
the still-queued request and the pending crg_udc_ep_nuke() ->
crg_udc_req_done() triggers a use-after-free when copying bounce buffers
into req->buf and invoking req->complete().

[ ... ]

> +	td_bytes = buffer_length - remaining;
> +	remaining = buffer_length;
> +	for (i = 0; i < count; i++) {
> +		u32 trb_len = plan[i].len;
> +		bool chain_bit = i != count - 1;
> +		bool ioc = !chain_bit;
> +		bool short_pkt = usb_endpoint_dir_out(udc_ep_ptr->desc);
> +
> +		remaining -= trb_len;
> +		td_done += trb_len;
> +		td_size = crg_udc_td_size(td_bytes, td_done,
> +					  udc_ep_ptr->usb_ep.maxpacket, !chain_bit);
> +		if (!full_td && j == intr_rate) {
> +			ioc = true;
> +			j = 0;
> +		}

[Severity: Medium]
Why set ioc = true on intermediate chained TRBs when !full_td?

The last TRB of the truncated TD (i == count - 1) already has
chain_bit = false and ioc = true.  In crg_udc_handle_xfer_event(),
CMPL_CODE_SUCCESS ignores completion events for TRBs with
TRB_CHAIN_BIT_MASK set, so these intermediate IOC events cannot queue the
remaining TRBs, while crg_udc_update_dequeue_pt() prematurely advances
udc_ep_ptr->deq_pt past udc_req_ptr->first_trb into the middle of the
still-active TD.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261124-axiado-ax3000-usb-device-controller-v6-0-b991f9b27111@axiado.com?part=5

  reply	other threads:[~2026-11-24 13:47 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 13:14 [PATCH v6 0/6] Axiado AX3000 and AX3005 USB Device Controller (UDC) Petar Stepanovic
2026-11-24 13:14 ` [PATCH v6 1/6] dt-bindings: usb: gadget: udc: add Axiado AX3000 and AX3005 UDC Petar Stepanovic
2026-11-24 13:19   ` sashiko-bot
2026-11-24 13:14 ` [PATCH v6 2/6] usb: gadget: udc: crg: Add hardware definitions and structs Petar Stepanovic
2026-11-24 13:14 ` [PATCH v6 3/6] usb: gadget: udc: crg: Add ring and transfer management Petar Stepanovic
2026-11-24 13:14 ` [PATCH v6 4/6] usb: gadget: udc: crg: Add endpoint 0 handling Petar Stepanovic
2026-11-24 13:14 ` [PATCH v6 5/6] usb: gadget: udc: crg: Add gadget and endpoint operations Petar Stepanovic
2026-11-24 13:47   ` sashiko-bot [this message]
2026-11-24 13:14 ` [PATCH v6 6/6] usb: gadget: udc: crg: Add core driver and build integration Petar Stepanovic
2026-11-24 13:34   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-231251@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=pstepanovic@axiado.com \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox