This is a note to let you know that I've just added the patch titled md: factor out a mddev_find_locked helper from mddev_find to the 4.19-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: md-factor-out-a-mddev_find_locked-helper-from-mddev_find.patch and it can be found in the queue-4.19 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From 8b57251f9a91f5e5a599de7549915d2d226cc3af Mon Sep 17 00:00:00 2001 From: Christoph Hellwig <hch@xxxxxx> Date: Sat, 3 Apr 2021 18:15:28 +0200 Subject: md: factor out a mddev_find_locked helper from mddev_find From: Christoph Hellwig <hch@xxxxxx> commit 8b57251f9a91f5e5a599de7549915d2d226cc3af upstream. Factor out a self-contained helper to just lookup a mddev by the dev_t "unit". Cc: stable@xxxxxxxxxxxxxxx Reviewed-by: Heming Zhao <heming.zhao@xxxxxxxx> Signed-off-by: Christoph Hellwig <hch@xxxxxx> Signed-off-by: Song Liu <song@xxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- drivers/md/md.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -583,6 +583,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; @@ -610,13 +621,13 @@ static struct mddev *mddev_find_or_alloc 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); @@ -642,12 +653,7 @@ static struct mddev *mddev_find_or_alloc 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); Patches currently in stable-queue which might be from hch@xxxxxx are queue-4.19/modules-unexport-__module_address.patch queue-4.19/modules-mark-find_symbol-static.patch queue-4.19/modules-return-licensing-information-from-find_symbol.patch queue-4.19/modules-inherit-taint_proprietary_module.patch queue-4.19/modules-mark-ref_module-static.patch queue-4.19/modules-rename-the-licence-field-in-struct-symsearch-to-license.patch queue-4.19/md-factor-out-a-mddev_find_locked-helper-from-mddev_find.patch queue-4.19/modules-unexport-__module_text_address.patch queue-4.19/modules-mark-each_symbol_section-static.patch queue-4.19/md-split-mddev_find.patch