Message ID | 20210927220039.1064193-10-mcgrof@kernel.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | block: second batch of add_disk() error handling conversions | expand |
On 28.09.21 00:00, Luis Chamberlain wrote: > 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. > > Signed-off-by: Luis Chamberlain <mcgrof@kernel.org> Reviewed-by: Juergen Gross <jgross@suse.com> Juergen
diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index 72902104f111..86440b051766 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c @@ -2385,7 +2385,13 @@ static void blkfront_connect(struct blkfront_info *info) for_each_rinfo(info, rinfo, i) kick_pending_request_queues(rinfo); - device_add_disk(&info->xbdev->dev, info->gd, NULL); + err = device_add_disk(&info->xbdev->dev, info->gd, NULL); + if (err) { + blk_cleanup_disk(info->gd); + blk_mq_free_tag_set(&info->tag_set); + info->rq = NULL; + goto fail; + } info->is_ready = 1; return;
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. Signed-off-by: Luis Chamberlain <mcgrof@kernel.org> --- drivers/block/xen-blkfront.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)