drivers/staging/exfat: Replace binary semaphores for mutexes
PATCH 1/1 drivers/staging/exfat: Replace binary semaphores for mutexes
At a slight footprint cost (24 vs 32 bytes), mutexes are more optimal than semaphores; it's also a nicer interface for mutual exclusion, which is why they are encouraged over binary semaphores, when possible. There is also lockdep support.
For both v_sem and z_sem, their semantics imply traditional lock ownership; that is, the lock owner is the same for both lock/unlock operations and nothing is done in irq context. Therefore it is safe to convert.
---
This is part of further reducing semaphore users in the kernel.
drivers/staging/exfat/exfat.h | 2 +- drivers/staging/exfat/exfat_super.c | 84 ++++++++++++++++++------------------- 2 files changed, 43 insertions(+), 43 deletions(-)
drivers/staging/exfat/exfat.h +1 -1
@@ -618,7 +618,7 @@ struct fs_info_t {u32 dev_ejected;/* block device operation error flag */ struct fs_func *fs_func; -struct semaphore v_sem; +struct mutex v_mutex;/* FAT cache */ struct buf_cache_t FAT_cache_array[FAT_CACHE_SIZE ];
drivers/staging/exfat/exfat_super.c +42 -42
319 lines not on this page · raw message
Signature · 1 line
2.16.4
Greg KH
maintainerQuoted 45 lines · Davidlohr Bueso
At a slight footprint cost (24 vs 32 bytes), mutexes are more optimal than semaphores; it's also a nicer interface for mutual exclusion, which is why they are encouraged over binary semaphores, when possible. There is also lockdep support.
For both
v_semandz_sem, their semantics imply traditional lock ownership; that is, the lock owner is the same for both lock/unlock operations and nothing is done in irq context. Therefore it is safe to convert.Signed-off-by Davidlohr Bueso <[email protected]>---
This is part of further reducing semaphore users in the kernel.drivers/staging/exfat/exfat.h | 2 +- drivers/staging/exfat/exfat_super.c | 84 ++++++++++++++++++------------------- 2 files changed, 43 insertions(+), 43 deletions(-)drivers/staging/exfat/exfat.h +1
-1@@ -618,7 +618,7 @@ struct fs_info_t {u32 dev_ejected;/* block device operation error flag */ struct fs_func *fs_func; -struct semaphore v_sem; +struct mutex v_mutex;/* FAT cache */ struct buf_cache_t FAT_cache_array[FAT_CACHE_SIZE ];drivers/staging/exfat/exfat_super.c +1
-1@@ -283,7 +283,7 @@ static const struct dentry_operations exfat_dentry_ops = { .d_compare = exfat_cmp, }; -static DEFINE_SEMAPHORE (z_sem); +static DEFINE_MUTEX (z_mutex);static inline void fs_sync (struct super_block *sb,bool do_sync) {
drivers/staging/exfat/exfat_super.c static int ffsMountVol(struct super_block *sb) · line 355
Quoted 5 lines
drivers/staging/exfat/exfat_super.c +1
-1@@ -352,11 +352,11 @@ static int ffsMountVol(struct super_block *sb)pr_info ("[EXFAT] trying to mount...\n" ); -down (&z_sem); +mutex_lock (&z_mutex);
No tabs? :(
PATCH v2 1/1 drivers/staging/exfat: Replace binary semaphores for mutexes
At a slight footprint cost (24 vs 32 bytes), mutexes are more optimal than semaphores; it's also a nicer interface for mutual exclusion, which is why they are encouraged over binary semaphores, when possible.
For both v_sem and z_sem, their semantics imply traditional lock ownership; that is, the lock owner is the same for both lock/unlock operations. Therefore it is safe to convert.
---
This is part of further reducing semaphore users in the kernel.
v2: removed whitespace
drivers/staging/exfat/exfat.h | 2 +- drivers/staging/exfat/exfat_super.c | 84 ++++++++++++++++++------------------- 2 files changed, 43 insertions(+), 43 deletions(-)
drivers/staging/exfat/exfat.h +1 -1
@@ -618,7 +618,7 @@ struct fs_info_t {u32 dev_ejected;/* block device operation error flag */ struct fs_func *fs_func; -struct semaphore v_sem; +struct mutex v_mutex;/* FAT cache */ struct buf_cache_t FAT_cache_array[FAT_CACHE_SIZE ];
drivers/staging/exfat/exfat_super.c +42 -42
319 lines not on this page · raw message
Signature · 1 line
2.16.4
Quoted 9 lines · Davidlohr Bueso
At a slight footprint cost (24 vs 32 bytes), mutexes are more optimal than semaphores; it's also a nicer interface for mutual exclusion, which is why they are encouraged over binary semaphores, when possible.
For both
v_semandz_sem, their semantics imply traditional lock ownership; that is, the lock owner is the same for both lock/unlock operations. Therefore it is safe to convert.Signed-off-by Davidlohr Bueso <[email protected]>
Looks sane.