Skip to contentSkip to conversation

rust: devres: fix doctest build under `!CONFIG_PCI`

PATCH Applied Miguel Ojeda 3 participants 3 messages May 11, 2025 – May 12, 2025

Subsystems (2)
lore
Share & tools
lore

Miguel Ojeda

author maintainer
#0 lore raw

PATCH 1/1 rust: devres: fix doctest build under `!CONFIG_PCI`

The doctest requires CONFIG_PCI:

    error[E0432]: unresolved import `kernel::pci`
        --> rust/doctests_kernel_generated.rs:2689:44
         |
    2689 | use kernel::{device::Core, devres::Devres, pci};
         |                                            ^^^ no `pci` in the root
         |
    note: found an item that was configured out
        --> rust/kernel/lib.rs:96:9
    note: the item is gated here
        --> rust/kernel/lib.rs:95:1

Thus conditionally compile it (which still checks the syntax).

Fixes f301cb978c06 ("rust: devres: implement Devres::access()")

---
I noticed this in next-20250509 -- as usual, please feel free to fixup it (or not) as preferred. Thanks!

 rust/kernel/devres.rs | 1 +
 1 file changed, 1 insertion(+)
rust/kernel/devres.rs +1 -0
index b67247db92c7..0f79a2ec9474 100644
@@ -195,6 +195,7 @@ pub fn new_foreign_owned(dev: &Device<Bound>, data: T, flags: Flags) -> Result {
     /// # Example
     ///
     /// ```no_run
+    /// # #![cfg(CONFIG_PCI)]
     /// # use kernel::{device::Core, devres::Devres, pci};
     ///
     /// fn from_core(dev: &pci::Device<Core>, devres: Devres<pci::Bar<0x4>>) -> Result {

base-commit: ed61cb3d78d585209ec775933078e268544fe9a4 --
2.49.0

#1 lore raw
Quoted 2 lines · Miguel Ojeda

Thus conditionally compile it (which still checks the syntax).

i.e. "...even when disabled)."

Cheers,
Miguel

maintainer Applied
#2 lore raw
In reply to Miguel Ojeda
Quoted 13 lines · Miguel Ojeda

The doctest requires CONFIG_PCI:

    error[E0432]: unresolved import `kernel::pci`
        --> rust/doctests_kernel_generated.rs:2689:44
         |
    2689 | use kernel::{device::Core, devres::Devres, pci};
         |                                            ^^^ no `pci` in the root
         |
    note: found an item that was configured out
        --> rust/kernel/lib.rs:96:9
    note: the item is gated here
        --> rust/kernel/lib.rs:95:1
Quoted 4 lines

Thus conditionally compile it (which still checks the syntax).

Fixes f301cb978c06 ("rust: devres: implement Devres::access()")

Good catch!

Once we have the platform ioremap() abstractions [1], which are always built-in, we should use those for the doctests. Maybe this could be a good first issue.

Applied to nova-next, thanks!

[1] https://lore.kernel.org/rust-for-linux/20250509-topics-tyr-platform_iomem-v8-3-e9f1725a40da@collabora.com/