[PATCH 5/6] Revert "mtd: Remove redundant mutex from mtd_blkdevs.c"

From: Zhihao Cheng
Date: Sun Jun 13 2021 - 07:22:32 EST


This reverts commit 8cc9de3ebdf654601db51a516267dff89c49acc3.

Signed-off-by: Zhihao Cheng <chengzhihao1@xxxxxxxxxx>
---
drivers/mtd/mtd_blkdevs.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c
index 41dd3b955136..e8a77f10ae24 100644
--- a/drivers/mtd/mtd_blkdevs.c
+++ b/drivers/mtd/mtd_blkdevs.c
@@ -22,6 +22,7 @@

#include "mtdcore.h"

+static DEFINE_MUTEX(mtd_blkdevs_mutex);
static LIST_HEAD(blktrans_majors);
static DEFINE_MUTEX(blktrans_ref_mutex);

@@ -209,6 +210,7 @@ static int blktrans_open(struct block_device *bdev, fmode_t mode)
if (!dev)
return -ERESTARTSYS; /* FIXME: busy loop! -arnd*/

+ mutex_lock(&mtd_blkdevs_mutex);
mutex_lock(&dev->lock);

if (dev->open++)
@@ -227,6 +229,7 @@ static int blktrans_open(struct block_device *bdev, fmode_t mode)
unlock:
mutex_unlock(&dev->lock);
blktrans_dev_put(dev);
+ mutex_unlock(&mtd_blkdevs_mutex);
return ret;
}

@@ -237,6 +240,7 @@ static void blktrans_release(struct gendisk *disk, fmode_t mode)
if (!dev)
return;

+ mutex_lock(&mtd_blkdevs_mutex);
mutex_lock(&dev->lock);

if (--dev->open)
@@ -253,6 +257,7 @@ static void blktrans_release(struct gendisk *disk, fmode_t mode)
unlock:
mutex_unlock(&dev->lock);
blktrans_dev_put(dev);
+ mutex_unlock(&mtd_blkdevs_mutex);
}

static int blktrans_getgeo(struct block_device *bdev, struct hd_geometry *geo)
--
2.31.1