rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Danilo Krummrich <dakr@kernel.org>
To: Daniel Almeida <daniel.almeida@collabora.com>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	"Bjorn Helgaas" <bhelgaas@google.com>,
	"Mika Westerberg" <mika.westerberg@linux.intel.com>,
	"Ying Huang" <huang.ying.caritas@gmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org
Subject: Re: [PATCH v12 2/3] rust: io: mem: add a generic iomem abstraction
Date: Sat, 5 Jul 2025 19:24:29 +0200	[thread overview]
Message-ID: <aGlfzdUjvSkdFhNz@cassiopeiae> (raw)
In-Reply-To: <20250704-topics-tyr-platform_iomem-v12-2-1d3d4bd8207d@collabora.com>

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))
     }
 }

  reply	other threads:[~2025-07-05 17:24 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-04 16:25 [PATCH v12 0/3] rust: platform: add Io support Daniel Almeida
2025-07-04 16:25 ` [PATCH v12 1/3] rust: io: add resource abstraction Daniel Almeida
2025-07-05 17:28   ` Danilo Krummrich
2025-07-07  7:30     ` Alice Ryhl
2025-07-07  7:40   ` Alice Ryhl
2025-07-08 17:43     ` Daniel Almeida
2025-07-09 13:36       ` Alice Ryhl
2025-07-10  7:18       ` Alice Ryhl
2025-07-10 13:16     ` Daniel Almeida
2025-07-10 13:24       ` Alice Ryhl
2025-07-10 13:33     ` Daniel Almeida
2025-07-10 13:40       ` Alice Ryhl
2025-07-04 16:25 ` [PATCH v12 2/3] rust: io: mem: add a generic iomem abstraction Daniel Almeida
2025-07-05 17:24   ` Danilo Krummrich [this message]
2025-07-07  7:46   ` Alice Ryhl
2025-07-10 13:58     ` Daniel Almeida
2025-07-14 11:51       ` Alice Ryhl
2025-07-14 12:09         ` Danilo Krummrich
2025-07-14 23:39         ` Daniel Almeida
2025-07-04 16:25 ` [PATCH v12 3/3] rust: platform: add resource accessors Daniel Almeida
2025-07-05 17:34   ` 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=aGlfzdUjvSkdFhNz@cassiopeiae \
    --to=dakr@kernel.org \
    --cc=a.hindborg@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=bhelgaas@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=daniel.almeida@collabora.com \
    --cc=gary@garyguo.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=huang.ying.caritas@gmail.com \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=mika.westerberg@linux.intel.com \
    --cc=ojeda@kernel.org \
    --cc=rafael@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tmgross@umich.edu \
    /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).