target: Fix incorrect starting offset after MODE_SENSE refactoring
authorNicholas Bellinger <nab@linux-iscsi.org>
Fri, 2 Nov 2012 01:43:03 +0000 (18:43 -0700)
committerNicholas Bellinger <nab@linux-iscsi.org>
Wed, 7 Nov 2012 04:55:46 +0000 (20:55 -0800)
This patch fixes a new off-by-one bug in the hardcoded starting offset of
spc_emulate_modesense() code that causes BLOCK DESCRIPTOR to be incorrectly
written within the MEDIUM TYPE buffer area of the mode parameter header.

According to spc4r30, Section 7.5.4, BLOCK DESCRIPTOR for MODE_SENSE_10
starts at byte 3, and BLOCK_DESCRIPTOR for MODE_SENSE (6) starts at byte 2.

(roland: add MODE DATA LENGTH + MEDIUM TYPE offset comment)

Cc: Roland Dreier <roland@purestorage.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Douglas Gilbert <dgilbert@interlog.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
drivers/target/target_core_spc.c

index 33022a3f31fc0dc17bb0f143f2ddf47a7510feeb..f9c2bd02043c6e023226a16b6d4be2986453e8e3 100644 (file)
@@ -870,8 +870,11 @@ static int spc_emulate_modesense(struct se_cmd *cmd)
        } else {
                buf = map_buf;
        }
-
-       length = ten ? 2 : 1;
+       /*
+        * Skip over MODE DATA LENGTH + MEDIUM TYPE fields to byte 3 for
+        * MODE_SENSE_10 and byte 2 for MODE_SENSE (6).
+        */
+       length = ten ? 3 : 2;
 
        /* DEVICE-SPECIFIC PARAMETER */
        if ((cmd->se_lun->lun_access & TRANSPORT_LUNFLAGS_READ_ONLY) ||