Commit 31f9690e authored by Jan Kara's avatar Jan Kara Committed by Jens Axboe

null_blk: Cleanup error recovery in null_add_dev()

When creation of queues fails in init_driver_queues(), we free the
queues. But null_add_dev() doesn't test for this failure and continues
with the setup leading to strange consequences, likely oops. Fix the
problem by testing whether init_driver_queues() failed and do proper
error cleanup.

Coverity-id: 1148005
Signed-off-by: default avatarJan Kara <jack@suse.cz>
Signed-off-by: default avatarJens Axboe <axboe@fb.com>
parent 76d8137a
...@@ -450,14 +450,10 @@ static int init_driver_queues(struct nullb *nullb) ...@@ -450,14 +450,10 @@ static int init_driver_queues(struct nullb *nullb)
ret = setup_commands(nq); ret = setup_commands(nq);
if (ret) if (ret)
goto err_queue; return ret;
nullb->nr_queues++; nullb->nr_queues++;
} }
return 0; return 0;
err_queue:
cleanup_queues(nullb);
return ret;
} }
static int null_add_dev(void) static int null_add_dev(void)
...@@ -507,7 +503,9 @@ static int null_add_dev(void) ...@@ -507,7 +503,9 @@ static int null_add_dev(void)
goto out_cleanup_queues; goto out_cleanup_queues;
} }
blk_queue_make_request(nullb->q, null_queue_bio); blk_queue_make_request(nullb->q, null_queue_bio);
init_driver_queues(nullb); rv = init_driver_queues(nullb);
if (rv)
goto out_cleanup_blk_queue;
} else { } else {
nullb->q = blk_init_queue_node(null_request_fn, &nullb->lock, home_node); nullb->q = blk_init_queue_node(null_request_fn, &nullb->lock, home_node);
if (!nullb->q) { if (!nullb->q) {
...@@ -516,7 +514,9 @@ static int null_add_dev(void) ...@@ -516,7 +514,9 @@ static int null_add_dev(void)
} }
blk_queue_prep_rq(nullb->q, null_rq_prep_fn); blk_queue_prep_rq(nullb->q, null_rq_prep_fn);
blk_queue_softirq_done(nullb->q, null_softirq_done_fn); blk_queue_softirq_done(nullb->q, null_softirq_done_fn);
init_driver_queues(nullb); rv = init_driver_queues(nullb);
if (rv)
goto out_cleanup_blk_queue;
} }
nullb->q->queuedata = nullb; nullb->q->queuedata = nullb;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment