Skip to content

Commit 03ba84c

Browse files
hreineckeNicholas Bellinger
authored andcommitted
target_core: simplify scsi_name_len calculation
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>
1 parent 9c6e164 commit 03ba84c

1 file changed

Lines changed: 3 additions & 10 deletions

File tree

‎drivers/target/target_core_spc.c‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -365,16 +365,6 @@ spc_emulate_evpd_83(struct se_cmd *cmd, unsigned char *buf)
365365
* section 7.5.1 Table 362
366366
*/
367367
check_scsi_name:
368-
scsi_name_len = strlen(tpg->se_tpg_tfo->tpg_get_wwn(tpg));
369-
/* UTF-8 ",t,0x<16-bit TPGT>" + NULL Terminator */
370-
scsi_name_len += 10;
371-
/* Check for 4-byte padding */
372-
padding = ((-scsi_name_len) & 3);
373-
if (padding != 0)
374-
scsi_name_len += padding;
375-
/* Header size + Designation descriptor */
376-
scsi_name_len += 4;
377-
378368
buf[off] =
379369
(tpg->se_tpg_tfo->get_fabric_proto_ident(tpg) << 4);
380370
buf[off++] |= 0x3; /* CODE SET == UTF-8 */
@@ -402,8 +392,11 @@ spc_emulate_evpd_83(struct se_cmd *cmd, unsigned char *buf)
402392
* shall be no larger than 256 and shall be a multiple
403393
* of four.
404394
*/
395+
padding = ((-scsi_name_len) & 3);
405396
if (padding)
406397
scsi_name_len += padding;
398+
if (scsi_name_len > 256)
399+
scsi_name_len = 256;
407400

408401
buf[off-1] = scsi_name_len;
409402
off += scsi_name_len;

0 commit comments

Comments
 (0)