[PATCH v4] binderfs: free minor on binder-control creation failure

From: Chao Huang

Date: Sun Nov 29 2026 - 08:27:55 EST


From: Chao Huang <huangchao@xxxxxxxxxx>

The binderfs_binder_ctl_create() implementation in rust_binderfs.c
allocates a minor before creating the binder-control dentry. If
d_alloc_name() fails, the error path frees the device and drops the
inode, but leaves the minor allocated in binderfs_minors. Repeated
failures can therefore exhaust the global minor IDA.

Release the minor from a dedicated error path after a successful
allocation.

Fixes: eafedbc7c050 ("rust_binder: add Rust Binder driver")
Acked-by: Carlos Llamas <cmllamas@xxxxxxxxxx>
---
Changes in v4:
- Update only rust_binderfs.c because drivers/android/binderfs.c has been
removed from the current tree.

drivers/android/binder/rust_binderfs.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/android/binder/rust_binderfs.c b/drivers/android/binder/rust_binderfs.c
index 5f020226720d..47c4ca9ea74d 100644
--- a/drivers/android/binder/rust_binderfs.c
+++ b/drivers/android/binder/rust_binderfs.c
@@ -427,7 +427,7 @@ static int binderfs_binder_ctl_create(struct super_block *sb)

dentry = d_alloc_name(root, "binder-control");
if (!dentry)
- goto out;
+ goto out_with_minor;

inode->i_private = device;
info->control_dentry = dentry;
@@ -436,6 +436,11 @@ static int binderfs_binder_ctl_create(struct super_block *sb)

return 0;

+out_with_minor:
+ mutex_lock(&binderfs_minors_mutex);
+ ida_free(&binderfs_minors, minor);
+ mutex_unlock(&binderfs_minors_mutex);
+
out:
kfree(device);
iput(inode);
--
2.54.0 (Apple Git-157)