]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
nvme-multipath: fix leak on try_module_get failure
authorKeith Busch <kbusch@kernel.org>
Wed, 25 Feb 2026 19:38:05 +0000 (11:38 -0800)
committerKeith Busch <kbusch@kernel.org>
Fri, 27 Feb 2026 15:35:15 +0000 (07:35 -0800)
We need to fall back to the synchronous removal if we can't get a
reference on the module needed for the deferred removal.

Fixes: 62188639ec16 ("nvme-multipath: introduce delayed removal of the multipath head node")
Reviewed-by: Nilay Shroff <nilay@linux.ibm.com>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Keith Busch <kbusch@kernel.org>
drivers/nvme/host/multipath.c

index bfcc5904e6a266cbda174041f72d1bbc1338beaa..fc6800a9f7f9460d1eb4e3bd15f3700330f4be48 100644 (file)
@@ -1310,13 +1310,11 @@ void nvme_mpath_remove_disk(struct nvme_ns_head *head)
        if (!list_empty(&head->list))
                goto out;
 
-       if (head->delayed_removal_secs) {
-               /*
-                * Ensure that no one could remove this module while the head
-                * remove work is pending.
-                */
-               if (!try_module_get(THIS_MODULE))
-                       goto out;
+       /*
+        * Ensure that no one could remove this module while the head
+        * remove work is pending.
+        */
+       if (head->delayed_removal_secs && try_module_get(THIS_MODULE)) {
                mod_delayed_work(nvme_wq, &head->remove_work,
                                head->delayed_removal_secs * HZ);
        } else {