Skip to content

Commit

Permalink
target_core: simplify scsi_name_len calculation
Browse files Browse the repository at this point in the history
scsi_name_len in spc_emulate_evpd_83 is calculated twice, with
the results of the first calculation discarded. So remove it.
And check for the maximum allowed length, too.

Signed-off-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
  • Loading branch information
Hannes Reinecke authored and Nicholas Bellinger committed Dec 17, 2013
1 parent 9c6e164 commit 03ba84c
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions drivers/target/target_core_spc.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,16 +365,6 @@ spc_emulate_evpd_83(struct se_cmd *cmd, unsigned char *buf)
* section 7.5.1 Table 362
*/
check_scsi_name:
scsi_name_len = strlen(tpg->se_tpg_tfo->tpg_get_wwn(tpg));
/* UTF-8 ",t,0x<16-bit TPGT>" + NULL Terminator */
scsi_name_len += 10;
/* Check for 4-byte padding */
padding = ((-scsi_name_len) & 3);
if (padding != 0)
scsi_name_len += padding;
/* Header size + Designation descriptor */
scsi_name_len += 4;

buf[off] =
(tpg->se_tpg_tfo->get_fabric_proto_ident(tpg) << 4);
buf[off++] |= 0x3; /* CODE SET == UTF-8 */
Expand Down Expand Up @@ -402,8 +392,11 @@ spc_emulate_evpd_83(struct se_cmd *cmd, unsigned char *buf)
* shall be no larger than 256 and shall be a multiple
* of four.
*/
padding = ((-scsi_name_len) & 3);
if (padding)
scsi_name_len += padding;
if (scsi_name_len > 256)
scsi_name_len = 256;

buf[off-1] = scsi_name_len;
off += scsi_name_len;
Expand Down

0 comments on commit 03ba84c

Please sign in to comment.