Linux USB
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Yasunobu Sakashita" <hi@yasunobu.dev>
Cc: linux-usb@vger.kernel.org, media-ci@linuxtv.org
Subject: Re: [PATCH] media: uvcvideo: Batch StreamCam unlinks on ASUS ASM2142
Date: Thu, 19 Nov 2026 11:54:48 +0000	[thread overview]
Message-ID: <sashiko-outbox-223067@kernel.org> (raw)
In-Reply-To: <20261119-streamcam-batched-unlink-v1-1-076bc02866c1@yasunobu.dev>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] media: uvcvideo: uvc_streamcam_batch_unlink() skips suspend
  and over-scopes IDs
--

commit f1a098ca74da80c22f81d063591bc26d9db211f8
Author: Yasunobu Sakashita <hi@yasunobu.dev>

media: uvcvideo: Batch StreamCam unlinks on ASUS ASM2142

This commit batches URB unlinks before waiting in uvc_video_stop_transfer()
when stopping a Logitech StreamCam attached to an ASMedia ASM2142 xHCI
controller on an ASUS PRIME Z270-A motherboard.

> diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
> index a92a986ab714b..0ee5a7d175032 100644
> --- a/drivers/media/usb/uvc/uvc_video.c
> +++ b/drivers/media/usb/uvc/uvc_video.c
[ ... ]
> @@ -1885,6 +1886,26 @@ static int uvc_alloc_urb_buffers(struct uvc_streaming *stream,
>  	return 0;
>  }
>  
> +static bool uvc_streamcam_batch_unlink(const struct uvc_streaming *stream)
> +{
> +	const struct usb_device *udev = stream->dev->udev;
> +	struct device *controller = udev->bus->controller;
> +	const struct pci_dev *pdev;
> +
> +	if (stream->frozen || udev->state != USB_STATE_CONFIGURED ||
> +	    udev->speed != USB_SPEED_SUPER ||
> +	    le16_to_cpu(udev->descriptor.idVendor) != 0x046d ||
> +	    le16_to_cpu(udev->descriptor.idProduct) != 0x0893 ||
> +	    !controller || !dev_is_pci(controller))
> +		return false;
> +
> +	pdev = to_pci_dev(controller);
> +	return pdev->vendor == PCI_VENDOR_ID_ASMEDIA &&
> +	       pdev->device == 0x2142 &&
> +	       pdev->subsystem_vendor == PCI_VENDOR_ID_ASUSTEK &&
> +	       pdev->subsystem_device == 0x8732 && pdev->revision == 0;
> +}
> +
>  /*
>   * Uninitialize isochronous/bulk URBs and free transfer buffers.
>   */
> @@ -1896,12 +1917,24 @@ static void uvc_video_stop_transfer(struct uvc_streaming *stream,
>  	uvc_video_stats_stop(stream);
>  
>  	/*
> -	 * We must poison the URBs rather than kill them to ensure that even
> -	 * after the completion handler returns, any asynchronous workqueues
> -	 * will be prevented from resubmitting the URBs.
> +	 * URBs must stay blocked until the workqueue has been flushed.
> +	 * A completion handler can leave work that tries to resubmit an URB.
>  	 */
> -	for_each_uvc_urb(uvc_urb, stream)
> -		usb_poison_urb(uvc_urb->urb);
> +	if (uvc_streamcam_batch_unlink(stream)) {
> +		/*
> +		 * usb_block_urb() keeps URBs blocked after usb_kill_urb().
> +		 * Queue unlinks together so xHCI can coalesce them.
> +		 */
> +		for_each_uvc_urb(uvc_urb, stream)
> +			usb_block_urb(uvc_urb->urb);
> +		for_each_uvc_urb(uvc_urb, stream)
> +			usb_unlink_urb(uvc_urb->urb);
> +		for_each_uvc_urb(uvc_urb, stream)
> +			usb_kill_urb(uvc_urb->urb);
> +	} else {
> +		for_each_uvc_urb(uvc_urb, stream)
> +			usb_poison_urb(uvc_urb->urb);
> +	}

[Severity: Medium]
Does checking stream->frozen in uvc_streamcam_batch_unlink() leave the
suspend path exposed to the same xHCI halt?

uvc_video_suspend() sets stream->frozen = 1 immediately before calling
uvc_video_stop_transfer(), so suspending while streaming falls back to the
unbatched usb_poison_urb() loop.  Also, restricting this to a single USB
device ID and motherboard PCI subsystem ID leaves the ASM2142 host
controller exposed on other boards and cameras.

In uvc_video_complete(), stream->frozen is currently checked only for
-ENOENT before falling through to -ECONNRESET:

drivers/media/usb/uvc/uvc_video.c:uvc_video_complete() {
	...
	case -ENOENT:		/* usb_poison_urb() called. */
		if (stream->frozen)
			return;
		fallthrough;
	case -ECONNRESET:	/* usb_unlink_urb() called. */
	...
}

If uvc_video_complete() checks stream->frozen for both -ENOENT and
-ECONNRESET, uvc_video_stop_transfer() can block, unlink, and poison all
URBs unconditionally without PCI or USB ID checks.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261119-streamcam-batched-unlink-v1-1-076bc02866c1@yasunobu.dev?part=1

  reply	other threads:[~2026-11-19 11:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 11:44 [PATCH] media: uvcvideo: Batch StreamCam unlinks on ASUS ASM2142 Yasunobu Sakashita via B4 Relay
2026-11-19 11:54 ` sashiko-bot [this message]
2026-11-19 12:06 ` Ricardo Ribalda

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-223067@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=hi@yasunobu.dev \
    --cc=linux-usb@vger.kernel.org \
    --cc=media-ci@linuxtv.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