All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Michal Pecio" <michal.pecio@gmail.com>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH] usb: xhci: Work around the ASM3142 bulk UVC bug
Date: Wed, 02 Dec 2026 09:21:51 +0000	[thread overview]
Message-ID: <sashiko-outbox-245289@kernel.org> (raw)
In-Reply-To: <20261202101200.726fc9e3.michal.pecio@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] usb: xhci: skipped TRB loop for zero-length URBs in
  xhci_queue_bulk_tx()
--

commit 771a636094579efceb79700d7566c1836f19f8ac
Author: Michal Pecio <michal.pecio@gmail.com>

usb: xhci: Work around the ASM3142 bulk UVC bug

This commit adds the XHCI_NO_LINK_AFTER_TD quirk for ASMedia 2142/3142
controllers to prepend a No-Op TRB in xhci_queue_bulk_tx() when a bulk TD
would end right before a segment Link TRB or start on one.

> diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
> index 7ccd89a4b9951..9230db6f8bc2c 100644
> --- a/drivers/usb/host/xhci-ring.c
> +++ b/drivers/usb/host/xhci-ring.c
> @@ -3700,6 +3700,20 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
>  		addr = (u64) urb->transfer_dma;
>  		block_len = full_len;
>  	}
> +
> +	if (xhci->quirks & XHCI_NO_LINK_AFTER_TD) {
> +		/*
> +		 * Prepend a No-Op if our TD would end before a Link TRB, or if
> +		 * previous TD failed to prevent this and the HW bug may occur.
> +		 * FIXME: multi-segment TD and/or TD shortened by alignment.
> +		 */
> +		if (last_trb_on_seg(ring->enq_seg, ring->enqueue + num_trbs) ||
> +		    last_trb_on_seg(ring->enq_seg, ring->enqueue)) {
> +			num_trbs++;
> +			first_trb = false;
> +		}
> +	}
> +
>  	ret = prepare_transfer(xhci, xhci->devs[slot_id],
>  			ep_index, urb->stream_id,
>  			num_trbs, urb, 0, mem_flags);
> @@ -3723,6 +3737,10 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
>  	start_cycle = ring->cycle_state;
>  	send_addr = addr;
>  
> +	if (!first_trb)		/* see XHCI_NO_LINK_AFTER_TD */
> +		queue_trb(xhci, ring, true, 0, 0, TRB_INTR_TARGET(0),
> +				TRB_TYPE(TRB_TR_NOOP) | (ring->cycle_state ^ TRB_CYCLE));
> +
>  	/* Queue the TRBs, even if they are zero-length */
>  	for (enqd_len = 0; first_trb || enqd_len < full_len;
>  			enqd_len += trb_buff_len) {

[Severity: High]
Does setting first_trb = false skip the TRB loop completely for a
zero-length URB (full_len == 0)?

When first_trb is false and full_len is 0, only the TRB_TR_NOOP is queued:
no TRB_NORMAL with TRB_IOC is emitted, and td->end_trb and td->end_seg are
left NULL on a TD already linked into ep_ring->td_list.  The URB will never
complete, and the next transfer event or URB dequeue on the ring will hit a
NULL pointer dereference in trb_in_td() -> dma_in_range() ->
trb_to_pos(td->end_seg, td->end_trb).

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261202101200.726fc9e3.michal.pecio@gmail.com?part=1

      reply	other threads:[~2026-12-02  9:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  9:12 [PATCH] usb: xhci: Work around the ASM3142 bulk UVC bug Michal Pecio
2026-12-02  9:21 ` sashiko-bot [this message]

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-245289@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=michal.pecio@gmail.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.