[PATCH v2 4/4] rust: io: convert to use `#[macro_export_scoped]`
From: Gary Guo
Date: Thu Dec 03 2026 - 10:58:39 EST
Convert I/O macros that use `#[macro_export]` + `#[doc(hidden)]` trick to
use the `#[macro_export_scoped]` macro.
Acked-by: Danilo Krummrich <dakr@xxxxxxxxxx>
Signed-off-by: Gary Guo <gary@xxxxxxxxxxx>
---
rust/kernel/io.rs | 31 ++++++++++++-------------------
rust/kernel/pci/cap.rs | 4 ++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/rust/kernel/io.rs b/rust/kernel/io.rs
index a877df11a03e..746187cf49f4 100644
--- a/rust/kernel/io.rs
+++ b/rust/kernel/io.rs
@@ -10,6 +10,8 @@
num::TryFromIntError, //
};
+use macros::macro_export_scoped;
+
use crate::{
bindings,
fmt,
@@ -1818,8 +1820,7 @@ pub fn project_loc<U, L>(self, location: L) -> <T::Backend as IoBackend>::View<'
/// let reg: Mmio<'_, FIELD> = io_project!(whole, build: FIELD);
/// # Ok::<(), Error>(()) }
/// ```
-#[macro_export]
-#[doc(hidden)]
+#[macro_export_scoped]
macro_rules! io_project {
// Register projection
($io:expr, try: $ioloc:expr) => {{
@@ -1848,8 +1849,6 @@ macro_rules! io_project {
unsafe { view.project_view(ptr) }
}};
}
-#[doc(inline)]
-pub use crate::io_project;
/// Read from I/O memory.
///
@@ -1867,15 +1866,12 @@ macro_rules! io_project {
/// let field: u32 = kernel::io::io_read!(mmio, [try: 2].field);
/// # Ok::<(), Error>(()) }
/// ```
-#[macro_export]
-#[doc(hidden)]
+#[macro_export_scoped]
macro_rules! io_read {
($io:expr, $($proj:tt)*) => {
- $crate::io::Io::read_val($crate::io_project!($io, $($proj)*))
+ $crate::io::Io::read_val($crate::io::io_project!($io, $($proj)*))
};
}
-#[doc(inline)]
-pub use crate::io_read;
/// Writes to I/O memory.
///
@@ -1894,27 +1890,24 @@ macro_rules! io_read {
/// kernel::io::io_write!(mmio, [try: 2].field, 10);
/// # Ok::<(), Error>(()) }
/// ```
-#[macro_export]
-#[doc(hidden)]
+#[macro_export_scoped]
macro_rules! io_write {
(@parse [$io:expr] [$($proj:tt)*] [, $val:expr]) => {
- $crate::io::Io::write_val($crate::io_project!($io, $($proj)*), $val)
+ $crate::io::Io::write_val($crate::io::io_project!($io, $($proj)*), $val)
};
(@parse [$io:expr] [$($proj:tt)*] [.$field:tt $($rest:tt)*]) => {
- $crate::io_write!(@parse [$io] [$($proj)* .$field] [$($rest)*])
+ $crate::io::io_write!(@parse [$io] [$($proj)* .$field] [$($rest)*])
};
(@parse [$io:expr] [$($proj:tt)*] [[$flavor:ident: $index:expr] $($rest:tt)*]) => {
- $crate::io_write!(@parse [$io] [$($proj)* [$flavor: $index]] [$($rest)*])
+ $crate::io::io_write!(@parse [$io] [$($proj)* [$flavor: $index]] [$($rest)*])
};
(@parse [$io:expr] [] [try: $ioloc:expr, $($rest:tt)*]) => {
- $crate::io_write!(@parse [$io] [try: $ioloc] [, $($rest)*])
+ $crate::io::io_write!(@parse [$io] [try: $ioloc] [, $($rest)*])
};
(@parse [$io:expr] [] [build: $ioloc:expr, $($rest:tt)*]) => {
- $crate::io_write!(@parse [$io] [build: $ioloc] [, $($rest)*])
+ $crate::io::io_write!(@parse [$io] [build: $ioloc] [, $($rest)*])
};
($io:expr, $($rest:tt)*) => {
- $crate::io_write!(@parse [$io] [] [$($rest)*])
+ $crate::io::io_write!(@parse [$io] [] [$($rest)*])
};
}
-#[doc(inline)]
-pub use crate::io_write;
diff --git a/rust/kernel/pci/cap.rs b/rust/kernel/pci/cap.rs
index 62f263ada1b3..81e59798ab1c 100644
--- a/rust/kernel/pci/cap.rs
+++ b/rust/kernel/pci/cap.rs
@@ -237,7 +237,7 @@ impl ExtSriovCapability<'_> {
/// VF Offset itself.
#[inline]
pub fn first_vf_offset(&self) -> u16 {
- crate::io_read!(*self, .vf_offset)
+ crate::io::io_read!(*self, .vf_offset)
}
/// Returns an iterator over decoded VF BAR register encodings.
@@ -252,7 +252,7 @@ pub fn first_vf_offset(&self) -> u16 {
/// memory BAR, or if a 64-bit encoding has no upper DWORD.
pub fn vf_bars(&self) -> Result<impl Iterator<Item = ExtSriovVfBar>> {
let slots: [u32; NUM_VF_BARS] =
- core::array::from_fn(|slot| crate::io_read!(*self, .vf_bar[panic: slot]));
+ core::array::from_fn(|slot| crate::io::io_read!(*self, .vf_bar[panic: slot]));
let mut slots = slots.into_iter();
let mut bars = [None; NUM_VF_BARS];
let mut count = 0;
--
2.56.1