Re: [PATCH 0/2] rust: usb: add initial USB abstractions
From: Danilo Krummrich
Date: Thu Sep 25 2025 - 09:29:42 EST
On Thu Sep 25, 2025 at 2:52 PM CEST, Greg Kroah-Hartman wrote:
> Yes, this is not a normal way that bindings will probably be merged into
> the tree, but as I consulted deeply with the USB maintainer about this
> topic while eating some good Paris pizza and French wine this week while
> at the Kernel Recipes conference, I think that this deserves an
> exception as they agree this can be merged now and they will be
> responsible for any fallout.[1]
If you rather have it "staging" in-tree that's of course up to you. :)
But, I'd prefer not to expose the incorrect conversion between a
&usb::Interface<Ctx> and a &usb::Device<Ctx> for a full release in Linus' tree.
Besides other implications, this conversation also implies that
&usb::Device<Core> can be derived from &usb::Interface<Core>, which semantically
means that if the USB interface's device lock is held we infer that the device
lock of the USB device is held as well.
I know the code isn't even built, but I don't want people reading the code to
take wrong conclusions from that.
Also, it's dead code anyways, so maybe just apply the following hunk?
Thanks,
Danilo
diff --git a/rust/kernel/usb.rs b/rust/kernel/usb.rs
index 8899e7520b58..9bc3478cf561 100644
--- a/rust/kernel/usb.rs
+++ b/rust/kernel/usb.rs
@@ -340,18 +340,6 @@ fn as_ref(&self) -> &device::Device<Ctx> {
}
}
-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. For a valid interface,
- // the helper should always return a valid USB device pointer.
- let usb_dev = unsafe { bindings::interface_to_usbdev(self.as_raw()) };
-
- // SAFETY: The helper returns a valid interface pointer that shares the
- // same `DeviceContext`.
- unsafe { &*(usb_dev.cast()) }
- }
-}
-
// SAFETY: Instances of `Interface` are always reference-counted.
unsafe impl AlwaysRefCounted for Interface {
fn inc_ref(&self) {