Re: [PATCH v3 1/5] rust: usb: add revocable typed interface I/O
From: Danilo Krummrich
Date: Wed Aug 26 2026 - 15:00:15 EST
On Wed Aug 26, 2026 at 6:30 PM CEST, Mike Lothian wrote:
> + /// Asks the driver core to unbind whatever driver is currently bound to this interface.
What is this needed for? Where do you use it?
> + /// This is the narrow, reviewed replacement for handing out a raw `struct device` pointer: it
> + /// performs exactly one operation (`device_release_driver()`) on this interface's own device,
> + /// and cannot be used to reach the device-wide state of a composite peer.
> + ///
> + /// It is intended for a driver-provided "release my devices" control (e.g. a sysfs attribute),
> + /// and must not be called from the driver's own `probe()` or `disconnect()` callback: the
> + /// driver core already holds the device lock across those.
IOW, it must not be available for Interface<Core>, which due to the deref chain
is not that trivial to model. So, if this is really needed I think this needs a
an abstraction where you get a different device newtype from the scope where
this *should* be called from that allows you to do this and can never leave the
scope.
> + pub fn release_driver(&self) {
> + // SAFETY: `self.as_raw()` is a valid `struct usb_interface` by the type invariant, so the
> + // address of its embedded `dev` is a valid `struct device`. `device_release_driver()`
> + // takes the device lock itself and tolerates a device with no driver bound.
> + unsafe { bindings::device_release_driver(&raw mut (*self.as_raw()).dev) };
> + }
[...]
> +/// A revocable window during which USB I/O is permitted on an interface.
> +///
> +/// A driver-`Bound` interface is *not* on its own proof that a transfer may be issued: the USB
> +/// core forbids I/O outside the window that opens after a successful `probe()`/resume/reset-resume
> +/// and must be closed again before `disconnect()`, `suspend()` or `pre_reset()` returns. This type
> +/// represents exactly that narrower state.
How is this different or narrower than the device's Bound type state represents?
Also, this seems to reinvent Devres, which we superseded with Rust native
lifetimes and higher-ranked types. Please use that instead.