parallels: return earlier from parallels_open() function on error

At the beginning of the function we can return immediately until we
really allocate s->header.

Signed-off-by: Denis V. Lunev <den@openvz.org>
Reviewed-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
This commit is contained in:
Denis V. Lunev 2023-09-18 20:00:44 +02:00
parent 9c39878136
commit e17b9d08d9
1 changed files with 5 additions and 9 deletions

View File

@ -1090,7 +1090,7 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags,
ret = bdrv_pread(bs->file, 0, sizeof(ph), &ph, 0); ret = bdrv_pread(bs->file, 0, sizeof(ph), &ph, 0);
if (ret < 0) { if (ret < 0) {
goto fail; return ret;
} }
bs->total_sectors = le64_to_cpu(ph.nb_sectors); bs->total_sectors = le64_to_cpu(ph.nb_sectors);
@ -1110,13 +1110,11 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags,
s->tracks = le32_to_cpu(ph.tracks); s->tracks = le32_to_cpu(ph.tracks);
if (s->tracks == 0) { if (s->tracks == 0) {
error_setg(errp, "Invalid image: Zero sectors per track"); error_setg(errp, "Invalid image: Zero sectors per track");
ret = -EINVAL; return -EINVAL;
goto fail;
} }
if (s->tracks > INT32_MAX/513) { if (s->tracks > INT32_MAX/513) {
error_setg(errp, "Invalid image: Too big cluster"); error_setg(errp, "Invalid image: Too big cluster");
ret = -EFBIG; return -EFBIG;
goto fail;
} }
s->prealloc_size = MAX(s->tracks, s->prealloc_size); s->prealloc_size = MAX(s->tracks, s->prealloc_size);
s->cluster_size = s->tracks << BDRV_SECTOR_BITS; s->cluster_size = s->tracks << BDRV_SECTOR_BITS;
@ -1124,16 +1122,14 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags,
s->bat_size = le32_to_cpu(ph.bat_entries); s->bat_size = le32_to_cpu(ph.bat_entries);
if (s->bat_size > INT_MAX / sizeof(uint32_t)) { if (s->bat_size > INT_MAX / sizeof(uint32_t)) {
error_setg(errp, "Catalog too large"); error_setg(errp, "Catalog too large");
ret = -EFBIG; return -EFBIG;
goto fail;
} }
size = bat_entry_off(s->bat_size); size = bat_entry_off(s->bat_size);
s->header_size = ROUND_UP(size, bdrv_opt_mem_align(bs->file->bs)); s->header_size = ROUND_UP(size, bdrv_opt_mem_align(bs->file->bs));
s->header = qemu_try_blockalign(bs->file->bs, s->header_size); s->header = qemu_try_blockalign(bs->file->bs, s->header_size);
if (s->header == NULL) { if (s->header == NULL) {
ret = -ENOMEM; return -ENOMEM;
goto fail;
} }
ret = bdrv_pread(bs->file, 0, s->header_size, s->header, 0); ret = bdrv_pread(bs->file, 0, s->header_size, s->header, 0);