Skip to content

Commit 69d5fbb

Browse files
Valentin Obstojeda
authored andcommitted
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>
1 parent b6cda91 commit 69d5fbb

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

rust/kernel/error.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,9 @@ pub fn to_result(err: core::ffi::c_int) -> Result {
264264
/// pdev: &mut PlatformDevice,
265265
/// index: u32,
266266
/// ) -> Result<*mut core::ffi::c_void> {
267-
/// // SAFETY: FFI call.
268-
/// unsafe {
269-
/// from_err_ptr(bindings::devm_platform_ioremap_resource(
270-
/// pdev.to_ptr(),
271-
/// index,
272-
/// ))
273-
/// }
267+
/// // SAFETY: `pdev` points to a valid platform device. There are no safety requirements
268+
/// // on `index`.
269+
/// from_err_ptr(unsafe { bindings::devm_platform_ioremap_resource(pdev.to_ptr(), index) })
274270
/// }
275271
/// ```
276272
// TODO: Remove `dead_code` marker once an in-kernel client is available.

0 commit comments

Comments
 (0)