]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
rust: io: gate ioremap/iounmap on CONFIG_HAS_IOMEM
authorDanilo Krummrich <dakr@kernel.org>
Wed, 5 Aug 2026 21:28:35 +0000 (23:28 +0200)
committerDanilo Krummrich <dakr@kernel.org>
Thu, 6 Aug 2026 14:05:50 +0000 (16:05 +0200)
s390 does not provide ioremap()/iounmap() when CONFIG_HAS_IOMEM is not
set (which requires CONFIG_PCI on that architecture). This causes a
build failure with Rust enabled on e.g. s390 allnoconfig:

In file included from rust/helpers/helpers.c:68:
rust/helpers/io.c:8:9: error: call to undeclared function 'ioremap'; ISO C99 and later do not support implicit function declarations
      [-Wimplicit-function-declaration]
    8 |         return ioremap(offset, size);
      |                ^
rust/helpers/io.c:19:2: error: call to undeclared function 'iounmap'; ISO C99 and later do not support implicit function declarations
      [-Wimplicit-function-declaration]
   19 |         iounmap(addr);

Guard the C helpers behind #ifdef CONFIG_HAS_IOMEM and cfg-gate the Rust
io::mem module, such that IoMem, ExclusiveIoMem and IoRequest are not
available without CONFIG_HAS_IOMEM.

Note that the C API is inconsistent about this. For instance,
devm_ioremap() has no stub and produces a link failure without
CONFIG_HAS_IOMEM, whereas devm_platform_ioremap_resource() provides an
inline stub returning -EINVAL.

The approach taken here (compile-time gating) matches the former, which
is slightly more appropriate since any driver performing MMIO currently
requires CONFIG_HAS_IOMEM.

Ideally, s390 should provide ioremap()/iounmap() stubs unconditionally
(as UML already does), removing the need for any config gating as
discussed in [1]; a follow-up patch for s390 is expected.

Cc: Arnd Bergmann <arnd@arndb.de>
Reported-by: Miguel Ojeda <ojeda@kernel.org>
Closes: https://lore.kernel.org/all/20260803180931.97202-1-ojeda@kernel.org [1]
Fixes: 3f70ebe63858 ("s390: Enable Rust support")
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Link: https://patch.msgid.link/20260805212920.1996937-1-dakr@kernel.org
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
rust/helpers/io.c
rust/kernel/io.rs
rust/kernel/platform.rs

index 397810864a243958b23c0a6f530e2705ca5e909c..1edbc274951cbf45993f911edc13e2554f80ddc0 100644 (file)
@@ -3,6 +3,7 @@
 #include <linux/io.h>
 #include <linux/ioport.h>
 
+#ifdef CONFIG_HAS_IOMEM
 __rust_helper void __iomem *rust_helper_ioremap(phys_addr_t offset, size_t size)
 {
        return ioremap(offset, size);
@@ -18,6 +19,7 @@ __rust_helper void rust_helper_iounmap(void __iomem *addr)
 {
        iounmap(addr);
 }
+#endif /* CONFIG_HAS_IOMEM */
 
 __rust_helper u8 rust_helper_readb(const void __iomem *addr)
 {
index fcc7678fd9e3c192bcd71964f6e4a6c37863fac6..d30bb5c6d4fcf94be06a86e1b4944031f6acfd5f 100644 (file)
@@ -9,6 +9,7 @@ use crate::{
     prelude::*, //
 };
 
+#[cfg(CONFIG_HAS_IOMEM)]
 pub mod mem;
 pub mod poll;
 pub mod register;
index 9b362e0495d323b9cad883867ba675241ef528c6..d41555a4b31d23f1d21816cb5cd2f047403af4c0 100644 (file)
@@ -17,10 +17,7 @@ use crate::{
         from_result,
         to_result, //
     },
-    io::{
-        mem::IoRequest,
-        Resource, //
-    },
+    io::Resource,
     irq::{
         self,
         IrqRequest, //
@@ -31,6 +28,9 @@ use crate::{
     ThisModule, //
 };
 
+#[cfg(CONFIG_HAS_IOMEM)]
+use crate::io::mem::IoRequest;
+
 use core::{
     marker::PhantomData,
     mem::offset_of,
@@ -307,6 +307,7 @@ impl<Ctx: device::DeviceContext> Device<Ctx> {
     }
 }
 
+#[cfg(CONFIG_HAS_IOMEM)]
 impl Device<Bound> {
     /// Returns an `IoRequest` for the resource at `index`, if any.
     pub fn io_request_by_index(&self, index: u32) -> Option<IoRequest<'_>> {