Skip to main content

from_err_ptr

Function from_err_ptr 

Source
pub fn from_err_ptr<T>(ptr: *mut T) -> Result<*mut T>
Expand description

Transform a kernel “error pointer” to a normal pointer.

Some kernel C API functions return an “error pointer” which optionally embeds an errno. Callers are supposed to check the returned pointer for errors. This function performs the check and converts the “error pointer” to a normal pointer in an idiomatic fashion.

§Examples

ⓘ
fn devm_platform_ioremap_resource(
    pdev: &mut PlatformDevice,
    index: u32,
) -> Result<*mut kernel::ffi::c_void> {
    // 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) })
}