Commit 8b57251f authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Song Liu

md: factor out a mddev_find_locked helper from mddev_find

Factor out a self-contained helper to just lookup a mddev by the dev_t
"unit".

Cc: stable@vger.kernel.org
Reviewed-by: default avatarHeming Zhao <heming.zhao@suse.com>
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarSong Liu <song@kernel.org>
parent 6a4db2a6
...@@ -734,6 +734,17 @@ void mddev_init(struct mddev *mddev) ...@@ -734,6 +734,17 @@ void mddev_init(struct mddev *mddev)
} }
EXPORT_SYMBOL_GPL(mddev_init); EXPORT_SYMBOL_GPL(mddev_init);
static struct mddev *mddev_find_locked(dev_t unit)
{
struct mddev *mddev;
list_for_each_entry(mddev, &all_mddevs, all_mddevs)
if (mddev->unit == unit)
return mddev;
return NULL;
}
static struct mddev *mddev_find(dev_t unit) static struct mddev *mddev_find(dev_t unit)
{ {
struct mddev *mddev, *new = NULL; struct mddev *mddev, *new = NULL;
...@@ -745,8 +756,8 @@ static struct mddev *mddev_find(dev_t unit) ...@@ -745,8 +756,8 @@ static struct mddev *mddev_find(dev_t unit)
spin_lock(&all_mddevs_lock); spin_lock(&all_mddevs_lock);
if (unit) { if (unit) {
list_for_each_entry(mddev, &all_mddevs, all_mddevs) mddev = mddev_find_locked(unit);
if (mddev->unit == unit) { if (mddev) {
mddev_get(mddev); mddev_get(mddev);
spin_unlock(&all_mddevs_lock); spin_unlock(&all_mddevs_lock);
kfree(new); kfree(new);
...@@ -777,12 +788,7 @@ static struct mddev *mddev_find(dev_t unit) ...@@ -777,12 +788,7 @@ static struct mddev *mddev_find(dev_t unit)
return NULL; return NULL;
} }
is_free = 1; is_free = !mddev_find_locked(dev);
list_for_each_entry(mddev, &all_mddevs, all_mddevs)
if (mddev->unit == dev) {
is_free = 0;
break;
}
} }
new->unit = dev; new->unit = dev;
new->md_minor = MINOR(dev); new->md_minor = MINOR(dev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment