From: Biren Pandya <birenpandya@gmail.com>
To: gregkh@linuxfoundation.org, arve@android.com, tkjos@android.com,
brauner@kernel.org, cmllamas@google.com, aliceryhl@google.com
Cc: linux-kernel@vger.kernel.org, Biren Pandya <birenpandya@gmail.com>
Subject: [PATCH] android: binderfs: drop manual unlock via scoped_guard()
Date: Tue, 16 Jun 2026 23:23:41 +0530 [thread overview]
Message-ID: <20260616175340.60355-2-birenpandya@gmail.com> (raw)
The device_create function manually protects the minor number allocation
with binderfs_minors_mutex and relies on multiple manual unlocks on
success and error paths. This is error-prone and adds boilerplate.
Refactor the critical section to use the modern scoped_guard(mutex)
macro. This strictly binds the lock lifecycle to the scope block,
completely eliminating the manual unlocks and guaranteeing lock
safety against future code modifications.
Signed-off-by: Biren Pandya <birenpandya@gmail.com>
---
drivers/android/binderfs.c | 25 ++++++++++++-------------
1 file changed, 12 insertions(+), 13 deletions(-)
diff --git a/drivers/android/binderfs.c b/drivers/android/binderfs.c
index 361d69f756f5..ad5d9439ff87 100644
--- a/drivers/android/binderfs.c
+++ b/drivers/android/binderfs.c
@@ -129,20 +129,19 @@ static int binderfs_binder_device_create(struct inode *ref_inode,
#endif
/* Reserve new minor number for the new device. */
- mutex_lock(&binderfs_minors_mutex);
- if (++info->device_count <= info->mount_opts.max)
- minor = ida_alloc_max(&binderfs_minors,
- use_reserve ? BINDERFS_MAX_MINOR - 1 :
- BINDERFS_MAX_MINOR_CAPPED - 1,
- GFP_KERNEL);
- else
- minor = -ENOSPC;
- if (minor < 0) {
- --info->device_count;
- mutex_unlock(&binderfs_minors_mutex);
- return minor;
+ scoped_guard(mutex, &binderfs_minors_mutex) {
+ if (++info->device_count <= info->mount_opts.max)
+ minor = ida_alloc_max(&binderfs_minors,
+ use_reserve ? BINDERFS_MAX_MINOR - 1 :
+ BINDERFS_MAX_MINOR_CAPPED - 1,
+ GFP_KERNEL);
+ else
+ minor = -ENOSPC;
+ if (minor < 0) {
+ --info->device_count;
+ return minor;
+ }
}
- mutex_unlock(&binderfs_minors_mutex);
ret = -ENOMEM;
device = kzalloc_obj(*device);
base-commit: 64d712aa31f30a125291e7c47209ef7ebd3285a3
--
2.50.1 (Apple Git-155)
next reply other threads:[~2026-06-16 17:53 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-16 17:53 Biren Pandya [this message]
2026-06-17 1:25 ` [PATCH] android: binderfs: drop manual unlock via scoped_guard() Greg KH
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=20260616175340.60355-2-birenpandya@gmail.com \
--to=birenpandya@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=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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.