mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-08-27 15:17:04 -04:00
Wrap the generated code in a `const _: ()` block to avoid symbol conflict. This removes the need of creating a new identifier. Signed-off-by: Gary Guo <gary@garyguo.net> Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Link: https://patch.msgid.link/20260629-id_info-v2-7-56fccbe9c5ef@garyguo.net [ Consider the serdev code merged in the meantime. - Danilo ] Signed-off-by: Danilo Krummrich <dakr@kernel.org>
55 lines
1.3 KiB
Rust
55 lines
1.3 KiB
Rust
// SPDX-License-Identifier: GPL-2.0
|
|
// SPDX-FileCopyrightText: Copyright (C) 2025 Collabora Ltd.
|
|
|
|
//! Rust USB driver sample.
|
|
|
|
use kernel::{
|
|
device::{
|
|
self,
|
|
Core, //
|
|
},
|
|
prelude::*,
|
|
sync::aref::ARef,
|
|
usb, //
|
|
};
|
|
|
|
struct SampleDriver {
|
|
_intf: ARef<usb::Interface>,
|
|
}
|
|
|
|
kernel::usb_device_table!(
|
|
USB_TABLE,
|
|
<SampleDriver as usb::Driver>::IdInfo,
|
|
[(usb::DeviceId::from_id(0x1234, 0x5678), ()),]
|
|
);
|
|
|
|
impl usb::Driver for SampleDriver {
|
|
type IdInfo = ();
|
|
type Data<'bound> = Self;
|
|
const ID_TABLE: usb::IdTable<Self::IdInfo> = &USB_TABLE;
|
|
|
|
fn probe<'bound>(
|
|
intf: &'bound usb::Interface<Core<'_>>,
|
|
_id: &usb::DeviceId,
|
|
_info: Option<&'bound Self::IdInfo>,
|
|
) -> impl PinInit<Self, Error> + 'bound {
|
|
let dev: &device::Device<Core<'_>> = intf.as_ref();
|
|
dev_info!(dev, "Rust USB driver sample probed\n");
|
|
|
|
Ok(Self { _intf: intf.into() })
|
|
}
|
|
|
|
fn disconnect<'bound>(intf: &'bound usb::Interface<Core<'_>>, _data: Pin<&Self>) {
|
|
let dev: &device::Device<Core<'_>> = intf.as_ref();
|
|
dev_info!(dev, "Rust USB driver sample disconnected\n");
|
|
}
|
|
}
|
|
|
|
kernel::module_usb_driver! {
|
|
type: SampleDriver,
|
|
name: "rust_driver_usb",
|
|
authors: ["Daniel Almeida"],
|
|
description: "Rust USB driver sample",
|
|
license: "GPL v2",
|
|
}
|