Skip to contentSkip to conversation

target: Fix 16-bit target ports for SET TARGET PORT GROUPS emulation

PATCH Applied Roland Dreier 2 participants 2 messages Feb 24, 2012 – Feb 25, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target: Fix 16-bit target ports for SET TARGET PORT GROUPS emulation

From: Roland Dreier <[email protected]>

The old code did (MSB << 8) & 0xff, which always evaluates to 0. Just use get_unaligned_be16() so we don't have to worry about whether our open-coded version is correct or not.

---
 drivers/target/target_core_alua.c |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)
drivers/target/target_core_alua.c +3 -4
index 01a2691..c7746a3 100644
@@ -30,6 +30,7 @@
 #include <linux/export.h>
 #include <scsi/scsi.h>
 #include <scsi/scsi_cmnd.h>
+#include <asm/unaligned.h>
 
 #include <target/target_core_base.h>
 #include <target/target_core_backend.h>
@@ -267,8 +268,7 @@ int target_emulate_set_target_port_groups(struct se_task *task)
 		 * changed.
 		 */
 		if (primary) {
-			tg_pt_id = ((ptr[2] << 8) & 0xff);
-			tg_pt_id |= (ptr[3] & 0xff);
+			tg_pt_id = get_unaligned_be16(ptr + 2);
 			/*
 			 * Locate the matching target port group ID from
 			 * the global tg_pt_gp list
@@ -312,8 +312,7 @@ int target_emulate_set_target_port_groups(struct se_task *task)
 			 * the Target Port in question for the the incoming
 			 * SET_TARGET_PORT_GROUPS op.
 			 */
-			rtpi = ((ptr[2] << 8) & 0xff);
-			rtpi |= (ptr[3] & 0xff);
+			rtpi = get_unaligned_be16(ptr + 2);
 			/*
 			 * Locate the matching relative target port identifer
 			 * for the struct se_device storage object.
Signature · 1 line
1.7.9
#1 lore raw
Quoted 34 lines · Roland Dreier

From: Roland Dreier <[email protected]>

The old code did (MSB << 8) & 0xff, which always evaluates to 0. Just use get_unaligned_be16() so we don't have to worry about whether our open-coded version is correct or not.

---
 drivers/target/target_core_alua.c |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)
drivers/target/target_core_alua.c +2 -2
index 01a2691..c7746a3 100644
@@ -30,6 +30,7 @@
 #include <linux/export.h>
 #include <scsi/scsi.h>
 #include <scsi/scsi_cmnd.h>
+#include <asm/unaligned.h>
 
 #include <target/target_core_base.h>
 #include <target/target_core_backend.h>
@@ -267,8 +268,7 @@ int target_emulate_set_target_port_groups(struct se_task *task)
 		 * changed.
 		 */
 		if (primary) {
-			tg_pt_id = ((ptr[2] << 8) & 0xff);
-			tg_pt_id |= (ptr[3] & 0xff);
+			tg_pt_id = get_unaligned_be16(ptr + 2);
 			/*
 			 * Locate the matching target port group ID from
 			 * the global tg_pt_gp list

drivers/target/target_core_alua.c int target_emulate_set_target_port_groups(struct se_task *task) · line 318

Quoted 9 lines
drivers/target/target_core_alua.c +1 -2
@@ -312,8 +312,7 @@ int target_emulate_set_target_port_groups(struct se_task *task)
 			 * the Target Port in question for the the incoming
 			 * SET_TARGET_PORT_GROUPS op.
 			 */
-			rtpi = ((ptr[2] << 8) & 0xff);
-			rtpi |= (ptr[3] & 0xff);
+			rtpi = get_unaligned_be16(ptr + 2);
 			/*
 			 * Locate the matching relative target port identifer
 			 * for the struct se_device storage object.

Applied. Thanks Roland!

--nab