mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v4] rust_binder: unregister shrinker if binderfs initialization fails
@ 2026-12-03  3:22 Poil Zero
  2026-12-03  5:28 ` Shuai Liu
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Poil Zero @ 2026-12-03  3:22 UTC (permalink / raw)
  To: Alice Ryhl, Greg Kroah-Hartman
  Cc: Arve Hjønnevåg, Todd Kjos, Christian Brauner,
	Carlos Llamas, linux-kernel, rust-for-linux

BinderModule::init() registers the Binder shrinker before initializing
binderfs. If init_rust_binderfs() fails, the driver returns an error
but leaves the shrinker registered and its list_lru allocated.

Unregister the shrinker on this error path before destroying its
list_lru so that active reclaim callbacks finish before teardown.
Return the original binderfs error.

Fixes: eafedbc7c050 ("rust_binder: add Rust Binder driver")
Signed-off-by: Poil Zero <poilandgginchi@gmail.com>
---
Changes in v4:
- Resend with git send-email to preserve the diff headers.

Changes in v3:
- Match the From and Signed-off-by names.
- Use Error::from_errno() via the prelude (Alice).

I build-tested the patched Rust Binder object on x86_64 at 89a312991dc6
with CONFIG_ANDROID_BINDER_IPC_RUST=y. I checked the failure path by
source inspection on v7.4-rc5 (fe6ff8d5d675).

 drivers/android/binder/page_range.rs       | 16 ++++++++++++++++
 drivers/android/binder/rust_binder_main.rs |  6 +++++-
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/drivers/android/binder/page_range.rs b/drivers/android/binder/page_range.rs
--- a/drivers/android/binder/page_range.rs
+++ b/drivers/android/binder/page_range.rs
@@ -103,6 +103,22 @@ impl Shrinker {
 
         Ok(())
     }
+
+    /// Unregister this shrinker and destroy its LRU.
+    ///
+    /// Must only be called after a successful `register`.
+    pub(crate) fn unregister(&'static self) {
+        // SAFETY: A successful register initialized list_lru and
+        // stored the registered shrinker in inner.
+        unsafe {
+            let shrinker = *self.inner.get();
+            if !shrinker.is_null() {
+                bindings::shrinker_free(shrinker);
+                self.inner.get().write(ptr::null_mut());
+            }
+            bindings::list_lru_destroy(self.list_lru.get());
+        }
+    }
 }
 
 /// A container that manages a page range in a vma.
diff --git a/drivers/android/binder/rust_binder_main.rs b/drivers/android/binder/rust_binder_main.rs
--- a/drivers/android/binder/rust_binder_main.rs
+++ b/drivers/android/binder/rust_binder_main.rs
@@ -309,7 +309,11 @@ impl kernel::Module for BinderModule {
         BINDER_SHRINKER.register(c"android-binder")?;
 
         // SAFETY: The module is being loaded, so we can initialize binderfs.
-        unsafe { kernel::error::to_result(binderfs::init_rust_binderfs())? };
+        let ret = unsafe { binderfs::init_rust_binderfs() };
+        if ret != 0 {
+            BINDER_SHRINKER.unregister();
+            return Err(Error::from_errno(ret));
+        }
 
         Ok(Self { _netlink: netlink })
     }

base-commit: 89a312991dc6e638a36adc43ccb91dbc25504c04
-- 
Poil Zero

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-12-03 12:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-03  3:22 [PATCH v4] rust_binder: unregister shrinker if binderfs initialization fails Poil Zero
2026-12-03  5:28 ` Shuai Liu
2026-12-03  8:19 ` Alice Ryhl
2026-12-03 12:05 ` Greg Kroah-Hartman

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®