diff options
author | Christoph Hellwig <hch@lst.de> | 2021-04-03 19:15:28 +0300 |
---|---|---|
committer | Song Liu <song@kernel.org> | 2021-04-08 08:41:26 +0300 |
commit | 8b57251f9a91f5e5a599de7549915d2d226cc3af (patch) | |
tree | 6f73ef1c1c7455464ff00120bf706135fdd1f6f4 | |
parent | 6a4db2a60306eb65bfb14ccc9fde035b74a4b4e7 (diff) | |
download | linux-8b57251f9a91f5e5a599de7549915d2d226cc3af.tar.xz |
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: Heming Zhao <heming.zhao@suse.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Song Liu <song@kernel.org>
-rw-r--r-- | drivers/md/md.c | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/drivers/md/md.c b/drivers/md/md.c index 464cca5d5952..e10d91122483 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -734,6 +734,17 @@ void mddev_init(struct mddev *mddev) } 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) { struct mddev *mddev, *new = NULL; @@ -745,13 +756,13 @@ static struct mddev *mddev_find(dev_t unit) spin_lock(&all_mddevs_lock); if (unit) { - list_for_each_entry(mddev, &all_mddevs, all_mddevs) - if (mddev->unit == unit) { - mddev_get(mddev); - spin_unlock(&all_mddevs_lock); - kfree(new); - return mddev; - } + mddev = mddev_find_locked(unit); + if (mddev) { + mddev_get(mddev); + spin_unlock(&all_mddevs_lock); + kfree(new); + return mddev; + } if (new) { list_add(&new->all_mddevs, &all_mddevs); @@ -777,12 +788,7 @@ static struct mddev *mddev_find(dev_t unit) return NULL; } - is_free = 1; - list_for_each_entry(mddev, &all_mddevs, all_mddevs) - if (mddev->unit == dev) { - is_free = 0; - break; - } + is_free = !mddev_find_locked(dev); } new->unit = dev; new->md_minor = MINOR(dev); |