mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] rust_binder: return ENOMEM on shrinker allocation failure
@ 2026-11-28 15:35 Adhyansh Verma
  0 siblings, 0 replies; only message in thread
From: Adhyansh Verma @ 2026-11-28 15:35 UTC (permalink / raw)
  To: Alice Ryhl, Greg Kroah-Hartman, Carlos Llamas
  Cc: Arve Hjønnevåg, Todd Kjos, Christian Brauner,
	Miguel Ojeda, rust-for-linux, linux-kernel

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@gmail.com>
---
 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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-28 15:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-28 15:35 [PATCH] rust_binder: return ENOMEM on shrinker allocation failure Adhyansh Verma

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®