mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Adhyansh Verma <adhyanshverma2010@gmail.com>
To: Alice Ryhl <aliceryhl@google.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Carlos Llamas <cmllamas@google.com>
Cc: "Arve Hjønnevåg" <arve@android.com>,
	"Todd Kjos" <tkjos@android.com>,
	"Christian Brauner" <brauner@kernel.org>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] rust_binder: return ENOMEM on shrinker allocation failure
Date: Sat, 28 Nov 2026 21:05:29 +0530	[thread overview]
Message-ID: <20261128153529.143070-1-adhyanshverma2010@gmail.com> (raw)

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

                 reply	other threads:[~2026-11-28 15:35 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261128153529.143070-1-adhyanshverma2010@gmail.com \
    --to=adhyanshverma2010@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=arve@android.com \
    --cc=brauner@kernel.org \
    --cc=cmllamas@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tkjos@android.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®