From: Jianjian Huo <samuel.huo@gmail.com>
Date: Sun, 13 Jul 2014 16:08:59 +0000 (-0700)
Subject: bcache: add mutex lock for bch_is_open
X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=789d21dbd9d8889e62c79ec19585fcc97e42ef07;p=linux.git

bcache: add mutex lock for bch_is_open

Since bch_is_open will iterate linked list bch_cache_sets and
uncached_devices, it needs bch_register_lock.

Signed-off-by: Jianjian Huo <samuel.huo@gmail.com>
---

diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
index b6114d6724130..60e75130a44c6 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -1966,10 +1966,12 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
 	if (IS_ERR(bdev)) {
 		if (bdev == ERR_PTR(-EBUSY)) {
 			bdev = lookup_bdev(strim(path));
+			mutex_lock(&bch_register_lock);
 			if (!IS_ERR(bdev) && bch_is_open(bdev))
 				err = "device already registered";
 			else
 				err = "device busy";
+			mutex_unlock(&bch_register_lock);
 		}
 		goto err;
 	}