diff options
author | Valentin Obst <kernel@valentinobst.de> | 2024-01-31 21:23:24 +0100 |
---|---|---|
committer | Miguel Ojeda <ojeda@kernel.org> | 2024-02-18 21:22:27 +0100 |
commit | 69d5fbb0159673ea6737204f4d458a220e81a0c9 (patch) | |
tree | 7013565c84f229db90353952b93bcd4fd751c66f /rust | |
parent | rust: kernel: fix multiple typos in documentation (diff) | |
download | linux-69d5fbb0159673ea6737204f4d458a220e81a0c9.tar.xz linux-69d5fbb0159673ea6737204f4d458a220e81a0c9.zip |
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: Valentin Obst <kernel@valentinobst.de>
Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Trevor Gross <tmgross@umich.edu>
Link: https://lore.kernel.org/r/20240131-doc-fixes-v3-v3-2-0c8af94ed7de@valentinobst.de
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Diffstat (limited to 'rust')
-rw-r--r-- | rust/kernel/error.rs | 10 |
1 files 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. |