Re: [PATCH] rust: error: clarify that `from_err_ptr` can return `Ok(NULL)`

From: Miguel Ojeda

Date: Sat Mar 28 2026 - 14:01:43 EST


On Sat, Mar 28, 2026 at 4:51 PM Mirko Adzic <adzicmirko97@xxxxxxxxx> wrote:
>
> +/// ```
> +/// # use kernel::error::from_err_ptr;
> +/// # mod bindings {

I see you followed the way we provide "dummy bindings" from elsewhere
-- that is good, thanks!

> +/// fn einval_err_ptr() {
> +/// // SAFETY: ...
> +/// let result = from_err_ptr(unsafe { bindings::einval_err_ptr() });
> +/// assert_eq!(result, Err(EINVAL));
> +/// }

Like you yourself mentioned in the GitHub issue, code inside functions
is not called, so please move it out -- you can keep the "blocks"
separated with a newline so that it is easier to see the different
cases.

> +/// assert_eq!(result, Ok(0x1234 as *mut kernel::ffi::c_void));

Since you are asserting the value, but the bindings are hidden, it may
be best to just assert it is not null.

Thanks for the patch! Please feel free to send a v2 fixing those.

Cheers,
Miguel