Skip to contentSkip to conversation

mtd:mtdblock: remove the needless mtdblks_lock

PATCH RESEND In review Gu Zheng 2 participants 3 messages Dec 3, 2014 – Jan 8, 2015 Memory technology devices (MTD)

lore
Share & tools
lore

Gu Zheng

author
#0 lore raw

PATCH RESEND 1/3 mtd:mtdblock: remove the needless mtdblks_lock

The global lock mtdblks_lock was used to protect the original mtdblks array to avoid race conditions. As the mtdblks array was already gone, but the mtdblks_lock is left, and it causes latency when open/release dev. So we need to remove it here.

---
 drivers/mtd/mtdblock.c |   10 ----------
 1 files changed, 0 insertions(+), 10 deletions(-)
drivers/mtd/mtdblock.c +0 -10
index 485ea75..bb4c14f 100644
@@ -45,8 +45,6 @@ struct mtdblk_dev {
 	enum { STATE_EMPTY, STATE_CLEAN, STATE_DIRTY } cache_state;
 };
 
-static DEFINE_MUTEX(mtdblks_lock);
-
 /*
  * Cache stuff...
  *
@@ -286,10 +284,8 @@ static int mtdblock_open(struct mtd_blktrans_dev *mbd)
 
 	pr_debug("mtdblock_open\n");
 
-	mutex_lock(&mtdblks_lock);
 	if (mtdblk->count) {
 		mtdblk->count++;
-		mutex_unlock(&mtdblks_lock);
 		return 0;
 	}
 
@@ -302,8 +298,6 @@ static int mtdblock_open(struct mtd_blktrans_dev *mbd)
 		mtdblk->cache_data = NULL;
 	}
 
-	mutex_unlock(&mtdblks_lock);
-
 	pr_debug("ok\n");
 
 	return 0;
@@ -315,8 +309,6 @@ static void mtdblock_release(struct mtd_blktrans_dev *mbd)
 
 	pr_debug("mtdblock_release\n");
 
-	mutex_lock(&mtdblks_lock);
-
 	mutex_lock(&mtdblk->cache_mutex);
 	write_cached_data(mtdblk);
 	mutex_unlock(&mtdblk->cache_mutex);
@@ -331,8 +323,6 @@ static void mtdblock_release(struct mtd_blktrans_dev *mbd)
 		vfree(mtdblk->cache_data);
 	}
 
-	mutex_unlock(&mtdblks_lock);
-
 	pr_debug("ok\n");
 }
 
Signature · 3 lines
1.7.7

.
#1 lore raw
Quoted 6 lines · Gu Zheng

The global lock mtdblks_lock was used to protect the original mtdblks array to avoid race conditions. As the mtdblks array was already gone, but the mtdblks_lock is left, and it causes latency when open/release dev. So we need to remove it here.

Pushed this first patch to l2-mtd.git. Thanks!

I'm kinda ambivalent about the next two. They don't seem like necessary cleanups, really. With the third patch, I think it's actually pretty important that the caller understand that it's using container_of(). I could be convinced otherwise though...

Brian

author
#2 lore raw

Hi Brian,

Quoted 9 lines · Brian Norris
Quoted 6 lines · Gu Zheng

The global lock mtdblks_lock was used to protect the original mtdblks array to avoid race conditions. As the mtdblks array was already gone, but the mtdblks_lock is left, and it causes latency when open/release dev. So we need to remove it here.

Pushed this first patch to l2-mtd.git. Thanks!

Thanks.

Quoted 5 lines

I'm kinda ambivalent about the next two. They don't seem like necessary cleanups, really. With the third patch, I think it's actually pretty important that the caller understand that it's using container_of(). I could be convinced otherwise though...

OK.

Regards,
Gu

Quoted 3 lines

Brian