Re: [PATCH v2 11/11] RFC: rust: driver: support map-like syntax for ID table
From: Danilo Krummrich
Date: Thu Jul 30 2026 - 17:07:43 EST
On Mon Jun 29, 2026 at 2:39 PM CEST, Gary Guo wrote:
> diff --git a/rust/kernel/device_id.rs b/rust/kernel/device_id.rs
> index c81fca5b4986..5f4d191fce51 100644
> --- a/rust/kernel/device_id.rs
> +++ b/rust/kernel/device_id.rs
> @@ -183,6 +183,17 @@ macro_rules! module_device_table {
> $table_type: literal, $device_id_ty: ty,
> $table_name: ident, $id_info_type: ty,
> [$(($id: expr, $info:expr $(,)?)),* $(,)?]
> + ) => {
> + $crate::module_device_table!(
> + $table_type, $device_id_ty, $table_name, $id_info_type,
> + {$($id=>$info,)*}
> + );
> + };
> +
> + (
> + $table_type: literal, $device_id_ty: ty,
> + $table_name: ident, $id_info_type: ty,
> + {$($id: expr => $info:expr),* $(,)?}
> ) => {
> #[export_name =
> concat!("__mod_device_table__", ::core::line!(),
> diff --git a/samples/rust/rust_driver_pci.rs b/samples/rust/rust_driver_pci.rs
> index 2282191e6292..652819dff082 100644
> --- a/samples/rust/rust_driver_pci.rs
> +++ b/samples/rust/rust_driver_pci.rs
> @@ -75,10 +75,9 @@ struct SampleDriverData<'bound> {
> kernel::pci_device_table!(
> PCI_TABLE,
> <SampleDriver as pci::Driver>::IdInfo,
> - [(
> - pci::DeviceId::from_id(pci::Vendor::REDHAT, 0x5),
> - TestIndex::NO_EVENTFD
> - )]
> + {
> + pci::DeviceId::from_id(pci::Vendor::REDHAT, 0x5) => TestIndex::NO_EVENTFD,
> + }
> );
This LGTM, do you want to send a follow-up series?
Thanks,
Danilo