From ad589c81e678bd4135f580adf9875cd4ca5e08b1 Mon Sep 17 00:00:00 2001 From: Gollu Appalanaidu Date: Tue, 18 May 2021 09:55:55 +0530 Subject: [PATCH] zns: fix get_zdes_bytes return value in failed cases get_zdes_bytes shall return constant value in failed cases in order to catch in called function Check if the get_zdes_bytes returned proper data length or not. Signed-off-by: Gollu Appalanaidu --- plugins/zns/zns.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/zns/zns.c b/plugins/zns/zns.c index f83f6fa3..5c5ed92a 100644 --- a/plugins/zns/zns.c +++ b/plugins/zns/zns.c @@ -208,19 +208,19 @@ static int get_zdes_bytes(int fd, __u32 nsid) err = nvme_identify_ns(fd, nsid, false, &id_ns); if (err > 0) { nvme_show_status(err); - return err; + return -1; } else if (err < 0) { perror("identify namespace"); - return err; + return -1; } err = nvme_zns_identify_ns(fd, nsid, &ns); if (err > 0) { nvme_show_status(err); - return err; + return -1; } else if (err < 0) { perror("zns identify namespace"); - return err; + return -1; } lbaf = id_ns.flbas & NVME_NS_FLBAS_LBA_MASK; @@ -281,9 +281,9 @@ static int zone_mgmt_send(int argc, char **argv, struct command *cmd, struct plu if (cfg.zsa == NVME_ZNS_ZSA_SET_DESC_EXT) { if(!cfg.data_len) { cfg.data_len = get_zdes_bytes(fd, cfg.namespace_id); - if (cfg.data_len == 0) { + if (!cfg.data_len || cfg.data_len < 0) { fprintf(stderr, - "Zone Descriptor Extensions are not supported\n"); + "Zone Descriptor Extensions are not supported\n"); goto close_fd; } else if (cfg.data_len < 0) { err = cfg.data_len; @@ -414,7 +414,7 @@ static int set_zone_desc(int argc, char **argv, struct command *cmd, struct plug data_len = get_zdes_bytes(fd, cfg.namespace_id); - if (!data_len) { + if (!data_len || data_len < 0) { fprintf(stderr, "zone format does not provide descriptor extention\n"); errno = EINVAL; -- 2.50.1