* [PATCH] android: binderfs: drop manual unlock via scoped_guard()
@ 2026-06-16 17:53 Biren Pandya
2026-06-17 1:25 ` Greg KH
0 siblings, 1 reply; 2+ messages in thread
From: Biren Pandya @ 2026-06-16 17:53 UTC (permalink / raw)
To: gregkh, arve, tkjos, brauner, cmllamas, aliceryhl
Cc: linux-kernel, Biren Pandya
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)
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] android: binderfs: drop manual unlock via scoped_guard()
2026-06-16 17:53 [PATCH] android: binderfs: drop manual unlock via scoped_guard() Biren Pandya
@ 2026-06-17 1:25 ` Greg KH
0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2026-06-17 1:25 UTC (permalink / raw)
To: Biren Pandya; +Cc: arve, tkjos, brauner, cmllamas, aliceryhl, linux-kernel
On Tue, Jun 16, 2026 at 11:23:41PM +0530, Biren Pandya wrote:
> 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.
We don't do scope guard changes that don't actually fix a bug, as it's
not needed. Otherwise we would be rewriting large chunks of the kernel
for it.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-06-17 1:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-16 17:53 [PATCH] android: binderfs: drop manual unlock via scoped_guard() Biren Pandya
2026-06-17 1:25 ` Greg KH
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.