summaryrefslogtreecommitdiff
path: root/rust/kernel/usb.rs
diff options
context:
space:
mode:
authorDanilo Krummrich <dakr@kernel.org>2026-01-07 11:35:02 +0100
committerDanilo Krummrich <dakr@kernel.org>2026-01-16 01:16:44 +0100
commit0af1a9e4629a85964a7eebe58ebd2ca37c8c21fc (patch)
tree1e29b5527f924d339ccb5ffaa3416c8f80f51037 /rust/kernel/usb.rs
parent5f4476e98387618ce22bb93fb5c11142827458ec (diff)
rust: driver: introduce a DriverLayout trait
The DriverLayout trait describes the layout of a specific driver structure, such as `struct pci_driver` or `struct platform_driver`. In a first step, this replaces the associated type RegType of the RegistrationOps with the DriverLayout::DriverType associated type. Acked-by: Alice Ryhl <aliceryhl@google.com> Acked-by: Igor Korotin <igor.korotin.linux@gmail.com> Link: https://patch.msgid.link/20260107103511.570525-4-dakr@kernel.org [ Rename driver::Driver to driver::DriverLayout, as it represents the layout of a driver structure rather than the driver structure itself. - Danilo ] Signed-off-by: Danilo Krummrich <dakr@kernel.org>
Diffstat (limited to 'rust/kernel/usb.rs')
-rw-r--r--rust/kernel/usb.rs18
1 files changed, 11 insertions, 7 deletions
diff --git a/rust/kernel/usb.rs b/rust/kernel/usb.rs
index d10b65e9fb6a..60b761c06fbd 100644
--- a/rust/kernel/usb.rs
+++ b/rust/kernel/usb.rs
@@ -27,13 +27,17 @@ use core::{
/// An adapter for the registration of USB drivers.
pub struct Adapter<T: Driver>(T);
-// SAFETY: A call to `unregister` for a given instance of `RegType` is guaranteed to be valid if
+// SAFETY:
+// - `bindings::usb_driver` is a C type declared as `repr(C)`.
+unsafe impl<T: Driver + 'static> driver::DriverLayout for Adapter<T> {
+ type DriverType = bindings::usb_driver;
+}
+
+// SAFETY: A call to `unregister` for a given instance of `DriverType` is guaranteed to be valid if
// a preceding call to `register` has been successful.
unsafe impl<T: Driver + 'static> driver::RegistrationOps for Adapter<T> {
- type RegType = bindings::usb_driver;
-
unsafe fn register(
- udrv: &Opaque<Self::RegType>,
+ udrv: &Opaque<Self::DriverType>,
name: &'static CStr,
module: &'static ThisModule,
) -> Result {
@@ -45,14 +49,14 @@ unsafe impl<T: Driver + 'static> driver::RegistrationOps for Adapter<T> {
(*udrv.get()).id_table = T::ID_TABLE.as_ptr();
}
- // SAFETY: `udrv` is guaranteed to be a valid `RegType`.
+ // SAFETY: `udrv` is guaranteed to be a valid `DriverType`.
to_result(unsafe {
bindings::usb_register_driver(udrv.get(), module.0, name.as_char_ptr())
})
}
- unsafe fn unregister(udrv: &Opaque<Self::RegType>) {
- // SAFETY: `udrv` is guaranteed to be a valid `RegType`.
+ unsafe fn unregister(udrv: &Opaque<Self::DriverType>) {
+ // SAFETY: `udrv` is guaranteed to be a valid `DriverType`.
unsafe { bindings::usb_deregister(udrv.get()) };
}
}