From: sashiko-bot@kernel.org
To: "Keisuke Tsukuda" <tkdkei@outlook.jp>
Cc: "linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>
Subject: Re: [RFC PATCH] usb: gadget: uvc: allow userspace to send status packets
Date: Fri, 04 Dec 2026 10:54:16 +0000 [thread overview]
Message-ID: <sashiko-outbox-249640@kernel.org> (raw)
In-Reply-To: <20261204102506.98205-1-tkdkei@outlook.jp>
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] usb: gadget: uvc: stale interrupt_ep->desc on SuperSpeed
reconnect
- [Medium] usb: gadget: uvc: non-extensible UVCIOC_SEND_STATUS UAPI and
no completion
- [Medium] usb: gadget: uvc: unbind hangs on status_ready without
disabling interrupt_ep
- [Medium] usb: uvc: uvc_function_set_alt() skips config_ep_by_speed()
on stale desc
- [Medium] usb: gadget: uvc: uvc_function_unbind() waits without
disabling interrupt_ep
--
commit 740d5c5287a2ae908ef90a9a8ab7b974a03848e7
Author: Keisuke Tsukuda <tkdkei@outlook.jp>
usb: gadget: uvc: allow userspace to send status packets
This commit adds the UVCIOC_SEND_STATUS ioctl and its 32-bit compat handler
so userspace can queue raw status packets on the optional VideoControl
interrupt endpoint. It preallocates a single status request, serializes
queueing with endpoint enable and disable, propagates usb_ep_enable()
errors, and waits for any pending request during unbind.
> diff --git a/drivers/usb/gadget/function/f_uvc.c b/drivers/usb/gadget/function/f_uvc.c
> index c7ce2ce1d5db5..6cf76134853fb 100644
> --- a/drivers/usb/gadget/function/f_uvc.c
> +++ b/drivers/usb/gadget/function/f_uvc.c
[ ... ]
> @@ -305,14 +342,20 @@ uvc_function_set_alt(struct usb_function *f, unsigned interface, unsigned alt)
>
> if (uvc->enable_interrupt_ep) {
> uvcg_info(f, "reset UVC interrupt endpoint\n");
> + spin_lock_irqsave(&uvc->status_ep_lock, flags);
> usb_ep_disable(uvc->interrupt_ep);
> + spin_unlock_irqrestore(&uvc->status_ep_lock, flags);
>
> if (!uvc->interrupt_ep->desc)
> if (config_ep_by_speed(cdev->gadget, f,
> uvc->interrupt_ep))
> return -EINVAL;
>
> - usb_ep_enable(uvc->interrupt_ep);
> + spin_lock_irqsave(&uvc->status_ep_lock, flags);
> + ret = usb_ep_enable(uvc->interrupt_ep);
> + spin_unlock_irqrestore(&uvc->status_ep_lock, flags);
> + if (ret)
> + return ret;
> }
[Severity: High]
Can propagating the error from usb_ep_enable() here fail SET_CONFIGURATION
when reconnecting at SuperSpeed after a Full-Speed or High-Speed session?
On UDCs whose ep->ops->disable() does not clear usb_ep->desc (such as cdnsp
and tegra-xudc), uvc->interrupt_ep->desc remains non-NULL after disconnect,
so config_ep_by_speed() is skipped and uvc->interrupt_ep->comp_desc stays
NULL. During usb_ep_enable(), cdnsp_get_endpoint_max_burst() dereferences
NULL comp_desc->bMaxBurst, while __tegra_xudc_ep_enable() returns -EINVAL
which now aborts uvc_function_set_alt() and fails enumeration. Calling
config_ep_by_speed() unconditionally, as uvc->video.ep already does, avoids
both failures.
[ ... ]
> @@ -391,8 +435,11 @@ uvc_function_disable(struct usb_function *f)
> uvc->state = UVC_STATE_DISCONNECTED;
>
> usb_ep_disable(uvc->video.ep);
> - if (uvc->enable_interrupt_ep)
> + if (uvc->enable_interrupt_ep) {
> + spin_lock_irqsave(&uvc->status_ep_lock, flags);
> usb_ep_disable(uvc->interrupt_ep);
> + spin_unlock_irqrestore(&uvc->status_ep_lock, flags);
> + }
> }
[Severity: Medium]
Should uvc_function_disable() also clear uvc->interrupt_ep->desc (and
comp_desc) after disabling the endpoint?
Because core usb_ep_disable() and UDC drivers such as tegra-xudc and dwc2
leave usb_ep->desc populated, a multi-configuration gadget that shares the
same hardware endpoint across configurations can re-enable interrupt_ep
with the previous configuration's stale descriptor, or fail at SuperSpeed
with a stale NULL comp_desc. This matches the issue fixed for f_ecm and
f_rndis in commit e5b5da96da50 ("usb: gadget: fix wrong endpoint desc").
[ ... ]
> @@ -1076,6 +1145,15 @@ static void uvc_function_unbind(struct usb_configuration *c,
> uvc->control_req = NULL;
> kfree(uvc->control_buf);
> uvc->control_buf = NULL;
> + if (uvc->status_req) {
> + /* Endpoint disable returns pending requests before unbind. */
> + wait_for_completion(&uvc->status_ready);
> + kfree(uvc->status_req->buf);
> + usb_ep_free_request(uvc->interrupt_ep, uvc->status_req);
> + uvc->status_req = NULL;
> + /* The same function object may be bound again. */
> + complete(&uvc->status_ready);
> + }
[Severity: Medium]
Can wait_for_completion(&uvc->status_ready) hang forever here if an
in-flight setup request re-enables uvc->interrupt_ep during configfs
unbind?
Unlike legacy usb_remove_function(), configfs purge_configs_funcs() invokes
f->unbind() without calling f->disable(). On UDCs that do not implement
udc_async_callbacks or set gadget->irq (such as tegra-xudc and
renesas_usb3), an in-flight setup callback can run between
usb_gadget_disconnect_locked() and gi->unbind = 1:
CPU0 (unbind) CPU1 (EP0 setup / userspace)
gadget_unbind_driver()
usb_gadget_disconnect_locked()
uvc_function_disable()
configfs_composite_setup()
uvc_function_set_alt()
usb_ep_enable(interrupt_ep)
configfs_composite_unbind()
gi->unbind = 1
purge_configs_funcs()
uvc_function_unbind()
uvc_function_send_status()
try_wait_for_completion(&status_ready)
usb_ep_queue(interrupt_ep, status_req)
wait_for_completion(&vdev_release_done)
wait_for_completion(&status_ready) <-- hangs forever
Because usb_gadget_udc_stop_locked() cannot run until uvc_function_unbind()
returns, status_req is never completed and unbind wedges in uninterruptible
sleep while holding configfs and gadget device locks.
[Severity: Medium]
Should uvc_function_unbind() explicitly disable uvc->interrupt_ep under
uvc->status_ep_lock before waiting on uvc->status_ready?
On UDCs such as musb (where musb_gadget_pullup() defers pullup disable to
delayed work without stopping setup IRQs) and chipidea (where
isr_setup_packet_handler() drops ci->lock before driver->setup() and
ci_udc_pullup(0) does not synchronize IRQs), a concurrent setup request can
re-enable uvc->interrupt_ep after usb_gadget_disconnect_locked(), allowing
UVCIOC_SEND_STATUS to queue status_req while uvc_function_unbind() waits
for the V4L2 device to close. Calling usb_ep_disable(uvc->interrupt_ep)
under status_ep_lock after wait_for_completion(&vdev_release_done) cancels
any pending request before wait_for_completion(&uvc->status_ready).
> diff --git a/include/uapi/linux/usb/g_uvc.h b/include/uapi/linux/usb/g_uvc.h
> index 8d7824dde1b2f..cfe290b3063a6 100644
> --- a/include/uapi/linux/usb/g_uvc.h
> +++ b/include/uapi/linux/usb/g_uvc.h
> @@ -38,5 +38,8 @@ struct uvc_event {
> };
>
> #define UVCIOC_SEND_RESPONSE _IOW('U', 1, struct uvc_request_data)
> +#define UVCIOC_SEND_STATUS _IOW('U', 2, struct uvc_request_data)
> +
> +#define UVC_STATUS_MAX_PACKET_SIZE 16
>
> #endif /* __LINUX_USB_G_UVC_H */
[Severity: Medium]
Should UVCIOC_SEND_STATUS use a dedicated extensible struct instead of
reusing struct uvc_request_data?
struct uvc_request_data uses a signed __s32 length specifically for
UVCIOC_SEND_RESPONSE's EP0 stall convention and has no flags or reserved
fields for future extensions without adding another ioctl. Exporting
UVC_STATUS_MAX_PACKET_SIZE as 16 also locks the driver's current hardcoded
wMaxPacketSize into permanent UAPI, even though UVC status packets can
exceed 16 bytes if made configurable.
In addition, uvc_function_status_complete() currently discards req->status
without notifying userspace, so callers that receive -EBUSY while a host
(such as an idle Linux 6.16+ uvcvideo host) is not polling the interrupt
endpoint have no event-driven signal to resend the latest control value.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204102506.98205-1-tkdkei@outlook.jp?part=1
prev parent reply other threads:[~2026-12-04 10:54 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 10:25 [RFC PATCH] usb: gadget: uvc: allow userspace to send status packets Keisuke Tsukuda
2026-12-04 10:54 ` 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-249640@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tkdkei@outlook.jp \
/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.