Re: [PATCH] rust_binder: return ENOMEM on shrinker allocation failure

From: Alice Ryhl

Date: Sun Nov 29 2026 - 06:17:00 EST


On Sat, Nov 28, 2026 at 09:05:29PM +0530, Adhyansh Verma wrote:
> In Shrinker::register(), __list_lru_init() is called to initialize the
> list_lru. When it succeeds, ret is 0. Subsequently, shrinker_alloc() is
> called to allocate the shrinker. If memory allocation fails, shrinker is
> null and the error cleanup path executes:
>
> unsafe { bindings::list_lru_destroy(self.list_lru.get()) };
> return Err(Error::from_errno(ret));
>
> Because ret is still 0 from the earlier successful __list_lru_init(),
> Error::from_errno(0) is called.
>
> Per rust/kernel/error.rs, passing 0 to Error::from_errno() is considered
> a kernel bug. It triggers a pr_warn! warning ("attempted to create Error
> with out of range errno: 0") and falls back to EINVAL instead of
> returning ENOMEM to indicate the allocation failure.
>
> Fix this by returning Err(ENOMEM) directly when shrinker_alloc() returns
> null.
>
> Fixes: eafedbc7c050 ("rust_binder: add Rust Binder driver")
> Signed-off-by: Adhyansh Verma <adhyanshverma2010@xxxxxxxxx>

Reviewed-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>

Alice