From: Danilo Krummrich <dakr@kernel.org>
To: dakr@kernel.org, aliceryhl@google.com,
daniel.almeida@collabora.com, ojeda@kernel.org, boqun@kernel.org,
gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org,
a.hindborg@kernel.org, tmgross@umich.edu, tamird@kernel.org,
acourbot@nvidia.com, work@onurozkan.dev
Cc: driver-core@lists.linux.dev, rust-for-linux@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] rust: io: gate ioremap/iounmap on CONFIG_HAS_IOMEM
Date: Mon, 3 Aug 2026 22:02:36 +0200 [thread overview]
Message-ID: <20260803200249.3494259-1-dakr@kernel.org> (raw)
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 provide a
cfg-gated stub in IoMem::ioremap() that returns -EINVAL when IOMEM is
unavailable, mirroring the C pattern used by
devm_platform_ioremap_resource() and friends.
Reported-by: Miguel Ojeda <ojeda@kernel.org>
Closes: https://lore.kernel.org/all/20260803180931.97202-1-ojeda@kernel.org
Fixes: 3f70ebe63858 ("s390: Enable Rust support")
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
---
rust/helpers/io.c | 2 ++
rust/kernel/io/mem.rs | 11 ++++++++++-
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/rust/helpers/io.c b/rust/helpers/io.c
index 397810864a24..1edbc274951c 100644
--- a/rust/helpers/io.c
+++ b/rust/helpers/io.c
@@ -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)
{
diff --git a/rust/kernel/io/mem.rs b/rust/kernel/io/mem.rs
index fc2a3e24f8d5..3f596bc4fb26 100644
--- a/rust/kernel/io/mem.rs
+++ b/rust/kernel/io/mem.rs
@@ -233,6 +233,12 @@ pub struct IoMem<'a, const SIZE: usize = 0> {
}
impl<'a, const SIZE: usize> IoMem<'a, SIZE> {
+ #[cfg(not(CONFIG_HAS_IOMEM))]
+ fn ioremap(_dev: &'a Device<Bound>, _resource: &Resource) -> Result<Self> {
+ Err(EINVAL)
+ }
+
+ #[cfg(CONFIG_HAS_IOMEM)]
fn ioremap(dev: &'a Device<Bound>, resource: &Resource) -> Result<Self> {
// Note: Some ioremap() implementations use types that depend on the CPU
// word width rather than the bus address width.
@@ -286,8 +292,11 @@ pub fn into_devres(self) -> Result<Devres<IoMem<'static, SIZE>>> {
impl<const SIZE: usize> Drop for IoMem<'_, SIZE> {
fn drop(&mut self) {
+ #[cfg(CONFIG_HAS_IOMEM)]
// SAFETY: Safe as by the invariant of `Io`.
- unsafe { bindings::iounmap(self.io.addr() as *mut c_void) }
+ unsafe {
+ bindings::iounmap(self.io.addr() as *mut c_void)
+ }
}
}
base-commit: 667d0fb32149f023b8b34a1f6f3d384556eafb5a
--
2.55.0
next reply other threads:[~2026-08-03 20:03 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-03 20:02 Danilo Krummrich [this message]
2026-08-03 20:02 ` [PATCH 2/2] rust: io: gate ioremap doctests on CONFIG_HAS_IOMEM Danilo Krummrich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260803200249.3494259-1-dakr@kernel.org \
--to=dakr@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=driver-core@lists.linux.dev \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).