]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nvme-status: return negative status if !errno
authorMinwoo Im <minwoo.im.dev@gmail.com>
Fri, 22 Jan 2021 15:20:38 +0000 (00:20 +0900)
committerKeith Busch <kbusch@kernel.org>
Tue, 26 Jan 2021 21:21:47 +0000 (14:21 -0700)
'errno' is set to errno value when system calls are returning with an
error (e.g., ioctl).  But, If a command fails without any system call,
then it needs to return the raw negative error value.

For example, if we don't provide any options for connect command:

root@vm:~# nvme connect
need a transport (-t) argument
root@vm:~# echo $?
0

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

index 7821de2df2888d0108793d6ac8ac04e10b06ff1b..149e6f2b4fc2623e48a010ae58001f9565f865e6 100644 (file)
@@ -141,8 +141,11 @@ __u8 nvme_status_to_errno(int status, bool fabrics)
        if (!status)
                return 0;
 
-       if (status < 0)
-               return errno;
+       if (status < 0) {
+               if (errno)
+                       return errno;
+               return status;
+       }
 
        /*
         * The actual status code is enough with masking 0xff, but we need to