]> www.infradead.org Git - users/hch/nvme-cli.git/commitdiff
Warn on admin-passthru opcode not matching read/write flag
authorKelly Ursenbach <kelly.ursenbach@eideticom.com>
Wed, 4 Dec 2019 19:45:39 +0000 (12:45 -0700)
committerKeith Busch <kbusch@kernel.org>
Wed, 4 Dec 2019 20:16:11 +0000 (13:16 -0700)
Opcode bits 1:0 indicate the direction of data transfer. These
bits should agree with the read or write flags provided.

Signed-off-by: Kelly Ursenbach <kelly.ursenbach@eideticom.com>
nvme.c

diff --git a/nvme.c b/nvme.c
index f81549405c9cc8dbbacf0dd6c678054aac91f374..0c23eee8a477165fb172c6fabc8cc33a09eea150 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -4645,6 +4645,14 @@ static int passthru(int argc, char **argv, int ioctl_cmd, const char *desc, stru
                        goto free_metadata;
                }
 
+               if (cfg.write && !(cfg.opcode & 0x01)) {
+                       fprintf(stderr, "warning: write flag set but write direction bit is not set in the opcode\n");
+               }
+
+               if (cfg.read && !(cfg.opcode & 0x02)) {
+                       fprintf(stderr, "warning: read flag set but read direction bit is not set in the opcode\n");
+               }
+
                memset(data, cfg.prefill, cfg.data_len);
                if (!cfg.read && !cfg.write) {
                        fprintf(stderr, "data direction not given\n");