zbd: return ENOMEM if zone buffer allocation fails
authorDmitry Fomichev <dmitry.fomichev@wdc.com>
Wed, 27 Jan 2021 04:19:08 +0000 (13:19 +0900)
committerJens Axboe <axboe@kernel.dk>
Fri, 29 Jan 2021 15:14:00 +0000 (08:14 -0700)
parse_zone_info() function tries to allocate a buffer of
ZBD_REPORT_MAX_ZONES zone descriptors and exits if this allocation
fails. The problem is that it returns 0 error code in this case and
the caller may interpret this as the success.

Just return ENOMEM if we can't allocate that buffer.

Signed-off-by: Dmitry Fomichev <dmitry.fomichev@wdc.com>
Reviewed-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
zbd.c

diff --git a/zbd.c b/zbd.c
index f2599bd4871cd97e7028654d04083fd5eba64d90..46992746fc2c437e6da7a9b063e850fcecc4292b 100644 (file)
--- a/zbd.c
+++ b/zbd.c
@@ -443,7 +443,7 @@ static int parse_zone_info(struct thread_data *td, struct fio_file *f)
        struct fio_zone_info *p;
        uint64_t zone_size, offset;
        struct zoned_block_device_info *zbd_info = NULL;
-       int i, j, ret = 0;
+       int i, j, ret = -ENOMEM;
 
        zones = calloc(ZBD_REPORT_MAX_ZONES, sizeof(struct zbd_zone));
        if (!zones)
@@ -475,7 +475,6 @@ static int parse_zone_info(struct thread_data *td, struct fio_file *f)
 
        zbd_info = scalloc(1, sizeof(*zbd_info) +
                           (nr_zones + 1) * sizeof(zbd_info->zone_info[0]));
-       ret = -ENOMEM;
        if (!zbd_info)
                goto out;
        mutex_init_pshared(&zbd_info->mutex);