Skip to content

Commit

Permalink
block: Simplify qmp_block_resize() error paths
Browse files Browse the repository at this point in the history
The only thing that happens after the 'out:' label is blk_unref(blk).
However, blk = NULL in all of the error cases, so instead of jumping to
'out:', we can just return directly.

Cc: qemu-stable@nongnu.org
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20201203172311.68232-2-kwolf@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
  • Loading branch information
kevmw committed Dec 11, 2020
1 parent 8b11700 commit d9dbf25
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions blockdev.c
Expand Up @@ -2454,7 +2454,7 @@ void coroutine_fn qmp_block_resize(bool has_device, const char *device,
int64_t size, Error **errp)
{
Error *local_err = NULL;
BlockBackend *blk = NULL;
BlockBackend *blk;
BlockDriverState *bs;
AioContext *old_ctx;

Expand All @@ -2468,17 +2468,17 @@ void coroutine_fn qmp_block_resize(bool has_device, const char *device,

if (size < 0) {
error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "size", "a >0 size");
goto out;
return;
}

if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_RESIZE, NULL)) {
error_setg(errp, QERR_DEVICE_IN_USE, device);
goto out;
return;
}

blk = blk_new_with_bs(bs, BLK_PERM_RESIZE, BLK_PERM_ALL, errp);
if (!blk) {
goto out;
return;
}

bdrv_drained_begin(bs);
Expand All @@ -2487,7 +2487,6 @@ void coroutine_fn qmp_block_resize(bool has_device, const char *device,
bdrv_co_leave(bs, old_ctx);
bdrv_drained_end(bs);

out:
bdrv_co_lock(bs);
blk_unref(blk);
bdrv_co_unlock(bs);
Expand Down

0 comments on commit d9dbf25

Please sign in to comment.