Skip to contentSkip to conversation

drivers/staging/exfat: Replace binary semaphores for mutexes

PATCH Superseded Davidlohr Bueso 3 participants 4 messages Oct 28, 2019 – Oct 30, 2019 Staging

lore
Share & tools
lore
#0 lore raw

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
index 6c12f2d79f4d..95c02f55de60 100644
@@ -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
maintainer
#1 lore raw
Quoted 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_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
index 6c12f2d79f4d..95c02f55de60 100644
@@ -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
index 5f6caee819a6..c0b09b2dbe96 100644
@@ -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? :(

#2 lore raw

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
index 6c12f2d79f4d..95c02f55de60 100644
@@ -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
#3 lore raw
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_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.

Looks sane.