]> www.infradead.org Git - users/hch/block.git/commitdiff
loop: reorder loop_exit
authorChristoph Hellwig <hch@lst.de>
Thu, 17 Jun 2021 06:14:41 +0000 (08:14 +0200)
committerChristoph Hellwig <hch@lst.de>
Thu, 17 Jun 2021 06:15:40 +0000 (08:15 +0200)
Unregister the misc and blockdevice first to prevent further access,
and only then iterate to remove the devices.  Also only take
loop_ctl_mutex for the remove action that it actually serialises.

Signed-off-by: Christoph Hellwig <hch@lst.de>
drivers/block/loop.c

index 76e12f3482a917ab9ddc64121095fc5742805bfb..3d4dafc9c8ce745186d16e588b9066fafa4410ea 100644 (file)
@@ -2386,16 +2386,14 @@ static int loop_exit_cb(int id, void *ptr, void *data)
 
 static void __exit loop_exit(void)
 {
-       mutex_lock(&loop_ctl_mutex);
-
-       idr_for_each(&loop_index_idr, &loop_exit_cb, NULL);
-       idr_destroy(&loop_index_idr);
-
        unregister_blkdev(LOOP_MAJOR, "loop");
-
        misc_deregister(&loop_misc);
 
+       mutex_lock(&loop_ctl_mutex);
+       idr_for_each(&loop_index_idr, &loop_exit_cb, NULL);
        mutex_unlock(&loop_ctl_mutex);
+
+       idr_destroy(&loop_index_idr);
 }
 
 module_init(loop_init);