]> www.infradead.org Git - users/hch/block.git/commitdiff
nbd: set nbd->index before releasing nbd_index_mutex
authorTetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
Wed, 25 Aug 2021 13:08:42 +0000 (15:08 +0200)
committerChristoph Hellwig <hch@lst.de>
Wed, 25 Aug 2021 15:03:38 +0000 (17:03 +0200)
Set nbd->index before releasing nbd_index_mutex, as populate_nbd_status()
might access nbd->index as soon as nbd_index_mutex is released.

Fixes: 6e4df4c64881 ("nbd: reduce the nbd_index_mutex scope")
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
[hch: split from a larger patch]
Signed-off-by: Christoph Hellwig <hch@lst.de>
drivers/block/nbd.c

index dfaa95df8d6c95bcc1bf369901718affc3170491..042af761d3a4d7276b4b91023bcd74cda6b492ac 100644 (file)
@@ -1724,10 +1724,10 @@ static struct nbd_device *nbd_dev_add(int index, unsigned int refs)
                if (err >= 0)
                        index = err;
        }
+       nbd->index = index;
        mutex_unlock(&nbd_index_mutex);
        if (err < 0)
                goto out_free_tags;
-       nbd->index = index;
 
        disk = blk_mq_alloc_disk(&nbd->tag_set, NULL);
        if (IS_ERR(disk)) {