linux/zvol_os: don't try to set disk ops if alloc fails

If the kernel fails to allocate the gendisk, zvo_disk will be NULL, and
derefencing it will explode. So don't do that.

Sponsored-by: Klara, Inc.
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Rob Norris <rob.norris@klarasystems.com>
Closes #17396
This commit is contained in:
Rob Norris 2025-05-31 00:25:09 +10:00 committed by GitHub
parent 3084336ae4
commit 0c94d3838d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1352,13 +1352,15 @@ zvol_alloc(dev_t dev, const char *name, uint64_t volblocksize)
*/ */
if (zv->zv_zso->use_blk_mq) { if (zv->zv_zso->use_blk_mq) {
ret = zvol_alloc_blk_mq(zv, &limits); ret = zvol_alloc_blk_mq(zv, &limits);
if (ret != 0)
goto out_kmem;
zso->zvo_disk->fops = &zvol_ops_blk_mq; zso->zvo_disk->fops = &zvol_ops_blk_mq;
} else { } else {
ret = zvol_alloc_non_blk_mq(zso, &limits); ret = zvol_alloc_non_blk_mq(zso, &limits);
if (ret != 0)
goto out_kmem;
zso->zvo_disk->fops = &zvol_ops; zso->zvo_disk->fops = &zvol_ops;
} }
if (ret != 0)
goto out_kmem;
/* Limit read-ahead to a single page to prevent over-prefetching. */ /* Limit read-ahead to a single page to prevent over-prefetching. */
blk_queue_set_read_ahead(zso->zvo_queue, 1); blk_queue_set_read_ahead(zso->zvo_queue, 1);