[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CALNs47t1OME29WyYqv_O8PQ0ZesrXEHtg4xntwQWgL0O6f3L=A@mail.gmail.com>
Date: Wed, 31 Jan 2024 21:23:48 -0500
From: Trevor Gross <tmgross@...ch.edu>
To: kernel@...entinobst.de
Cc: Miguel Ojeda <ojeda@...nel.org>, Alex Gaynor <alex.gaynor@...il.com>,
Wedson Almeida Filho <wedsonaf@...il.com>, Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <benno.lossin@...ton.me>, Andreas Hindborg <a.hindborg@...sung.com>,
Alice Ryhl <aliceryhl@...gle.com>, rust-for-linux@...r.kernel.org,
linux-kernel@...r.kernel.org, Martin Rodriguez Reboredo <yakoyoku@...il.com>
Subject: Re: [PATCH v3 02/12] rust: error: improve unsafe code in example
On Wed, Jan 31, 2024 at 3:24 PM Valentin Obst via B4 Relay
<devnull+kernel.valentinobst.de@...nel.org> wrote:
>
> From: Valentin Obst <kernel@...entinobst.de>
>
> The `from_err_ptr` function is safe. There is no need for the call to it
> to be inside the unsafe block.
>
> Reword the SAFETY comment to provide a better justification of why the
> FFI call is safe.
>
> Signed-off-by: Valentin Obst <kernel@...entinobst.de>
> Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@...il.com>
> Reviewed-by: Alice Ryhl <aliceryhl@...gle.com>
Reviewed-by: Trevor Gross <tmgross@...ch.edu>
> ---
> rust/kernel/error.rs | 10 +++-------
> 1 file changed, 3 insertions(+), 7 deletions(-)
>
> diff --git a/rust/kernel/error.rs b/rust/kernel/error.rs
> index 4f0c1edd63b7..4786d3ee1e92 100644
> --- a/rust/kernel/error.rs
> +++ b/rust/kernel/error.rs
> @@ -264,13 +264,9 @@ pub fn to_result(err: core::ffi::c_int) -> Result {
> /// pdev: &mut PlatformDevice,
> /// index: u32,
> /// ) -> Result<*mut core::ffi::c_void> {
> -/// // SAFETY: FFI call.
> -/// unsafe {
> -/// from_err_ptr(bindings::devm_platform_ioremap_resource(
> -/// pdev.to_ptr(),
> -/// index,
> -/// ))
> -/// }
> +/// // SAFETY: `pdev` points to a valid platform device. There are no safety requirements
> +/// // on `index`.
> +/// from_err_ptr(unsafe { bindings::devm_platform_ioremap_resource(pdev.to_ptr(), index) })
> /// }
> /// ```
> // TODO: Remove `dead_code` marker once an in-kernel client is available.
>
> --
> 2.43.0
>
>
Powered by blists - more mailing lists