android: binderfs: drop manual unlock via scoped_guard()
PATCH 1/1 android: binderfs: drop manual unlock via scoped_guard()
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.
--- drivers/android/binderfs.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-)
drivers/android/binderfs.c +12 -13
@@ -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
Signature · 1 line
2.50.1 (Apple Git-155)
Greg KH
maintainerQuoted 8 lines · Biren Pandya
The
device_createfunction manually protects the minor number allocation withbinderfs_minors_mutexand 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