[RFC PATCH 3/9] rust: usb: add usb::Device::set_interface()
From: Mike Lothian
Date: Wed Jun 17 2026 - 11:10:35 EST
Add a safe wrapper over `usb_set_interface()` (the standard SET_INTERFACE
request) so a Rust driver can select an interface's alternate setting
during bring-up. It blocks and sleeps, so it must be called from process
context only.
Signed-off-by: Mike Lothian <mike@xxxxxxxxxxxxxx>
Assisted-by: Claude:claude-opus-4-8 [Claude-Code]
---
rust/kernel/usb.rs | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/rust/kernel/usb.rs b/rust/kernel/usb.rs
index e1fb50fd6997..73637e3467f1 100644
--- a/rust/kernel/usb.rs
+++ b/rust/kernel/usb.rs
@@ -605,6 +605,19 @@ pub fn control_recv(
)
})
}
+
+ /// Selects alternate setting `alternate` of interface `interface`.
+ ///
+ /// Wraps [`usb_set_interface()`] (the standard `SET_INTERFACE` request). This is
+ /// a blocking, sleeping call and must only be invoked from process context.
+ ///
+ /// [`usb_set_interface()`]: https://docs.kernel.org/driver-api/usb/usb.html#c.usb_set_interface
+ pub fn set_interface(&self, interface: u8, alternate: u8) -> Result {
+ // SAFETY: `self.as_raw()` is a valid `struct usb_device` by the type invariant.
+ to_result(unsafe {
+ bindings::usb_set_interface(self.as_raw(), interface.into(), alternate.into())
+ })
+ }
}
// SAFETY: `Device` is a transparent wrapper of a type that doesn't depend on `Device`'s generic
--
2.54.0