[PATCH] rust_binder: return ENOMEM on shrinker allocation failure

From: Adhyansh Verma

Date: Sat Nov 28 2026 - 10:35:42 EST


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>
---
drivers/android/binder/page_range.rs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/android/binder/page_range.rs b/drivers/android/binder/page_range.rs
index b0c797523bc..a1f432560a5 100644
--- a/drivers/android/binder/page_range.rs
+++ b/drivers/android/binder/page_range.rs
@@ -84,7 +84,7 @@ pub(crate) fn register(&'static self, name: &CStr) -> Result {
if shrinker.is_null() {
// SAFETY: We initialized it, so its okay to destroy it.
unsafe { bindings::list_lru_destroy(self.list_lru.get()) };
- return Err(Error::from_errno(ret));
+ return Err(ENOMEM);
}

// SAFETY: We're about to register the shrinker, and these are the fields we need to
--
2.56.1