Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rust: io: add typedef for phys_addr_t

The C typedef phys_addr_t is missing an analogue in Rust, meaning that
we end up using bindings::phys_addr_t or ResourceSize as a replacement
in various places throughout the kernel. Fix that by introducing a new
typedef on the Rust side. Place it next to the existing ResourceSize
typedef since they're quite related to each other.

Cc: stable@vger.kernel.org # for v6.18 [1]
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Link: https://patch.msgid.link/20251112-resource-phys-typedefs-v2-4-538307384f82@google.com
Link: https://lore.kernel.org/all/20251112-resource-phys-typedefs-v2-0-538307384f82@google.com/ [1]
Signed-off-by: Danilo Krummrich <dakr@kernel.org>

authored by

Alice Ryhl and committed by
Danilo Krummrich
dd6ff5cf ee2776e5

+38 -9
+15 -3
rust/kernel/devres.rs
··· 52 52 /// # Examples 53 53 /// 54 54 /// ```no_run 55 - /// # use kernel::{bindings, device::{Bound, Device}, devres::Devres, io::{Io, IoRaw}}; 56 - /// # use core::ops::Deref; 55 + /// use kernel::{ 56 + /// bindings, 57 + /// device::{ 58 + /// Bound, 59 + /// Device, 60 + /// }, 61 + /// devres::Devres, 62 + /// io::{ 63 + /// Io, 64 + /// IoRaw, 65 + /// PhysAddr, 66 + /// }, 67 + /// }; 68 + /// use core::ops::Deref; 57 69 /// 58 70 /// // See also [`pci::Bar`] for a real example. 59 71 /// struct IoMem<const SIZE: usize>(IoRaw<SIZE>); ··· 78 66 /// unsafe fn new(paddr: usize) -> Result<Self>{ 79 67 /// // SAFETY: By the safety requirements of this function [`paddr`, `paddr` + `SIZE`) is 80 68 /// // valid for `ioremap`. 81 - /// let addr = unsafe { bindings::ioremap(paddr as bindings::phys_addr_t, SIZE) }; 69 + /// let addr = unsafe { bindings::ioremap(paddr as PhysAddr, SIZE) }; 82 70 /// if addr.is_null() { 83 71 /// return Err(ENOMEM); 84 72 /// }
+17 -3
rust/kernel/io.rs
··· 15 15 16 16 pub use resource::Resource; 17 17 18 + /// Physical address type. 19 + /// 20 + /// This is a type alias to either `u32` or `u64` depending on the config option 21 + /// `CONFIG_PHYS_ADDR_T_64BIT`, and it can be a u64 even on 32-bit architectures. 22 + pub type PhysAddr = bindings::phys_addr_t; 23 + 18 24 /// Resource Size type. 19 25 /// 20 26 /// This is a type alias to either `u32` or `u64` depending on the config option ··· 76 70 /// # Examples 77 71 /// 78 72 /// ```no_run 79 - /// # use kernel::{bindings, ffi::c_void, io::{Io, IoRaw}}; 80 - /// # use core::ops::Deref; 73 + /// use kernel::{ 74 + /// bindings, 75 + /// ffi::c_void, 76 + /// io::{ 77 + /// Io, 78 + /// IoRaw, 79 + /// PhysAddr, 80 + /// }, 81 + /// }; 82 + /// use core::ops::Deref; 81 83 /// 82 84 /// // See also [`pci::Bar`] for a real example. 83 85 /// struct IoMem<const SIZE: usize>(IoRaw<SIZE>); ··· 98 84 /// unsafe fn new(paddr: usize) -> Result<Self>{ 99 85 /// // SAFETY: By the safety requirements of this function [`paddr`, `paddr` + `SIZE`) is 100 86 /// // valid for `ioremap`. 101 - /// let addr = unsafe { bindings::ioremap(paddr as bindings::phys_addr_t, SIZE) }; 87 + /// let addr = unsafe { bindings::ioremap(paddr as PhysAddr, SIZE) }; 102 88 /// if addr.is_null() { 103 89 /// return Err(ENOMEM); 104 90 /// }
+6 -3
rust/kernel/io/resource.rs
··· 16 16 types::Opaque, // 17 17 }; 18 18 19 - pub use super::ResourceSize; 19 + pub use super::{ 20 + PhysAddr, 21 + ResourceSize, // 22 + }; 20 23 21 24 /// A region allocated from a parent [`Resource`]. 22 25 /// ··· 100 97 /// the region, or a part of it, is already in use. 101 98 pub fn request_region( 102 99 &self, 103 - start: ResourceSize, 100 + start: PhysAddr, 104 101 size: ResourceSize, 105 102 name: CString, 106 103 flags: Flags, ··· 134 131 } 135 132 136 133 /// Returns the start address of the resource. 137 - pub fn start(&self) -> ResourceSize { 134 + pub fn start(&self) -> PhysAddr { 138 135 let inner = self.0.get(); 139 136 // SAFETY: Safe as per the invariants of `Resource`. 140 137 unsafe { (*inner).start }