Commit 69d5fbb0 authored by Valentin Obst's avatar Valentin Obst Committed by Miguel Ojeda

rust: error: improve unsafe code in example

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: default avatarValentin Obst <kernel@valentinobst.de>
Reviewed-by: default avatarMartin Rodriguez Reboredo <yakoyoku@gmail.com>
Reviewed-by: default avatarAlice Ryhl <aliceryhl@google.com>
Reviewed-by: default avatarTrevor Gross <tmgross@umich.edu>
Link: https://lore.kernel.org/r/20240131-doc-fixes-v3-v3-2-0c8af94ed7de@valentinobst.deSigned-off-by: default avatarMiguel Ojeda <ojeda@kernel.org>
parent b6cda913
...@@ -264,13 +264,9 @@ pub fn to_result(err: core::ffi::c_int) -> Result { ...@@ -264,13 +264,9 @@ pub fn to_result(err: core::ffi::c_int) -> Result {
/// pdev: &mut PlatformDevice, /// pdev: &mut PlatformDevice,
/// index: u32, /// index: u32,
/// ) -> Result<*mut core::ffi::c_void> { /// ) -> Result<*mut core::ffi::c_void> {
/// // SAFETY: FFI call. /// // SAFETY: `pdev` points to a valid platform device. There are no safety requirements
/// unsafe { /// // on `index`.
/// from_err_ptr(bindings::devm_platform_ioremap_resource( /// from_err_ptr(unsafe { bindings::devm_platform_ioremap_resource(pdev.to_ptr(), index) })
/// pdev.to_ptr(),
/// index,
/// ))
/// }
/// } /// }
/// ``` /// ```
// TODO: Remove `dead_code` marker once an in-kernel client is available. // TODO: Remove `dead_code` marker once an in-kernel client is available.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment