[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aGlfzdUjvSkdFhNz@cassiopeiae>
Date: Sat, 5 Jul 2025 19:24:29 +0200
From: Danilo Krummrich <dakr@...nel.org>
To: Daniel Almeida <daniel.almeida@...labora.com>
Cc: Miguel Ojeda <ojeda@...nel.org>, Alex Gaynor <alex.gaynor@...il.com>,
Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Andreas Hindborg <a.hindborg@...nel.org>,
Alice Ryhl <aliceryhl@...gle.com>, Trevor Gross <tmgross@...ch.edu>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
"Rafael J. Wysocki" <rafael@...nel.org>,
Andrew Morton <akpm@...ux-foundation.org>,
Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
Ilpo Järvinen <ilpo.jarvinen@...ux.intel.com>,
Bjorn Helgaas <bhelgaas@...gle.com>,
Mika Westerberg <mika.westerberg@...ux.intel.com>,
Ying Huang <huang.ying.caritas@...il.com>,
Benno Lossin <lossin@...nel.org>, linux-kernel@...r.kernel.org,
rust-for-linux@...r.kernel.org
Subject: Re: [PATCH v12 2/3] rust: io: mem: add a generic iomem abstraction
On Fri, Jul 04, 2025 at 01:25:27PM -0300, Daniel Almeida wrote:
This looks good now, one comment below.
> + /// Creates a new `IoMem` instance from a previously acquired [`IoRequest`].
> + pub fn new<'a>(io_request: IoRequest<'a>) -> Result<impl PinInit<Devres<Self>, Error> + 'a> {
> + let io = Self::ioremap(io_request.resource)?;
> + let devres = Devres::new(io_request.device, io);
> +
> + Ok(devres)
> + }
This method should not return `Result<impl PinInit<Devres<Self>, Error> + 'a>`,
but just `impl PinInit<Devres<Self>, Error> + 'a`.
Here's the full diff of the changes needed. :)
diff --git a/rust/kernel/io/mem.rs b/rust/kernel/io/mem.rs
index b047b9a73ae5..cb0805ef0860 100644
--- a/rust/kernel/io/mem.rs
+++ b/rust/kernel/io/mem.rs
@@ -60,7 +60,7 @@ pub(crate) unsafe fn new(device: &'a Device<Bound>, resource: &'a Resource) -> S
/// //
/// // No runtime checks will apply when reading and writing.
/// let request = pdev.request_io_by_index(0).ok_or(ENODEV)?;
- /// let iomem = request.iomap_sized::<42>()?;
+ /// let iomem = request.iomap_sized::<42>();
/// let iomem = KBox::pin_init(iomem, GFP_KERNEL)?;
///
/// let io = iomem.access(pdev.as_ref())?;
@@ -74,9 +74,7 @@ pub(crate) unsafe fn new(device: &'a Device<Bound>, resource: &'a Resource) -> S
/// }
/// }
/// ```
- pub fn iomap_sized<const SIZE: usize>(
- self,
- ) -> Result<impl PinInit<Devres<IoMem<SIZE>>, Error> + 'a> {
+ pub fn iomap_sized<const SIZE: usize>(self) -> impl PinInit<Devres<IoMem<SIZE>>, Error> + 'a {
IoMem::new(self)
}
@@ -88,7 +86,7 @@ pub fn iomap_sized<const SIZE: usize>(
/// C API.
pub fn iomap_exclusive_sized<const SIZE: usize>(
self,
- ) -> Result<impl PinInit<Devres<ExclusiveIoMem<SIZE>>, Error> + 'a> {
+ ) -> impl PinInit<Devres<ExclusiveIoMem<SIZE>>, Error> + 'a {
ExclusiveIoMem::new(self)
}
@@ -122,7 +120,7 @@ pub fn iomap_exclusive_sized<const SIZE: usize>(
/// // family of functions should be used, leading to runtime checks on every
/// // access.
/// let request = pdev.request_io_by_index(0).ok_or(ENODEV)?;
- /// let iomem = request.iomap()?;
+ /// let iomem = request.iomap();
/// let iomem = KBox::pin_init(iomem, GFP_KERNEL)?;
///
/// let io = iomem.access(pdev.as_ref())?;
@@ -135,13 +133,13 @@ pub fn iomap_exclusive_sized<const SIZE: usize>(
/// }
/// }
/// ```
- pub fn iomap(self) -> Result<impl PinInit<Devres<IoMem<0>>, Error> + 'a> {
+ pub fn iomap(self) -> impl PinInit<Devres<IoMem<0>>, Error> + 'a {
Self::iomap_sized::<0>(self)
}
/// Same as [`Self::iomap`] but with exclusive access to the underlying
/// region.
- pub fn iomap_exclusive(self) -> Result<impl PinInit<Devres<ExclusiveIoMem<0>>, Error> + 'a> {
+ pub fn iomap_exclusive(self) -> impl PinInit<Devres<ExclusiveIoMem<0>>, Error> + 'a {
Self::iomap_exclusive_sized::<0>(self)
}
}
@@ -185,11 +183,11 @@ fn ioremap(resource: &Resource) -> Result<Self> {
}
/// Creates a new `ExclusiveIoMem` instance from a previously acquired [`IoRequest`].
- pub fn new<'a>(io_request: IoRequest<'a>) -> Result<impl PinInit<Devres<Self>, Error> + 'a> {
- let iomem = Self::ioremap(io_request.resource)?;
- let devres = Devres::new(io_request.device, iomem);
+ pub fn new<'a>(io_request: IoRequest<'a>) -> impl PinInit<Devres<Self>, Error> + 'a {
+ let dev = io_request.device;
+ let res = io_request.resource;
- Ok(devres)
+ Devres::new(dev, Self::ioremap(res))
}
}
@@ -249,11 +247,11 @@ fn ioremap(resource: &Resource) -> Result<Self> {
}
/// Creates a new `IoMem` instance from a previously acquired [`IoRequest`].
- pub fn new<'a>(io_request: IoRequest<'a>) -> Result<impl PinInit<Devres<Self>, Error> + 'a> {
- let io = Self::ioremap(io_request.resource)?;
- let devres = Devres::new(io_request.device, io);
+ pub fn new<'a>(io_request: IoRequest<'a>) -> impl PinInit<Devres<Self>, Error> + 'a {
+ let dev = io_request.device;
+ let res = io_request.resource;
- Ok(devres)
+ Devres::new(dev, Self::ioremap(res))
}
}
Powered by blists - more mailing lists