[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAH5fLggiK6eg+aHGSXeZCMovkGTNkEhxKqKwubcKC=4accNuWQ@mail.gmail.com>
Date: Thu, 9 Jan 2025 15:00:38 +0100
From: Alice Ryhl <aliceryhl@...gle.com>
To: Daniel Almeida <daniel.almeida@...labora.com>
Cc: alex.gaynor@...il.com, boqun.feng@...il.com, gary@...yguo.net,
bjorn3_gh@...tonmail.com, benno.lossin@...ton.me, a.hindborg@...nel.org,
tmgross@...ch.edu, gregkh@...uxfoundation.org, rafael@...nel.org,
dakr@...nel.org, boris.brezillon@...labora.com,
rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v4 3/3] rust: platform: allow ioremap of platform resources
On Thu, Jan 9, 2025 at 2:32 PM Daniel Almeida
<daniel.almeida@...labora.com> wrote:
>
> The preceding patches added support for resources, and for a general
> IoMem abstraction, but thus far there is no way to access said IoMem
> from drivers, as its creation is unsafe and depends on a resource that
> must be acquired from a some device first.
"a some device" typo?
> + /// ```no_run
> + /// # use kernel::{bindings, c_str, platform};
> + ///
> + /// fn probe(pdev: &mut platform::Device, /* ... */) -> Result<()> {
When you use `#` to hide part of the example, you end up with a weird
empty line at the top of the example. Please un-hide the line or
remove the empty line.
> + /// Returns the resource at `index`, if any.
> + pub fn resource(&self, index: u32) -> Option<&Resource> {
> + // SAFETY: `self.as_raw()` returns a valid pointer to a `struct platform_device`.
> + let resource = unsafe {
> + bindings::platform_get_resource(self.as_raw(), bindings::IORESOURCE_MEM, index)
> + };
> +
> + // SAFETY: `resource` is a valid pointer to a `struct resource` as
> + // returned by `platform_get_resource`.
> + (!resource.is_null()).then(|| unsafe { Resource::from_ptr(resource) })
This is a bit confusing. Perhaps just
if resource.is_null() {
return None;
}
Some(Resource::from_ptr(resource))
Alice
Powered by blists - more mailing lists