]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nvme-cli: add error handling for a failure of malloc
authorMinwoo Im <minwoo.im.dev@gmail.com>
Wed, 17 Jan 2018 10:24:19 +0000 (19:24 +0900)
committerMinwoo Im <minwoo.im.dev@gmail.com>
Wed, 17 Jan 2018 10:24:19 +0000 (19:24 +0900)
Make it return ENOMEM when malloc of metadat is failed with some error
message.

Signed-off-by: Minwoo Im <minwoo.im.dev@gmail.com>
nvme.c

diff --git a/nvme.c b/nvme.c
index a6f0639ded1eac962bbdc3f09681ac9b0ee0a149..6563cfd224e16592ebe4e84cd7608f34a64d2253 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -3650,8 +3650,13 @@ static int passthru(int argc, char **argv, int ioctl_cmd, const char *desc, stru
                }
        }
 
-       if (cfg.metadata_len)
+       if (cfg.metadata_len) {
                metadata = malloc(cfg.metadata_len);
+               if (!metadata) {
+                       fprintf(stderr, "can not allocate metadata payload\n");
+                       return ENOMEM;
+               }
+       }
        if (cfg.data_len) {
                if (posix_memalign(&data, getpagesize(), cfg.data_len)) {
                        fprintf(stderr, "can not allocate data payload\n");