]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nvme-cli: misc. fixes for memory allocation failure case
authorGollu Appalanaidu <anaidu.gollu@samsung.com>
Thu, 25 Feb 2021 19:08:34 +0000 (00:38 +0530)
committerKeith Busch <kbusch@kernel.org>
Thu, 25 Feb 2021 20:45:14 +0000 (13:45 -0700)
Signed-off-by: Gollu Appalanaidu <anaidu.gollu@samsung.com>
fabrics.c
nvme.c
plugins/zns/zns.c

index 7846a06ac4b1ea2b2bfddc696c16ba633bcc1704..01037678ac7ce5cd7b9d6eb2372885743d09e96c 100644 (file)
--- a/fabrics.c
+++ b/fabrics.c
@@ -554,6 +554,7 @@ static int nvmf_get_log_page_discovery(const char *dev_path,
         */
        log = calloc(1, hdr_size);
        if (!log) {
+               perror("could not alloc memory for discovery log header");
                error = -ENOMEM;
                goto out_close;
        }
@@ -588,6 +589,7 @@ static int nvmf_get_log_page_discovery(const char *dev_path,
                /* allocate discovery log pages based on page_hdr->numrec */
                log = calloc(1, log_size);
                if (!log) {
+                       perror("could not alloc memory for discovery log page");
                        error = -ENOMEM;
                        goto out_close;
                }
diff --git a/nvme.c b/nvme.c
index ea5653c4cd8c00fabb440b0e7d15fff7d4b642f9..35e984d91c7f867355835895a94e75401800f91c 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -1234,7 +1234,7 @@ static int get_log(int argc, char **argv, struct command *cmd, struct plugin *pl
                if (!log) {
                        fprintf(stderr, "could not alloc buffer for log: %s\n",
                                        strerror(errno));
-                       err = -EINVAL;
+                       err = -ENOMEM;
                        goto close_fd;
                }
 
@@ -5129,6 +5129,7 @@ static int get_lba_status(int argc, char **argv, struct command *cmd,
        buf_len = (cfg.mndw + 1) * 4;
        buf = calloc(1, buf_len);
        if (!buf) {
+               perror("could not alloc memory for get lba status");
                err = -ENOMEM;
                goto close_fd;
        }
index 00c42d3e47ea267dd0a3c555cdaf178c03b3a61b..8eda0c78af14d3cc578cb920200ccfa4c7d59439 100644 (file)
@@ -429,7 +429,8 @@ static int set_zone_desc(int argc, char **argv, struct command *cmd, struct plug
 
        buf = calloc(1, data_len);
        if (!buf) {
-               err = -1;
+               perror("could not alloc memory for zone desc");
+               err = -ENOMEM;
                goto close_fd;
        }
 
@@ -524,7 +525,8 @@ static int zone_mgmt_recv(int argc, char **argv, struct command *cmd, struct plu
        if (cfg.data_len) {
                data = calloc(1, cfg.data_len);
                if (!data) {
-                       err = -1;
+                       perror("could not alloc memory for zone mgmt receive data");
+                       err = -ENOMEM;
                        goto close_fd;
                }
        }
@@ -637,7 +639,7 @@ static int report_zones(int argc, char **argv, struct command *cmd, struct plugi
        report = nvme_alloc(report_size, &huge);
        if (!report) {
                perror("alloc");
-               err = -1;
+               err = -ENOMEM;
                goto close_fd;
        }