Re: [PATCH v2 11/11] RFC: rust: driver: support map-like syntax for ID table

"Danilo Krummrich" <[email protected]> Thu, 30 Jul 2026 23:00:37 +0200
Newsgroups gmane.linux.acpi.devel,gmane.linux.kernel.rust,gmane.linux.kernel,gmane.linux.network,gmane.comp.video.dri.devel,gmane.linux.kernel.pci,gmane.linux.drivers.devicetree,gmane.linux.power-management.general,gmane.linux.pwm,gmane.linux.usb.general
Message-ID <[email protected]>
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