Skip to contentSkip to conversation

rust: usb: abstractions towards the port of usbsevseg.c to Rust

RFC PATCH In review Alexandru Radovici 2 participants 6 messages Aug 11 – Oct 1

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover rust: usb: abstractions towards the port of usbsevseg.c to Rust

My end goal is to port the usbsevseg.c USB driver to Rust. That driver is small enough to make a useful first target; the remaining piece it needs is sysfs attribute support for USB devices, which I plan to send separately.

Porting the driver requires:
- retrieving endpoints and sending control messages API (this series)
- enabling sysfs attributes API for USB devices (future patch)

These patches add the USB and sysfs abstractions needed to port drivers/usb/misc/usbsevseg.c to Rust: retrieving an interface's endpoints, and sending and receiving control messages.

Patch 1 adds AlternateEndpoint, along with AlternateSetting and the accessors needed to reach one. Patch 2 adds the control transfer methods and the Request type describing a setup packet. Patch 3 adds the sysfs abstractions. Patch 4 adds the sysfs abstractions to usb::Driver.

The part I would most like feedback on is the typestate design in patch
1. HostEndpoint is generic over a direction and a transfer type, both sealed 1-ZST markers, so a function can require e.g. &HostEndpoint<In, Bulk> and skip checking the descriptor itself. Control endpoints get a Bidirectional marker rather than a direction, since bit 7 of bEndpointAddress is ignored for them. I am not sure whether this earns its complexity for the drivers we expect, or whether plain run-time check would be better.

Only as_control(), as_in() and as_out() are implemented so far; as_bulk(), as_interrupt() and as_isochronous() are skiped for now as no current user needs them.

I am not sure about the soundness of the sysfs absgtractions, especially the lifetime annotations of DEVICE_GROUPS.
Feedback for this would be greatly appreciated.

---
Changes in v2:
- add sysfs abstractions
- add DEVICE_GROUPS abstractions to usb::Driver using sysfs
- rename the control_ methods correctly
- use Duration instead of i32 for control functions timeout
- fix control function 0 value timeout from "for ever" to USB_MAX_SYNCHRONOUS_TIMEOUT
- add #[inline] to short functions
- use u16::from_le to read wMaxPacketSize
- rename Generic generic type to Dir
- impl max_nak_rate for HostEndpoint<Bidirectional, Control>
- make data &mut [u8] for control_message_receive
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Alexandru Radovici (4):
rust: usb: add endpoint abstraction
rust: usb: add control message send and receive
rust: sysfs: add abstractions for device attributes
rust: usb: allow drivers to expose sysfs attributes

 rust/kernel/device.rs           |   2 +-
 rust/kernel/lib.rs              |   2 +
 rust/kernel/sysfs.rs            | 602 ++++++++++++++++++++++++++++++++++++++++
 rust/kernel/usb.rs              | 227 ++++++++++++++-
 rust/kernel/usb/control.rs      | 367 ++++++++++++++++++++++++
 rust/kernel/usb/endpoint.rs     | 516 ++++++++++++++++++++++++++++++++++
 samples/rust/rust_driver_usb.rs |  14 +
 7 files changed, 1725 insertions(+), 5 deletions(-)

---
base-commit: 8ba098e6b6ff0db8edf28528d1552be261af30d4
change-id: 20260801-rust-usb_control_msg-ee34e002b818

Best regards,

Signature · 1 line
Alexandru Radovici <[email protected]>
#1 lore raw

RFC PATCH v2 1/4 rust: usb: add endpoint abstraction

Add an abstraction for struct usb_host_endpoint, together with the accessors needed to reach one: AlternateSetting wrapping struct usb_host_interface, Interface::alternate_settings() and Interface::current_alternate_setting(), and Device::control_endpoint() for the default control endpoint, which no interface descriptor lists.

HostEndpoint is generic over two sealed marker traits, EndpointDirection and EndpointTransferType, whose implementors are 1-ZSTs held in PhantomData. An endpoint borrowed from an alternate setting starts out generic in both; as_in(), as_out() and as_control() check the descriptor once and return a reference carrying the corresponding marker, so a function taking &HostEndpoint<In, Bulk> needs no check of its own. The type is #[repr(transparent)] over the C struct and the markers are zero-sized, so the refinement costs nothing and a slice of endpoints can be borrowed directly from the C array.

Control endpoints get a distinct Bidirectional marker rather than an IN or OUT one. A control transfer takes its direction from bit 7 of the setup packet's bmRequestType, and USB 2.0 section 9.6.6 defines the corresponding bit of bEndpointAddress as ignored for control endpoints. as_in() and as_out() are not implemented for Bidirectional, making calling them a compile error rather than a misleading result.

---
 rust/kernel/usb.rs          | 126 ++++++++++-
 rust/kernel/usb/endpoint.rs | 516 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 641 insertions(+), 1 deletion(-)
rust/kernel/usb.rs +125 -1
index 7aff0c82d0af..4f5f1db3e7ca 100644
@@ -20,6 +20,7 @@
     prelude::*,
     sync::aref::AlwaysRefCounted,
     types::Opaque,
+    usb::endpoint::HostEndpoint,
     ThisModule, //
 };
 use core::{
@@ -29,8 +30,11 @@
         MaybeUninit, //
     },
     ptr::NonNull,
+    slice, //
 };
 
+pub mod endpoint;
+
 /// An adapter for the registration of USB drivers.
 pub struct Adapter<T: Driver>(T);
 
@@ -334,6 +338,78 @@ fn disconnect<'bound>(
     );
 }
 
+/// A single alternate setting of an [`Interface`].
+///
+/// A USB interface declares one or more alternate settings, each of which describes a different
+/// endpoint configuration for the same logical function - for example a UVC camera exposing one
+/// setting per bandwidth tier, plus a zero-bandwidth setting used while idle. Exactly one is
+/// active at a time; see [`Interface::current_alt_setting()`].
+///
+/// # Invariants
+///
+/// The wrapped [`Opaque`] holds an initialised `struct usb_host_interface`. Instances are never
+/// constructed by Rust code: they are only ever borrowed out of the `altsetting` array of a
+/// `struct usb_interface` owned by the C side, which guarantees that `desc` is initialised and
+/// that the setting outlives the borrow.
+#[repr(transparent)]
+pub struct AlternateSetting(Opaque<bindings::usb_host_interface>);
+
+impl AlternateSetting {
+    /// Returns a raw pointer to the underlying `struct usb_host_interface`.
+    ///
+    /// By the type invariants the pointer is non-null and points at an initialised alternate
+    /// setting for at least the lifetime of `&self`.
+    fn as_raw(&self) -> *mut bindings::usb_host_interface {
+        self.0.get()
+    }
+
+    /// Returns this setting's `bAlternateSetting` number.
+    ///
+    /// Alternate settings of one interface are numbered from zero; setting 0 always exists and is
+    /// the one the device defaults to after a configuration is selected. This is the value passed
+    /// to `usb_set_interface()` to activate the setting.
+    pub fn number(&self) -> u8 {
+        // SAFETY: By the type invariants, `self.as_raw()` points at a valid
+        // `struct usb_host_interface` with an initialised `desc`.
+        unsafe { (*self.as_raw()).desc.bAlternateSetting }
+    }
+
+    /// Returns the `bInterfaceNumber` of the interface this setting belongs to.
+    ///
+    /// Every alternate setting of a given interface reports the same number, so this identifies
+    /// the interface within its configuration rather than distinguishing settings from one
+    /// another, use [`number()`](Self::number) for that.
+    pub fn interface_number(&self) -> u8 {
+        // SAFETY: By the type invariants, `self.as_raw()` points at a valid
+        // `struct usb_host_interface` with an initialised `desc`.
+        unsafe { (*self.as_raw()).desc.bInterfaceNumber }
+    }
+
+    /// Returns the endpoints declared by this alternate setting, in descriptor order.
+    ///
+    /// The endpoints come back untyped, as `Endpoint<Generic, Generic>`; refine them with
+    /// [`Endpoint::as_in()`], [`Endpoint::as_out()`] and [`Endpoint::as_control()`].
+    pub fn endpoints(&self) -> &[HostEndpoint] {
+        // SAFETY: By the type invariants, `self.as_raw()` points at a valid
+        // `struct usb_host_interface` with an initialised `desc`.
+        let (ptr, len) = (unsafe { (*self.as_raw()).endpoint }, unsafe {
+            (*self.as_raw()).desc.bNumEndpoints
+        });
+
+        if len == 0 {
+            &[]
+        } else {
+            // SAFETY: When `bNumEndpoints` is non-zero the C side has allocated an array of that
+            // many initialised `struct usb_host_endpoint` at `ptr`, living as long as the
+            // interface. `Endpoint` is a `#[repr(transparent)]` wrapper around
+            // `Opaque<bindings::usb_host_endpoint>`, which is itself layout-compatible with
+            // `struct usb_host_endpoint`, so the cast preserves both size and alignment and the
+            // resulting slice borrows for no longer than `&self`.
+            unsafe { slice::from_raw_parts(ptr.cast(), len as usize) }
+        }
+    }
+}
+
 /// A USB interface.
 ///
 /// This structure represents the Rust abstraction for a C [`struct usb_interface`].
@@ -356,6 +432,54 @@ impl<Ctx: device::DeviceContext> Interface<Ctx> {
     fn as_raw(&self) -> *mut bindings::usb_interface {
         self.0.get()
     }
+
+    /// Returns all alternate settings of this interface, in `bAlternateSetting` order.
+    ///
+    /// The slice is never empty: every interface has at least setting 0.
+    pub fn alternate_settings(&self) -> &[AlternateSetting] {
+        // SAFETY: By the type invariants, `self.as_raw()` points at a valid `struct usb_interface`,
+        // so both fields are initialised. Reading them requires nothing of the device context:
+        // `altsetting` is filled in when the interface is created and holds until it is released.
+        let (ptr, len) = (unsafe { (*self.as_raw()).altsetting }, unsafe {
+            (*self.as_raw()).num_altsetting
+        });
+
+        if len == 0 {
+            &[]
+        } else {
+            // SAFETY: When `num_altsetting` is non-zero the C side has allocated an array of that
+            // many initialised `struct usb_host_interface` at `ptr`, kept alive by the interface's
+            // reference for at least as long as `&self`.
+            //
+            // `AlternateSetting` is a `#[repr(transparent)]` wrapper around
+            // `Opaque<bindings::usb_host_interface>`, which is itself layout-compatible with
+            // `struct usb_host_interface`, so the cast preserves both size and alignment and
+            // the resulting slice borrows for no longer than `&self`.
+            unsafe { slice::from_raw_parts(ptr.cast(), len as usize) }
+        }
+    }
+
+    /// Returns the alternate setting that is currently active on this interface.
+    ///
+    /// This is the setting whose endpoints the device is actually prepared to service, so it is
+    /// the one a driver should read endpoint descriptors from. After configuration it is
+    /// setting 0.
+    ///
+    /// The result is a snapshot. `usb_set_interface()` can repoint the interface at a different
+    /// setting, which does not invalidate the returned reference - both point into the same live
+    /// array - but does stop it being the current one. A driver that caches endpoints across a
+    /// setting switch will go on using the previous setting's descriptors.
+    pub fn current_alternate_setting(&self) -> &AlternateSetting {
+        // SAFETY: By the type invariants, `self.as_raw()` points at a valid `struct usb_interface`.
+        // `cur_altsetting` is set when the interface is created and only ever repointed within
+        // that same array by `usb_set_interface()`, so it is non-null and names an initialised
+        // `struct usb_host_interface` for at least the lifetime of `&self`.
+        //
+        // `AlternateSetting` is a `#[repr(transparent)]` wrapper around
+        // `Opaque<bindings::usb_host_interface>` and so layout-compatible with it, and the borrow
+        // lasts no longer than `&self`.
+        unsafe { &*(*self.as_raw()).cur_altsetting.cast() }
+    }
 }
 
 // SAFETY: `usb::Interface` is a transparent wrapper of `struct usb_interface`.
@@ -426,7 +550,7 @@ unsafe impl Sync for Interface {}
 ///
 /// [`struct usb_device`]: https://www.kernel.org/doc/html/latest/driver-api/usb/usb.html#c.usb_device
 #[repr(transparent)]
-struct Device<Ctx: device::DeviceContext = device::Normal>(
+pub struct Device<Ctx: device::DeviceContext = device::Normal>(
     Opaque<bindings::usb_device>,
     PhantomData<Ctx>,
 );
rust/kernel/usb/endpoint.rs new file +516 -0

516 lines not on this page · raw message

Signature · 1 line
2.55.0
#2 lore raw

Re: [PATCH RFC v2 1/4] rust: usb: add endpoint abstraction

Hi Alexandru,

I think the typestate should go away in favor of something simpler:

#[derive(Clone, Copy)]
pub struct Endpoint(u8); <------- private constructor

Drivers ask the Rust layer for their endpoints at probe time, through a wrapper around the C helpers, e.g. usb_find_common_endpoints() or similar

    pub fn find_bulk_endpoints(&self) -> Result<(Endpoint, Endpoint)>

Unlike your current &HostEndpoint, an Endpoint can be stored in the driver's data, since it’s just a u8.

Also, perhaps the control endpoint should be its own type, i.e.:

/// # Invariants
///
/// The wrapped [Endpoint] is a control endpoint of the device. #[derive(Clone, Copy)]
pub struct ControlEndpoint(Endpoint);

impl Deref for ControlEndpoint {
    type Target = Endpoint;

    fn deref(&self) -> &Endpoint {
        &self.0
    }
}
impl Interface<device::Bound> {
    pub fn control_endpoint(&self) -> ControlEndpoint {
        // INVARIANT: Endpoint 0 is always a control endpoint.
        ControlEndpoint(Endpoint(0))
    }

    pub fn control_message_send(&self, ep: ControlEndpoint, ...) -> Result
    pub fn control_message_receive(&self, ep: ControlEndpoint, ...) -> Result
}

By the way, the alternate setting accessors and making usb::Device public don't have a user, not even a planned one, so I'd drop them.

-- Daniel

#3 lore raw

RFC PATCH v2 2/4 rust: usb: add control message send and receive

In reply to Alexandru Radovici

Add Device::control_message_send() and Device::control_message_receive(), wrapping usb_control_msg_send() and usb_control_msg_recv(), plus a Request type describing the bmRequestType, bRequest, wValue and wIndex fields of a setup packet.

Request deliberately omits the two setup packet fields that are properties of a submission rather than of the request itself: the direction bit of bmRequestType and wLength. Both are derived from the method called and the buffer passed, so a caller cannot describe an inbound transfer while handing over a read-only buffer, nor set a length that disagrees with one.

Both methods take a &HostEndpoint<Bidirectional, Control>, so a non-control endpoint cannot be passed by construction.

---
 rust/kernel/usb.rs         |   1 +
 rust/kernel/usb/control.rs | 367 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 368 insertions(+)
rust/kernel/usb.rs +1 -0
index 4f5f1db3e7ca..6670fa2ff377 100644
@@ -33,6 +33,7 @@
     slice, //
 };
 
+pub mod control;
 pub mod endpoint;
 
 /// An adapter for the registration of USB drivers.
rust/kernel/usb/control.rs new file +367 -0

367 lines not on this page · raw message

Signature · 1 line
2.55.0
#4 lore raw

RFC PATCH v2 3/4 rust: sysfs: add abstractions for device attributes

In reply to Alexandru Radovici

Add safe abstractions for exposing sysfs attributes on a device.

A driver implements AttributeOperations once per attribute, keyed by a const ID so that a single type can back several files, and the attribute_list!() macro assembles the statics the C side requires: one struct device_attribute per file, a NULL terminated array of struct attribute pointers, a struct attribute_group, and the NULL terminated group array that a bus driver stores in its dev_groups field.

The show() and store() trampolines recover the driver private data from dev->driver_data and pass it to the operations as Pin<&Data>, together with a bound device. That is only meaningful while a driver is bound, so the groups must be installed through the driver's dev_groups, which the driver core creates after a successful probe and removes before remove runs. Groups reachable earlier, for instance through a device_type, would expose the files from device_add onwards, when no private data has been stored yet.

The file mode is derived from which of the two operations the type implements, so an attribute is never readable without a show() nor writable without a store().

Only a single unnamed group is supported. Attribute visibility callbacks and binary attributes are not implemented.

---
 rust/kernel/device.rs |   2 +-
 rust/kernel/lib.rs    |   2 +
 rust/kernel/sysfs.rs  | 602 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 605 insertions(+), 1 deletion(-)
rust/kernel/device.rs +1 -1
index 1a38b3bbdfb7..c42dcc6edc89 100644
@@ -260,7 +260,7 @@ impl Device<Bound> {
     ///   the device is fully unbound.
     /// - The type `T` must match the type of the `ForeignOwnable` previously stored by
     ///   [`Device::set_drvdata`].
-    unsafe fn drvdata_unchecked<T>(&self) -> Pin<&T> {
+    pub(crate) unsafe fn drvdata_unchecked<T>(&self) -> Pin<&T> {
         // SAFETY: By the type invariants, `self.as_raw()` is a valid pointer to a `struct device`.
         let ptr = unsafe { bindings::dev_get_drvdata(self.as_raw()) };
 
rust/kernel/lib.rs +2 -0
index 9512af7156df..67f981bb7c70 100644
@@ -126,6 +126,8 @@
 pub mod std_vendor;
 pub mod str;
 pub mod sync;
+#[cfg(CONFIG_SYSFS)]
+pub mod sysfs;
 pub mod task;
 pub mod time;
 pub mod tracepoint;
rust/kernel/sysfs.rs new file +602 -0

602 lines not on this page · raw message

Signature · 1 line
2.55.0
#5 lore raw

RFC PATCH v2 4/4 rust: usb: allow drivers to expose sysfs attributes

In reply to Alexandru Radovici

Add an optional DEVICE_GROUPS constant to the USB driver trait and pass it to struct usb_driver::dev_groups, so that a driver can expose sysfs files on every interface it binds to. Drivers that leave it unset keep the current behaviour, as the field stays NULL.

usbcore forwards dev_groups to the embedded struct device_driver, so the files are created only after probe() has returned successfully and are removed before disconnect() runs. An attribute callback therefore always finds the private data that probe() stored.

The constant is typed AttributeGroups<Self::Data<'static>> because a 'static reference cannot name the 'bound lifetime that probe() works with, while the value handed to a callback is a Self::Data<'bound>. A driver whose private data borrows from 'bound must not set this constant; only types that are the same for every instantiation are sound here.

---
 rust/kernel/usb.rs              | 100 ++++++++++++++++++++++++++++++++++++++--
 samples/rust/rust_driver_usb.rs |  14 ++++++
 2 files changed, 111 insertions(+), 3 deletions(-)
rust/kernel/usb.rs +97 -3
index 6670fa2ff377..27fc5e28b45a 100644
@@ -19,6 +19,7 @@
     },
     prelude::*,
     sync::aref::AlwaysRefCounted,
+    sysfs::AttributeGroups,
     types::Opaque,
     usb::endpoint::HostEndpoint,
     ThisModule, //
@@ -26,10 +27,13 @@
 use core::{
     marker::PhantomData,
     mem::{
-        offset_of,
-        MaybeUninit, //
+        offset_of, //
+        MaybeUninit,
+    },
+    ptr::{
+        self,
+        NonNull, //
     },
-    ptr::NonNull,
     slice, //
 };
 
@@ -64,6 +68,11 @@ unsafe fn register(
             (*udrv.get()).probe = Some(Self::probe_callback);
             (*udrv.get()).disconnect = Some(Self::disconnect_callback);
             (*udrv.get()).id_table = T::ID_TABLE.as_ptr();
+            (*udrv.get()).dev_groups = if let Some(dev_group) = T::DEVICE_GROUPS {
+                dev_group.as_ptr()
+            } else {
+                ptr::null_mut()
+            };
         }
 
         // SAFETY: `udrv` is guaranteed to be a valid `DriverType`.
@@ -320,6 +329,91 @@ pub trait Driver {
     /// The table of device ids supported by the driver.
     const ID_TABLE: IdTable<Self::IdInfo>;
 
+    /// The sysfs attribute groups to create for interfaces bound to this driver.
+    ///
+    /// Defaults to `None`, i.e. the driver exposes no attributes of its own.
+    /// Build the value with [`attribute_list!`](crate::attribute_list), which
+    /// declares the necessary `static`s and evaluates to a
+    /// `&'static AttributeGroups`. Only a single group is supported.
+    ///
+    /// The files appear in the sysfs directory of each bound USB *interface*, not
+    /// of the USB device, for instance `/sys/bus/usb/devices/1-1:1.0/`. Because
+    /// `dev_groups` belongs to the driver rather than to one device, every
+    /// interface this driver binds to gets the same set of files, and there is no
+    /// way to hide an individual attribute for some interfaces.
+    ///
+    /// # Registration window
+    ///
+    /// The array is stored in `struct usb_driver::dev_groups`, which usbcore
+    /// forwards to the embedded `struct device_driver`. The driver core creates
+    /// the files only after [`Driver::probe`] has returned successfully and
+    /// removes them before [`Driver::disconnect`] runs, so an attribute callback
+    /// always finds live private data on the interface. That is what makes it
+    /// sound for the callbacks to recover it at all. Groups installed anywhere
+    /// that is populated earlier, such as a `device_type`, would expose the files
+    /// from `device_add` onwards, before `probe` had stored anything.
+    ///
+    /// # `Sync`
+    ///
+    /// Attribute callbacks receive a shared reference to the private data, and
+    /// two readers on separate file descriptors can be inside a `show` for the
+    /// same interface at once, so [`Self::Data`] has to be `Sync` for a driver
+    /// that sets this to `Some`. The bound is deliberately not stated here: it
+    /// comes from `AttributeOperations::Data`, so it is checked at the
+    /// `attribute_list!` call site rather than being imposed on every driver,
+    /// including the ones that leave this as `None`.
+    ///
+    /// # The `'static` in `Self::Data<'static>`
+    ///
+    /// The reference is `'static`, so `'static` is the only lifetime this type
+    /// can name. The value a callback is handed at runtime is the
+    /// `Self::Data<'bound>` that [`Driver::probe`] returned for the current
+    /// binding, so the tag names a different instantiation of the GAT than the
+    /// one that exists, and the attribute code reads the private data as a
+    /// `Self::Data<'static>`. Variance turns `'static` into `'bound`, not the
+    /// reverse, so nothing recovers the difference.
+    ///
+    /// Only set this to `Some` when [`Self::Data`] does not borrow from `'bound`,
+    /// i.e. when every instantiation is the same owning type. A `Data` holding
+    /// `&'bound` references can leak them out of an attribute callback with a
+    /// longer lifetime than they have, and nothing here catches it.
+    ///
+    /// # Examples
+    ///
+    /// ```ignore
+    /// const BLINK: u64 = 0;
+    ///
+    /// // No `'bound` borrows, so `Data<'static>` is the type that exists.
+    /// struct MyData { blinking: AtomicBool }
+    ///
+    /// impl usb::Driver for MyDriver {
+    ///     type Data<'bound> = MyData;
+    ///
+    ///     const DEVICE_GROUPS: Option<&'static AttributeGroups<Self::Data<'static>>> =
+    ///         Some(kernel::attribute_list!(
+    ///             data: MyData,
+    ///             ops: MyDriver,
+    ///             attributes: BLINK,
+    ///         ));
+    ///
+    ///     // ... ID_TABLE, probe, disconnect
+    /// }
+    ///
+    /// impl kernel::sysfs::AttributeOperations<BLINK> for MyDriver {
+    ///     type Data = MyData;
+    ///
+    ///     fn show(
+    ///         data: Pin<&MyData>,
+    ///         _dev: &Device<Bound>,
+    ///         buf: &mut [u8; PAGE_SIZE],
+    ///     ) -> Result<usize> {
+    ///         // Format into `buf` and return the byte count.
+    ///         Ok(0)
+    ///     }
+    /// }
+    /// ```
+    const DEVICE_GROUPS: Option<&'static AttributeGroups<Self::Data<'static>>> = None;
+
     /// USB driver probe.
     ///
     /// Called when a new USB interface is bound to this driver.
samples/rust/rust_driver_usb.rs +14 -0
index 02bd5085f9bc..055c46faf144 100644
@@ -3,6 +3,9 @@
 
 //! Rust USB driver sample.
 
+const ATTR1: u64 = 0;
+const ATTR2: u64 = 1;
+
 use kernel::{
     device::{
         self,
@@ -10,6 +13,7 @@
     },
     prelude::*,
     sync::aref::ARef,
+    sysfs::AttributeOperations,
     usb, //
 };
 
@@ -17,6 +21,16 @@ struct SampleDriver {
     _intf: ARef<usb::Interface>,
 }
 
+#[vtable]
+impl AttributeOperations<ATTR1> for SampleDriver {
+    type Data = Self;
+}
+
+#[vtable]
+impl AttributeOperations<ATTR2> for SampleDriver {
+    type Data = Self;
+}
+
 kernel::usb_device_table!(
     USB_TABLE,
     MODULE_USB_TABLE,
Signature · 1 line
2.55.0