It is possible that `pci_device_id_any` will be passed to the driver, e.g. `driver_override` is used on the device. Therefore, the driver must be able to handle the case where `driver_data` is 0. Thus, update the `probe` functions to get `Option`.
The current code cannot tell if the info does not exist or is the first entry; however this will be achievable once the code is updated to use a `&'static IdInfo` pointer instead of indices. Signed-off-by: Gary Guo <[email protected]> --- drivers/gpu/nova-core/driver.rs | 2 +- rust/kernel/pci.rs | 6 +++--- samples/rust/rust_dma.rs | 2 +- samples/rust/rust_driver_auxiliary.rs | 2 +- samples/rust/rust_driver_pci.rs | 3 ++- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/nova-core/driver.rs b/drivers/gpu/nova-core/driver.rs index 5738d4ac521b..5a5f0b63e0f3 100644 --- a/drivers/gpu/nova-core/driver.rs +++ b/drivers/gpu/nova-core/driver.rs @@ -70,7 +70,7 @@ impl pci::Driver for NovaCoreDriver { fn probe<'bound>( pdev: &'bound pci::Device<Core<'_>>, - _info: &'bound Self::IdInfo, + _info: Option<&'bound Self::IdInfo>, ) -> impl PinInit<Self::Data<'bound>, Error> + 'bound { pin_init::pin_init_scope(move || { dev_dbg!(pdev, "Probe Nova Core GPU driver.\n"); diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs index 5071cae6543f..0e055e4df99e 100644 --- a/rust/kernel/pci.rs +++ b/rust/kernel/pci.rs @@ -113,7 +113,7 @@ extern "C" fn probe_callback( let info = T::ID_TABLE.info(id.index()); from_result(|| { - let data = T::probe(pdev, info); + let data = T::probe(pdev, Some(info)); pdev.as_ref().set_drvdata(data)?; Ok(0) @@ -284,7 +284,7 @@ macro_rules! pci_device_table { /// /// fn probe<'bound>( /// _pdev: &'bound pci::Device<Core<'_>>, -/// _id_info: &'bound Self::IdInfo, +/// _id_info: Option<&'bound Self::IdInfo>, /// ) -> impl PinInit<Self::Data<'bound>, Error> + 'bound { /// Err(ENODEV) /// } @@ -313,7 +313,7 @@ pub trait Driver { /// attempt to initialize the device here. fn probe<'bound>( dev: &'bound Device<device::Core<'_>>, - id_info: &'bound Self::IdInfo, + id_info: Option<&'bound Self::IdInfo>, ) -> impl PinInit<Self::Data<'bound>, Error> + 'bound; /// PCI driver unbind. diff --git a/samples/rust/rust_dma.rs b/samples/rust/rust_dma.rs index 5046b4628d0e..9beb37275e0d 100644 --- a/samples/rust/rust_dma.rs +++ b/samples/rust/rust_dma.rs @@ -63,7 +63,7 @@ impl pci::Driver for DmaSampleDriver { fn probe<'bound>( pdev: &'bound pci::Device<Core<'_>>, - _info: &'bound Self::IdInfo, + _info: Option<&'bound Self::IdInfo>, ) -> impl PinInit<Self, Error> + 'bound { pin_init::pin_init_scope(move || { dev_info!(pdev, "Probe DMA test driver.\n"); diff --git a/samples/rust/rust_driver_auxiliary.rs b/samples/rust/rust_driver_auxiliary.rs index 2c1351040e45..73c63afc046a 100644 --- a/samples/rust/rust_driver_auxiliary.rs +++ b/samples/rust/rust_driver_auxiliary.rs @@ -79,7 +79,7 @@ impl pci::Driver for ParentDriver { fn probe<'bound>( pdev: &'bound pci::Device<Core<'_>>, - _info: &'bound Self::IdInfo, + _info: Option<&'bound Self::IdInfo>, ) -> impl PinInit<Self::Data<'bound>, Error> + 'bound { Ok(ParentData { // SAFETY: `ParentData` is the driver's private data, which is dropped when the diff --git a/samples/rust/rust_driver_pci.rs b/samples/rust/rust_driver_pci.rs index 1aa8197d8698..5547dd704a1b 100644 --- a/samples/rust/rust_driver_pci.rs +++ b/samples/rust/rust_driver_pci.rs @@ -144,7 +144,7 @@ impl pci::Driver for SampleDriver { fn probe<'bound>( pdev: &'bound pci::Device<Core<'_>>, - info: &'bound Self::IdInfo, + info: Option<&'bound Self::IdInfo>, ) -> impl PinInit<Self::Data<'bound>, Error> + 'bound { let vendor = pdev.vendor_id(); dev_dbg!( @@ -153,6 +153,7 @@ fn probe<'bound>( vendor, pdev.device_id() ); + let info = info.ok_or(ENODEV)?; pdev.enable_device_mem()?; pdev.set_master(); -- 2.54.0
