Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

xen-blkfront: add error handling support for add_disk()

We never checked for errors on device_add_disk() as this function
returned void. Now that this is fixed, use the shiny new error
handling. The function xlvbd_alloc_gendisk() typically does the
unwinding on error on allocating the disk and creating the tag,
but since all that error handling was stuffed inside
xlvbd_alloc_gendisk() we must repeat the tag free'ing as well.

We set the info->rq to NULL to ensure blkif_free() doesn't crash
on blk_mq_stop_hw_queues() on device_add_disk() error as the queue
will be long gone by then.

Reviewed-by: Juergen Gross <jgross@suse.com>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
Link: https://lore.kernel.org/r/20211015233028.2167651-6-mcgrof@kernel.org
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Luis Chamberlain and committed by
Jens Axboe
293a7c52 2961c3bb

+7 -1
+7 -1
drivers/block/xen-blkfront.c
··· 2386 2386 for_each_rinfo(info, rinfo, i) 2387 2387 kick_pending_request_queues(rinfo); 2388 2388 2389 - device_add_disk(&info->xbdev->dev, info->gd, NULL); 2389 + err = device_add_disk(&info->xbdev->dev, info->gd, NULL); 2390 + if (err) { 2391 + blk_cleanup_disk(info->gd); 2392 + blk_mq_free_tag_set(&info->tag_set); 2393 + info->rq = NULL; 2394 + goto fail; 2395 + } 2390 2396 2391 2397 info->is_ready = 1; 2392 2398 return;