aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/target/iscsi/iscsi_target_erl0.c
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@infradead.org>2012-09-26 08:00:40 -0400
committerNicholas Bellinger <nab@linux-iscsi.org>2012-10-03 17:39:22 -0400
commit50e5c87de4c244662e47b28e499ace885d62248f (patch)
tree0cd84e70a1549a8d757e6fe48a8254b6e43ab783 /drivers/target/iscsi/iscsi_target_erl0.c
parent66c7db687631247b7a3493322b9aedeef3c6c7b5 (diff)
iscsit: proper endianess conversions
Make sure all on the wire types are use as big endian and big endian only so that sparse can verify all the conversions are done right. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
Diffstat (limited to 'drivers/target/iscsi/iscsi_target_erl0.c')
-rw-r--r--drivers/target/iscsi/iscsi_target_erl0.c80
1 files changed, 44 insertions, 36 deletions
diff --git a/drivers/target/iscsi/iscsi_target_erl0.c b/drivers/target/iscsi/iscsi_target_erl0.c
index 0c37533ccbb5..8aacf611b86d 100644
--- a/drivers/target/iscsi/iscsi_target_erl0.c
+++ b/drivers/target/iscsi/iscsi_target_erl0.c
@@ -95,14 +95,15 @@ static int iscsit_dataout_within_command_recovery_check(
95 */ 95 */
96 if (conn->sess->sess_ops->DataSequenceInOrder) { 96 if (conn->sess->sess_ops->DataSequenceInOrder) {
97 if ((cmd->cmd_flags & ICF_WITHIN_COMMAND_RECOVERY) && 97 if ((cmd->cmd_flags & ICF_WITHIN_COMMAND_RECOVERY) &&
98 (cmd->write_data_done != hdr->offset)) 98 cmd->write_data_done != be32_to_cpu(hdr->offset))
99 goto dump; 99 goto dump;
100 100
101 cmd->cmd_flags &= ~ICF_WITHIN_COMMAND_RECOVERY; 101 cmd->cmd_flags &= ~ICF_WITHIN_COMMAND_RECOVERY;
102 } else { 102 } else {
103 struct iscsi_seq *seq; 103 struct iscsi_seq *seq;
104 104
105 seq = iscsit_get_seq_holder(cmd, hdr->offset, payload_length); 105 seq = iscsit_get_seq_holder(cmd, be32_to_cpu(hdr->offset),
106 payload_length);
106 if (!seq) 107 if (!seq)
107 return DATAOUT_CANNOT_RECOVER; 108 return DATAOUT_CANNOT_RECOVER;
108 /* 109 /*
@@ -111,15 +112,15 @@ static int iscsit_dataout_within_command_recovery_check(
111 cmd->seq_ptr = seq; 112 cmd->seq_ptr = seq;
112 113
113 if (conn->sess->sess_ops->DataPDUInOrder) { 114 if (conn->sess->sess_ops->DataPDUInOrder) {
114 if ((seq->status == 115 if (seq->status ==
115 DATAOUT_SEQUENCE_WITHIN_COMMAND_RECOVERY) && 116 DATAOUT_SEQUENCE_WITHIN_COMMAND_RECOVERY &&
116 ((seq->offset != hdr->offset) || 117 (seq->offset != be32_to_cpu(hdr->offset) ||
117 (seq->data_sn != hdr->datasn))) 118 seq->data_sn != be32_to_cpu(hdr->datasn)))
118 goto dump; 119 goto dump;
119 } else { 120 } else {
120 if ((seq->status == 121 if (seq->status ==
121 DATAOUT_SEQUENCE_WITHIN_COMMAND_RECOVERY) && 122 DATAOUT_SEQUENCE_WITHIN_COMMAND_RECOVERY &&
122 (seq->data_sn != hdr->datasn)) 123 seq->data_sn != be32_to_cpu(hdr->datasn))
123 goto dump; 124 goto dump;
124 } 125 }
125 126
@@ -148,12 +149,12 @@ static int iscsit_dataout_check_unsolicited_sequence(
148 u32 payload_length = ntoh24(hdr->dlength); 149 u32 payload_length = ntoh24(hdr->dlength);
149 150
150 151
151 if ((hdr->offset < cmd->seq_start_offset) || 152 if ((be32_to_cpu(hdr->offset) < cmd->seq_start_offset) ||
152 ((hdr->offset + payload_length) > cmd->seq_end_offset)) { 153 ((be32_to_cpu(hdr->offset) + payload_length) > cmd->seq_end_offset)) {
153 pr_err("Command ITT: 0x%08x with Offset: %u," 154 pr_err("Command ITT: 0x%08x with Offset: %u,"
154 " Length: %u outside of Unsolicited Sequence %u:%u while" 155 " Length: %u outside of Unsolicited Sequence %u:%u while"
155 " DataSequenceInOrder=Yes.\n", cmd->init_task_tag, 156 " DataSequenceInOrder=Yes.\n", cmd->init_task_tag,
156 hdr->offset, payload_length, cmd->seq_start_offset, 157 be32_to_cpu(hdr->offset), payload_length, cmd->seq_start_offset,
157 cmd->seq_end_offset); 158 cmd->seq_end_offset);
158 return DATAOUT_CANNOT_RECOVER; 159 return DATAOUT_CANNOT_RECOVER;
159 } 160 }
@@ -236,12 +237,12 @@ static int iscsit_dataout_check_sequence(
236 * fullfilling an Recovery R2T, it's best to just dump the 237 * fullfilling an Recovery R2T, it's best to just dump the
237 * payload here, instead of erroring out. 238 * payload here, instead of erroring out.
238 */ 239 */
239 if ((hdr->offset < cmd->seq_start_offset) || 240 if ((be32_to_cpu(hdr->offset) < cmd->seq_start_offset) ||
240 ((hdr->offset + payload_length) > cmd->seq_end_offset)) { 241 ((be32_to_cpu(hdr->offset) + payload_length) > cmd->seq_end_offset)) {
241 pr_err("Command ITT: 0x%08x with Offset: %u," 242 pr_err("Command ITT: 0x%08x with Offset: %u,"
242 " Length: %u outside of Sequence %u:%u while" 243 " Length: %u outside of Sequence %u:%u while"
243 " DataSequenceInOrder=Yes.\n", cmd->init_task_tag, 244 " DataSequenceInOrder=Yes.\n", cmd->init_task_tag,
244 hdr->offset, payload_length, cmd->seq_start_offset, 245 be32_to_cpu(hdr->offset), payload_length, cmd->seq_start_offset,
245 cmd->seq_end_offset); 246 cmd->seq_end_offset);
246 247
247 if (iscsit_dump_data_payload(conn, payload_length, 1) < 0) 248 if (iscsit_dump_data_payload(conn, payload_length, 1) < 0)
@@ -251,7 +252,8 @@ static int iscsit_dataout_check_sequence(
251 252
252 next_burst_len = (cmd->next_burst_len + payload_length); 253 next_burst_len = (cmd->next_burst_len + payload_length);
253 } else { 254 } else {
254 seq = iscsit_get_seq_holder(cmd, hdr->offset, payload_length); 255 seq = iscsit_get_seq_holder(cmd, be32_to_cpu(hdr->offset),
256 payload_length);
255 if (!seq) 257 if (!seq)
256 return DATAOUT_CANNOT_RECOVER; 258 return DATAOUT_CANNOT_RECOVER;
257 /* 259 /*
@@ -366,16 +368,16 @@ static int iscsit_dataout_check_datasn(
366 data_sn = seq->data_sn; 368 data_sn = seq->data_sn;
367 } 369 }
368 370
369 if (hdr->datasn > data_sn) { 371 if (be32_to_cpu(hdr->datasn) > data_sn) {
370 pr_err("Command ITT: 0x%08x, received DataSN: 0x%08x" 372 pr_err("Command ITT: 0x%08x, received DataSN: 0x%08x"
371 " higher than expected 0x%08x.\n", cmd->init_task_tag, 373 " higher than expected 0x%08x.\n", cmd->init_task_tag,
372 hdr->datasn, data_sn); 374 be32_to_cpu(hdr->datasn), data_sn);
373 recovery = 1; 375 recovery = 1;
374 goto recover; 376 goto recover;
375 } else if (hdr->datasn < data_sn) { 377 } else if (be32_to_cpu(hdr->datasn) < data_sn) {
376 pr_err("Command ITT: 0x%08x, received DataSN: 0x%08x" 378 pr_err("Command ITT: 0x%08x, received DataSN: 0x%08x"
377 " lower than expected 0x%08x, discarding payload.\n", 379 " lower than expected 0x%08x, discarding payload.\n",
378 cmd->init_task_tag, hdr->datasn, data_sn); 380 cmd->init_task_tag, be32_to_cpu(hdr->datasn), data_sn);
379 dump = 1; 381 dump = 1;
380 goto dump; 382 goto dump;
381 } 383 }
@@ -415,26 +417,27 @@ static int iscsit_dataout_pre_datapduinorder_yes(
415 * error has occured and fail the connection. 417 * error has occured and fail the connection.
416 */ 418 */
417 if (conn->sess->sess_ops->DataSequenceInOrder) { 419 if (conn->sess->sess_ops->DataSequenceInOrder) {
418 if (hdr->offset != cmd->write_data_done) { 420 if (be32_to_cpu(hdr->offset) != cmd->write_data_done) {
419 pr_err("Command ITT: 0x%08x, received offset" 421 pr_err("Command ITT: 0x%08x, received offset"
420 " %u different than expected %u.\n", cmd->init_task_tag, 422 " %u different than expected %u.\n", cmd->init_task_tag,
421 hdr->offset, cmd->write_data_done); 423 be32_to_cpu(hdr->offset), cmd->write_data_done);
422 recovery = 1; 424 recovery = 1;
423 goto recover; 425 goto recover;
424 } 426 }
425 } else { 427 } else {
426 struct iscsi_seq *seq = cmd->seq_ptr; 428 struct iscsi_seq *seq = cmd->seq_ptr;
427 429
428 if (hdr->offset > seq->offset) { 430 if (be32_to_cpu(hdr->offset) > seq->offset) {
429 pr_err("Command ITT: 0x%08x, received offset" 431 pr_err("Command ITT: 0x%08x, received offset"
430 " %u greater than expected %u.\n", cmd->init_task_tag, 432 " %u greater than expected %u.\n", cmd->init_task_tag,
431 hdr->offset, seq->offset); 433 be32_to_cpu(hdr->offset), seq->offset);
432 recovery = 1; 434 recovery = 1;
433 goto recover; 435 goto recover;
434 } else if (hdr->offset < seq->offset) { 436 } else if (be32_to_cpu(hdr->offset) < seq->offset) {
435 pr_err("Command ITT: 0x%08x, received offset" 437 pr_err("Command ITT: 0x%08x, received offset"
436 " %u less than expected %u, discarding payload.\n", 438 " %u less than expected %u, discarding payload.\n",
437 cmd->init_task_tag, hdr->offset, seq->offset); 439 cmd->init_task_tag, be32_to_cpu(hdr->offset),
440 seq->offset);
438 dump = 1; 441 dump = 1;
439 goto dump; 442 goto dump;
440 } 443 }
@@ -453,7 +456,7 @@ dump:
453 return DATAOUT_CANNOT_RECOVER; 456 return DATAOUT_CANNOT_RECOVER;
454 457
455 return (recovery) ? iscsit_recover_dataout_sequence(cmd, 458 return (recovery) ? iscsit_recover_dataout_sequence(cmd,
456 hdr->offset, payload_length) : 459 be32_to_cpu(hdr->offset), payload_length) :
457 (dump) ? DATAOUT_WITHIN_COMMAND_RECOVERY : DATAOUT_NORMAL; 460 (dump) ? DATAOUT_WITHIN_COMMAND_RECOVERY : DATAOUT_NORMAL;
458} 461}
459 462
@@ -465,7 +468,8 @@ static int iscsit_dataout_pre_datapduinorder_no(
465 struct iscsi_data *hdr = (struct iscsi_data *) buf; 468 struct iscsi_data *hdr = (struct iscsi_data *) buf;
466 u32 payload_length = ntoh24(hdr->dlength); 469 u32 payload_length = ntoh24(hdr->dlength);
467 470
468 pdu = iscsit_get_pdu_holder(cmd, hdr->offset, payload_length); 471 pdu = iscsit_get_pdu_holder(cmd, be32_to_cpu(hdr->offset),
472 payload_length);
469 if (!pdu) 473 if (!pdu)
470 return DATAOUT_CANNOT_RECOVER; 474 return DATAOUT_CANNOT_RECOVER;
471 475
@@ -479,7 +483,7 @@ static int iscsit_dataout_pre_datapduinorder_no(
479 case ISCSI_PDU_RECEIVED_OK: 483 case ISCSI_PDU_RECEIVED_OK:
480 pr_err("Command ITT: 0x%08x received already gotten" 484 pr_err("Command ITT: 0x%08x received already gotten"
481 " Offset: %u, Length: %u\n", cmd->init_task_tag, 485 " Offset: %u, Length: %u\n", cmd->init_task_tag,
482 hdr->offset, payload_length); 486 be32_to_cpu(hdr->offset), payload_length);
483 return iscsit_dump_data_payload(cmd->conn, payload_length, 1); 487 return iscsit_dump_data_payload(cmd->conn, payload_length, 1);
484 default: 488 default:
485 return DATAOUT_CANNOT_RECOVER; 489 return DATAOUT_CANNOT_RECOVER;
@@ -553,7 +557,7 @@ static int iscsit_dataout_post_crc_passed(
553 if (cmd->unsolicited_data) { 557 if (cmd->unsolicited_data) {
554 if ((cmd->first_burst_len + payload_length) == 558 if ((cmd->first_burst_len + payload_length) ==
555 conn->sess->sess_ops->FirstBurstLength) { 559 conn->sess->sess_ops->FirstBurstLength) {
556 if (iscsit_dataout_update_r2t(cmd, hdr->offset, 560 if (iscsit_dataout_update_r2t(cmd, be32_to_cpu(hdr->offset),
557 payload_length) < 0) 561 payload_length) < 0)
558 return DATAOUT_CANNOT_RECOVER; 562 return DATAOUT_CANNOT_RECOVER;
559 send_r2t = 1; 563 send_r2t = 1;
@@ -561,7 +565,8 @@ static int iscsit_dataout_post_crc_passed(
561 565
562 if (!conn->sess->sess_ops->DataPDUInOrder) { 566 if (!conn->sess->sess_ops->DataPDUInOrder) {
563 ret = iscsit_dataout_update_datapduinorder_no(cmd, 567 ret = iscsit_dataout_update_datapduinorder_no(cmd,
564 hdr->datasn, (hdr->flags & ISCSI_FLAG_CMD_FINAL)); 568 be32_to_cpu(hdr->datasn),
569 (hdr->flags & ISCSI_FLAG_CMD_FINAL));
565 if (ret == DATAOUT_CANNOT_RECOVER) 570 if (ret == DATAOUT_CANNOT_RECOVER)
566 return ret; 571 return ret;
567 } 572 }
@@ -586,7 +591,8 @@ static int iscsit_dataout_post_crc_passed(
586 if (conn->sess->sess_ops->DataSequenceInOrder) { 591 if (conn->sess->sess_ops->DataSequenceInOrder) {
587 if ((cmd->next_burst_len + payload_length) == 592 if ((cmd->next_burst_len + payload_length) ==
588 conn->sess->sess_ops->MaxBurstLength) { 593 conn->sess->sess_ops->MaxBurstLength) {
589 if (iscsit_dataout_update_r2t(cmd, hdr->offset, 594 if (iscsit_dataout_update_r2t(cmd,
595 be32_to_cpu(hdr->offset),
590 payload_length) < 0) 596 payload_length) < 0)
591 return DATAOUT_CANNOT_RECOVER; 597 return DATAOUT_CANNOT_RECOVER;
592 send_r2t = 1; 598 send_r2t = 1;
@@ -594,7 +600,7 @@ static int iscsit_dataout_post_crc_passed(
594 600
595 if (!conn->sess->sess_ops->DataPDUInOrder) { 601 if (!conn->sess->sess_ops->DataPDUInOrder) {
596 ret = iscsit_dataout_update_datapduinorder_no( 602 ret = iscsit_dataout_update_datapduinorder_no(
597 cmd, hdr->datasn, 603 cmd, be32_to_cpu(hdr->datasn),
598 (hdr->flags & ISCSI_FLAG_CMD_FINAL)); 604 (hdr->flags & ISCSI_FLAG_CMD_FINAL));
599 if (ret == DATAOUT_CANNOT_RECOVER) 605 if (ret == DATAOUT_CANNOT_RECOVER)
600 return ret; 606 return ret;
@@ -610,7 +616,8 @@ static int iscsit_dataout_post_crc_passed(
610 616
611 if ((seq->next_burst_len + payload_length) == 617 if ((seq->next_burst_len + payload_length) ==
612 seq->xfer_len) { 618 seq->xfer_len) {
613 if (iscsit_dataout_update_r2t(cmd, hdr->offset, 619 if (iscsit_dataout_update_r2t(cmd,
620 be32_to_cpu(hdr->offset),
614 payload_length) < 0) 621 payload_length) < 0)
615 return DATAOUT_CANNOT_RECOVER; 622 return DATAOUT_CANNOT_RECOVER;
616 send_r2t = 1; 623 send_r2t = 1;
@@ -618,7 +625,7 @@ static int iscsit_dataout_post_crc_passed(
618 625
619 if (!conn->sess->sess_ops->DataPDUInOrder) { 626 if (!conn->sess->sess_ops->DataPDUInOrder) {
620 ret = iscsit_dataout_update_datapduinorder_no( 627 ret = iscsit_dataout_update_datapduinorder_no(
621 cmd, hdr->datasn, 628 cmd, be32_to_cpu(hdr->datasn),
622 (hdr->flags & ISCSI_FLAG_CMD_FINAL)); 629 (hdr->flags & ISCSI_FLAG_CMD_FINAL));
623 if (ret == DATAOUT_CANNOT_RECOVER) 630 if (ret == DATAOUT_CANNOT_RECOVER)
624 return ret; 631 return ret;
@@ -678,7 +685,8 @@ static int iscsit_dataout_post_crc_failed(
678 } 685 }
679 686
680recover: 687recover:
681 return iscsit_recover_dataout_sequence(cmd, hdr->offset, payload_length); 688 return iscsit_recover_dataout_sequence(cmd, be32_to_cpu(hdr->offset),
689 payload_length);
682} 690}
683 691
684/* 692/*