Re: [RFC PATCH 2/4] rust: usb: add usb host interface and endpoint abstractions

From: Danilo Krummrich

Date: Mon Jul 13 2026 - 09:42:23 EST


(Cc: Oliver)

On Sun Jul 12, 2026 at 11:07 PM CEST, Colin Braun wrote:
> @@ -382,8 +556,8 @@ fn as_ref(&self) -> &device::Device<Ctx> {
> }
> }
>
> -impl<Ctx: device::DeviceContext> AsRef<Device> for Interface<Ctx> {
> - fn as_ref(&self) -> &Device {
> +impl<Ctx: device::DeviceContext> AsRef<Device<Ctx>> for Interface<Ctx> {
> + fn as_ref(&self) -> &Device<Ctx> {
> // SAFETY: `self.as_raw()` is valid by the type invariants.
> let usb_dev = unsafe { bindings::interface_to_usbdev(self.as_raw()) };

Please see commit f12140f21acb ("rust: usb: don't retain device context for the
interface parent").

We can't derive the device context of a USB device from a USB interface. Please
also see the device context documentation in [1].

USB device drivers are separate from USB interface drivers, we can't assume that
a USB device is bound to a USB device driver just because a USB interface (of
that same device) is bound to an USB interface driver.

The same is true from the Core context, which means the device is in a bus
device callback, where the device lock is held.

This is also the reason why I keep proposing to only expose simple forwarding
helpers on usb::Interface to implement URBs (see also [2] and [3]).

An URB requires either usb::Interface<Bound> or, for a USB device driver,
usb::Device<Bound>. But since we can't derive usb::Device<Bound> from
usb::Interface<Bound> a simple forwarding helper does the trick.

[1] https://rust.docs.kernel.org/kernel/device/trait.DeviceContext.html
[2] https://lore.kernel.org/lkml/DJRF98V7SMXT.14BS8WGBEESZ8@xxxxxxxxxx/
[3] https://lore.kernel.org/lkml/24196da3-62e8-4707-8024-d989bcd5d3a8@xxxxxxxxxxxxxxxxxxx/