diff options
-rw-r--r-- | drivers/target/target_core_spc.c | 35 | ||||
-rw-r--r-- | include/target/target_core_base.h | 1 |
2 files changed, 19 insertions, 17 deletions
diff --git a/drivers/target/target_core_spc.c b/drivers/target/target_core_spc.c index 4c861de538c..388a922c8f6 100644 --- a/drivers/target/target_core_spc.c +++ b/drivers/target/target_core_spc.c | |||
@@ -877,9 +877,11 @@ static int spc_emulate_modesense(struct se_cmd *cmd) | |||
877 | static int spc_emulate_request_sense(struct se_cmd *cmd) | 877 | static int spc_emulate_request_sense(struct se_cmd *cmd) |
878 | { | 878 | { |
879 | unsigned char *cdb = cmd->t_task_cdb; | 879 | unsigned char *cdb = cmd->t_task_cdb; |
880 | unsigned char *buf; | 880 | unsigned char *rbuf; |
881 | u8 ua_asc = 0, ua_ascq = 0; | 881 | u8 ua_asc = 0, ua_ascq = 0; |
882 | int err = 0; | 882 | unsigned char buf[SE_SENSE_BUF]; |
883 | |||
884 | memset(buf, 0, SE_SENSE_BUF); | ||
883 | 885 | ||
884 | if (cdb[1] & 0x01) { | 886 | if (cdb[1] & 0x01) { |
885 | pr_err("REQUEST_SENSE description emulation not" | 887 | pr_err("REQUEST_SENSE description emulation not" |
@@ -888,20 +890,21 @@ static int spc_emulate_request_sense(struct se_cmd *cmd) | |||
888 | return -ENOSYS; | 890 | return -ENOSYS; |
889 | } | 891 | } |
890 | 892 | ||
891 | buf = transport_kmap_data_sg(cmd); | 893 | rbuf = transport_kmap_data_sg(cmd); |
892 | 894 | if (cmd->scsi_sense_reason != 0) { | |
893 | if (!core_scsi3_ua_clear_for_request_sense(cmd, &ua_asc, &ua_ascq)) { | 895 | /* |
896 | * Out of memory. We will fail with CHECK CONDITION, so | ||
897 | * we must not clear the unit attention condition. | ||
898 | */ | ||
899 | target_complete_cmd(cmd, CHECK_CONDITION); | ||
900 | return 0; | ||
901 | } else if (!core_scsi3_ua_clear_for_request_sense(cmd, &ua_asc, &ua_ascq)) { | ||
894 | /* | 902 | /* |
895 | * CURRENT ERROR, UNIT ATTENTION | 903 | * CURRENT ERROR, UNIT ATTENTION |
896 | */ | 904 | */ |
897 | buf[0] = 0x70; | 905 | buf[0] = 0x70; |
898 | buf[SPC_SENSE_KEY_OFFSET] = UNIT_ATTENTION; | 906 | buf[SPC_SENSE_KEY_OFFSET] = UNIT_ATTENTION; |
899 | 907 | ||
900 | if (cmd->data_length < 18) { | ||
901 | buf[7] = 0x00; | ||
902 | err = -EINVAL; | ||
903 | goto end; | ||
904 | } | ||
905 | /* | 908 | /* |
906 | * The Additional Sense Code (ASC) from the UNIT ATTENTION | 909 | * The Additional Sense Code (ASC) from the UNIT ATTENTION |
907 | */ | 910 | */ |
@@ -915,11 +918,6 @@ static int spc_emulate_request_sense(struct se_cmd *cmd) | |||
915 | buf[0] = 0x70; | 918 | buf[0] = 0x70; |
916 | buf[SPC_SENSE_KEY_OFFSET] = NO_SENSE; | 919 | buf[SPC_SENSE_KEY_OFFSET] = NO_SENSE; |
917 | 920 | ||
918 | if (cmd->data_length < 18) { | ||
919 | buf[7] = 0x00; | ||
920 | err = -EINVAL; | ||
921 | goto end; | ||
922 | } | ||
923 | /* | 921 | /* |
924 | * NO ADDITIONAL SENSE INFORMATION | 922 | * NO ADDITIONAL SENSE INFORMATION |
925 | */ | 923 | */ |
@@ -927,8 +925,11 @@ static int spc_emulate_request_sense(struct se_cmd *cmd) | |||
927 | buf[7] = 0x0A; | 925 | buf[7] = 0x0A; |
928 | } | 926 | } |
929 | 927 | ||
930 | end: | 928 | if (rbuf) { |
931 | transport_kunmap_data_sg(cmd); | 929 | memcpy(rbuf, buf, min_t(u32, sizeof(buf), cmd->data_length)); |
930 | transport_kunmap_data_sg(cmd); | ||
931 | } | ||
932 | |||
932 | target_complete_cmd(cmd, GOOD); | 933 | target_complete_cmd(cmd, GOOD); |
933 | return 0; | 934 | return 0; |
934 | } | 935 | } |
diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h index 015cea01ae3..5be89373cea 100644 --- a/include/target/target_core_base.h +++ b/include/target/target_core_base.h | |||
@@ -121,6 +121,7 @@ | |||
121 | 121 | ||
122 | #define SE_INQUIRY_BUF 512 | 122 | #define SE_INQUIRY_BUF 512 |
123 | #define SE_MODE_PAGE_BUF 512 | 123 | #define SE_MODE_PAGE_BUF 512 |
124 | #define SE_SENSE_BUF 96 | ||
124 | 125 | ||
125 | /* struct se_hba->hba_flags */ | 126 | /* struct se_hba->hba_flags */ |
126 | enum hba_flags_table { | 127 | enum hba_flags_table { |