aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/target/loopback/tcm_loop.c13
-rw-r--r--drivers/target/target_core_configfs.c24
-rw-r--r--drivers/target/target_core_device.c5
-rw-r--r--drivers/target/target_core_pr.c6
-rw-r--r--drivers/target/target_core_tmr.c8
-rw-r--r--drivers/target/target_core_transport.c6
-rw-r--r--drivers/target/tcm_fc/tcm_fc.h2
-rw-r--r--drivers/target/tcm_fc/tfc_cmd.c64
-rw-r--r--drivers/target/tcm_fc/tfc_io.c2
-rw-r--r--drivers/target/tcm_fc/tfc_sess.c4
10 files changed, 73 insertions, 61 deletions
diff --git a/drivers/target/loopback/tcm_loop.c b/drivers/target/loopback/tcm_loop.c
index dee2a2c909f5..70c2e7fa6664 100644
--- a/drivers/target/loopback/tcm_loop.c
+++ b/drivers/target/loopback/tcm_loop.c
@@ -386,7 +386,7 @@ static int tcm_loop_device_reset(struct scsi_cmnd *sc)
386 */ 386 */
387 se_cmd->se_tmr_req = core_tmr_alloc_req(se_cmd, (void *)tl_tmr, 387 se_cmd->se_tmr_req = core_tmr_alloc_req(se_cmd, (void *)tl_tmr,
388 TMR_LUN_RESET); 388 TMR_LUN_RESET);
389 if (!se_cmd->se_tmr_req) 389 if (IS_ERR(se_cmd->se_tmr_req))
390 goto release; 390 goto release;
391 /* 391 /*
392 * Locate the underlying TCM struct se_lun from sc->device->lun 392 * Locate the underlying TCM struct se_lun from sc->device->lun
@@ -1017,6 +1017,7 @@ static int tcm_loop_make_nexus(
1017 struct se_portal_group *se_tpg; 1017 struct se_portal_group *se_tpg;
1018 struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba; 1018 struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba;
1019 struct tcm_loop_nexus *tl_nexus; 1019 struct tcm_loop_nexus *tl_nexus;
1020 int ret = -ENOMEM;
1020 1021
1021 if (tl_tpg->tl_hba->tl_nexus) { 1022 if (tl_tpg->tl_hba->tl_nexus) {
1022 printk(KERN_INFO "tl_tpg->tl_hba->tl_nexus already exists\n"); 1023 printk(KERN_INFO "tl_tpg->tl_hba->tl_nexus already exists\n");
@@ -1033,8 +1034,10 @@ static int tcm_loop_make_nexus(
1033 * Initialize the struct se_session pointer 1034 * Initialize the struct se_session pointer
1034 */ 1035 */
1035 tl_nexus->se_sess = transport_init_session(); 1036 tl_nexus->se_sess = transport_init_session();
1036 if (!tl_nexus->se_sess) 1037 if (IS_ERR(tl_nexus->se_sess)) {
1038 ret = PTR_ERR(tl_nexus->se_sess);
1037 goto out; 1039 goto out;
1040 }
1038 /* 1041 /*
1039 * Since we are running in 'demo mode' this call with generate a 1042 * Since we are running in 'demo mode' this call with generate a
1040 * struct se_node_acl for the tcm_loop struct se_portal_group with the SCSI 1043 * struct se_node_acl for the tcm_loop struct se_portal_group with the SCSI
@@ -1060,7 +1063,7 @@ static int tcm_loop_make_nexus(
1060 1063
1061out: 1064out:
1062 kfree(tl_nexus); 1065 kfree(tl_nexus);
1063 return -ENOMEM; 1066 return ret;
1064} 1067}
1065 1068
1066static int tcm_loop_drop_nexus( 1069static int tcm_loop_drop_nexus(
@@ -1140,7 +1143,7 @@ static ssize_t tcm_loop_tpg_store_nexus(
1140 * the fabric protocol_id set in tcm_loop_make_scsi_hba(), and call 1143 * the fabric protocol_id set in tcm_loop_make_scsi_hba(), and call
1141 * tcm_loop_make_nexus() 1144 * tcm_loop_make_nexus()
1142 */ 1145 */
1143 if (strlen(page) > TL_WWN_ADDR_LEN) { 1146 if (strlen(page) >= TL_WWN_ADDR_LEN) {
1144 printk(KERN_ERR "Emulated NAA Sas Address: %s, exceeds" 1147 printk(KERN_ERR "Emulated NAA Sas Address: %s, exceeds"
1145 " max: %d\n", page, TL_WWN_ADDR_LEN); 1148 " max: %d\n", page, TL_WWN_ADDR_LEN);
1146 return -EINVAL; 1149 return -EINVAL;
@@ -1321,7 +1324,7 @@ struct se_wwn *tcm_loop_make_scsi_hba(
1321 return ERR_PTR(-EINVAL); 1324 return ERR_PTR(-EINVAL);
1322 1325
1323check_len: 1326check_len:
1324 if (strlen(name) > TL_WWN_ADDR_LEN) { 1327 if (strlen(name) >= TL_WWN_ADDR_LEN) {
1325 printk(KERN_ERR "Emulated NAA %s Address: %s, exceeds" 1328 printk(KERN_ERR "Emulated NAA %s Address: %s, exceeds"
1326 " max: %d\n", name, tcm_loop_dump_proto_id(tl_hba), 1329 " max: %d\n", name, tcm_loop_dump_proto_id(tl_hba),
1327 TL_WWN_ADDR_LEN); 1330 TL_WWN_ADDR_LEN);
diff --git a/drivers/target/target_core_configfs.c b/drivers/target/target_core_configfs.c
index ee6fad979b50..25c1f49a7d8b 100644
--- a/drivers/target/target_core_configfs.c
+++ b/drivers/target/target_core_configfs.c
@@ -304,7 +304,7 @@ struct target_fabric_configfs *target_fabric_configfs_init(
304 printk(KERN_ERR "Unable to locate passed fabric name\n"); 304 printk(KERN_ERR "Unable to locate passed fabric name\n");
305 return NULL; 305 return NULL;
306 } 306 }
307 if (strlen(name) > TARGET_FABRIC_NAME_SIZE) { 307 if (strlen(name) >= TARGET_FABRIC_NAME_SIZE) {
308 printk(KERN_ERR "Passed name: %s exceeds TARGET_FABRIC" 308 printk(KERN_ERR "Passed name: %s exceeds TARGET_FABRIC"
309 "_NAME_SIZE\n", name); 309 "_NAME_SIZE\n", name);
310 return NULL; 310 return NULL;
@@ -312,7 +312,7 @@ struct target_fabric_configfs *target_fabric_configfs_init(
312 312
313 tf = kzalloc(sizeof(struct target_fabric_configfs), GFP_KERNEL); 313 tf = kzalloc(sizeof(struct target_fabric_configfs), GFP_KERNEL);
314 if (!(tf)) 314 if (!(tf))
315 return ERR_PTR(-ENOMEM); 315 return NULL;
316 316
317 INIT_LIST_HEAD(&tf->tf_list); 317 INIT_LIST_HEAD(&tf->tf_list);
318 atomic_set(&tf->tf_access_cnt, 0); 318 atomic_set(&tf->tf_access_cnt, 0);
@@ -851,7 +851,7 @@ static ssize_t target_core_dev_wwn_store_attr_vpd_unit_serial(
851 return -EOPNOTSUPP; 851 return -EOPNOTSUPP;
852 } 852 }
853 853
854 if ((strlen(page) + 1) > INQUIRY_VPD_SERIAL_LEN) { 854 if (strlen(page) >= INQUIRY_VPD_SERIAL_LEN) {
855 printk(KERN_ERR "Emulated VPD Unit Serial exceeds" 855 printk(KERN_ERR "Emulated VPD Unit Serial exceeds"
856 " INQUIRY_VPD_SERIAL_LEN: %d\n", INQUIRY_VPD_SERIAL_LEN); 856 " INQUIRY_VPD_SERIAL_LEN: %d\n", INQUIRY_VPD_SERIAL_LEN);
857 return -EOVERFLOW; 857 return -EOVERFLOW;
@@ -917,7 +917,7 @@ static ssize_t target_core_dev_wwn_show_attr_vpd_protocol_identifier(
917 917
918 transport_dump_vpd_proto_id(vpd, buf, VPD_TMP_BUF_SIZE); 918 transport_dump_vpd_proto_id(vpd, buf, VPD_TMP_BUF_SIZE);
919 919
920 if ((len + strlen(buf) > PAGE_SIZE)) 920 if ((len + strlen(buf) >= PAGE_SIZE))
921 break; 921 break;
922 922
923 len += sprintf(page+len, "%s", buf); 923 len += sprintf(page+len, "%s", buf);
@@ -962,19 +962,19 @@ static ssize_t target_core_dev_wwn_show_attr_##_name( \
962 \ 962 \
963 memset(buf, 0, VPD_TMP_BUF_SIZE); \ 963 memset(buf, 0, VPD_TMP_BUF_SIZE); \
964 transport_dump_vpd_assoc(vpd, buf, VPD_TMP_BUF_SIZE); \ 964 transport_dump_vpd_assoc(vpd, buf, VPD_TMP_BUF_SIZE); \
965 if ((len + strlen(buf) > PAGE_SIZE)) \ 965 if ((len + strlen(buf) >= PAGE_SIZE)) \
966 break; \ 966 break; \
967 len += sprintf(page+len, "%s", buf); \ 967 len += sprintf(page+len, "%s", buf); \
968 \ 968 \
969 memset(buf, 0, VPD_TMP_BUF_SIZE); \ 969 memset(buf, 0, VPD_TMP_BUF_SIZE); \
970 transport_dump_vpd_ident_type(vpd, buf, VPD_TMP_BUF_SIZE); \ 970 transport_dump_vpd_ident_type(vpd, buf, VPD_TMP_BUF_SIZE); \
971 if ((len + strlen(buf) > PAGE_SIZE)) \ 971 if ((len + strlen(buf) >= PAGE_SIZE)) \
972 break; \ 972 break; \
973 len += sprintf(page+len, "%s", buf); \ 973 len += sprintf(page+len, "%s", buf); \
974 \ 974 \
975 memset(buf, 0, VPD_TMP_BUF_SIZE); \ 975 memset(buf, 0, VPD_TMP_BUF_SIZE); \
976 transport_dump_vpd_ident(vpd, buf, VPD_TMP_BUF_SIZE); \ 976 transport_dump_vpd_ident(vpd, buf, VPD_TMP_BUF_SIZE); \
977 if ((len + strlen(buf) > PAGE_SIZE)) \ 977 if ((len + strlen(buf) >= PAGE_SIZE)) \
978 break; \ 978 break; \
979 len += sprintf(page+len, "%s", buf); \ 979 len += sprintf(page+len, "%s", buf); \
980 } \ 980 } \
@@ -1299,7 +1299,7 @@ static ssize_t target_core_dev_pr_show_attr_res_pr_registered_i_pts(
1299 &i_buf[0] : "", pr_reg->pr_res_key, 1299 &i_buf[0] : "", pr_reg->pr_res_key,
1300 pr_reg->pr_res_generation); 1300 pr_reg->pr_res_generation);
1301 1301
1302 if ((len + strlen(buf) > PAGE_SIZE)) 1302 if ((len + strlen(buf) >= PAGE_SIZE))
1303 break; 1303 break;
1304 1304
1305 len += sprintf(page+len, "%s", buf); 1305 len += sprintf(page+len, "%s", buf);
@@ -1496,7 +1496,7 @@ static ssize_t target_core_dev_pr_store_attr_res_aptpl_metadata(
1496 ret = -ENOMEM; 1496 ret = -ENOMEM;
1497 goto out; 1497 goto out;
1498 } 1498 }
1499 if (strlen(i_port) > PR_APTPL_MAX_IPORT_LEN) { 1499 if (strlen(i_port) >= PR_APTPL_MAX_IPORT_LEN) {
1500 printk(KERN_ERR "APTPL metadata initiator_node=" 1500 printk(KERN_ERR "APTPL metadata initiator_node="
1501 " exceeds PR_APTPL_MAX_IPORT_LEN: %d\n", 1501 " exceeds PR_APTPL_MAX_IPORT_LEN: %d\n",
1502 PR_APTPL_MAX_IPORT_LEN); 1502 PR_APTPL_MAX_IPORT_LEN);
@@ -1510,7 +1510,7 @@ static ssize_t target_core_dev_pr_store_attr_res_aptpl_metadata(
1510 ret = -ENOMEM; 1510 ret = -ENOMEM;
1511 goto out; 1511 goto out;
1512 } 1512 }
1513 if (strlen(isid) > PR_REG_ISID_LEN) { 1513 if (strlen(isid) >= PR_REG_ISID_LEN) {
1514 printk(KERN_ERR "APTPL metadata initiator_isid" 1514 printk(KERN_ERR "APTPL metadata initiator_isid"
1515 "= exceeds PR_REG_ISID_LEN: %d\n", 1515 "= exceeds PR_REG_ISID_LEN: %d\n",
1516 PR_REG_ISID_LEN); 1516 PR_REG_ISID_LEN);
@@ -1571,7 +1571,7 @@ static ssize_t target_core_dev_pr_store_attr_res_aptpl_metadata(
1571 ret = -ENOMEM; 1571 ret = -ENOMEM;
1572 goto out; 1572 goto out;
1573 } 1573 }
1574 if (strlen(t_port) > PR_APTPL_MAX_TPORT_LEN) { 1574 if (strlen(t_port) >= PR_APTPL_MAX_TPORT_LEN) {
1575 printk(KERN_ERR "APTPL metadata target_node=" 1575 printk(KERN_ERR "APTPL metadata target_node="
1576 " exceeds PR_APTPL_MAX_TPORT_LEN: %d\n", 1576 " exceeds PR_APTPL_MAX_TPORT_LEN: %d\n",
1577 PR_APTPL_MAX_TPORT_LEN); 1577 PR_APTPL_MAX_TPORT_LEN);
@@ -3052,7 +3052,7 @@ static struct config_group *target_core_call_addhbatotarget(
3052 int ret; 3052 int ret;
3053 3053
3054 memset(buf, 0, TARGET_CORE_NAME_MAX_LEN); 3054 memset(buf, 0, TARGET_CORE_NAME_MAX_LEN);
3055 if (strlen(name) > TARGET_CORE_NAME_MAX_LEN) { 3055 if (strlen(name) >= TARGET_CORE_NAME_MAX_LEN) {
3056 printk(KERN_ERR "Passed *name strlen(): %d exceeds" 3056 printk(KERN_ERR "Passed *name strlen(): %d exceeds"
3057 " TARGET_CORE_NAME_MAX_LEN: %d\n", (int)strlen(name), 3057 " TARGET_CORE_NAME_MAX_LEN: %d\n", (int)strlen(name),
3058 TARGET_CORE_NAME_MAX_LEN); 3058 TARGET_CORE_NAME_MAX_LEN);
diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
index 8407f9ca2b31..ba698ea62bb2 100644
--- a/drivers/target/target_core_device.c
+++ b/drivers/target/target_core_device.c
@@ -192,7 +192,7 @@ int transport_get_lun_for_tmr(
192 &SE_NODE_ACL(se_sess)->device_list[unpacked_lun]; 192 &SE_NODE_ACL(se_sess)->device_list[unpacked_lun];
193 if (deve->lun_flags & TRANSPORT_LUNFLAGS_INITIATOR_ACCESS) { 193 if (deve->lun_flags & TRANSPORT_LUNFLAGS_INITIATOR_ACCESS) {
194 se_lun = se_cmd->se_lun = se_tmr->tmr_lun = deve->se_lun; 194 se_lun = se_cmd->se_lun = se_tmr->tmr_lun = deve->se_lun;
195 dev = se_tmr->tmr_dev = se_lun->lun_se_dev; 195 dev = se_lun->lun_se_dev;
196 se_cmd->pr_res_key = deve->pr_res_key; 196 se_cmd->pr_res_key = deve->pr_res_key;
197 se_cmd->orig_fe_lun = unpacked_lun; 197 se_cmd->orig_fe_lun = unpacked_lun;
198 se_cmd->se_orig_obj_ptr = SE_LUN(se_cmd)->lun_se_dev; 198 se_cmd->se_orig_obj_ptr = SE_LUN(se_cmd)->lun_se_dev;
@@ -216,6 +216,7 @@ int transport_get_lun_for_tmr(
216 se_cmd->se_cmd_flags |= SCF_SCSI_CDB_EXCEPTION; 216 se_cmd->se_cmd_flags |= SCF_SCSI_CDB_EXCEPTION;
217 return -1; 217 return -1;
218 } 218 }
219 se_tmr->tmr_dev = dev;
219 220
220 spin_lock(&dev->se_tmr_lock); 221 spin_lock(&dev->se_tmr_lock);
221 list_add_tail(&se_tmr->tmr_list, &dev->dev_tmr_list); 222 list_add_tail(&se_tmr->tmr_list, &dev->dev_tmr_list);
@@ -1430,7 +1431,7 @@ struct se_lun_acl *core_dev_init_initiator_node_lun_acl(
1430 struct se_lun_acl *lacl; 1431 struct se_lun_acl *lacl;
1431 struct se_node_acl *nacl; 1432 struct se_node_acl *nacl;
1432 1433
1433 if (strlen(initiatorname) > TRANSPORT_IQN_LEN) { 1434 if (strlen(initiatorname) >= TRANSPORT_IQN_LEN) {
1434 printk(KERN_ERR "%s InitiatorName exceeds maximum size.\n", 1435 printk(KERN_ERR "%s InitiatorName exceeds maximum size.\n",
1435 TPG_TFO(tpg)->get_fabric_name()); 1436 TPG_TFO(tpg)->get_fabric_name());
1436 *ret = -EOVERFLOW; 1437 *ret = -EOVERFLOW;
diff --git a/drivers/target/target_core_pr.c b/drivers/target/target_core_pr.c
index a79f518ca6e2..b662db3a320b 100644
--- a/drivers/target/target_core_pr.c
+++ b/drivers/target/target_core_pr.c
@@ -1916,7 +1916,7 @@ static int __core_scsi3_update_aptpl_buf(
1916 pr_reg->pr_res_mapped_lun); 1916 pr_reg->pr_res_mapped_lun);
1917 } 1917 }
1918 1918
1919 if ((len + strlen(tmp) > pr_aptpl_buf_len)) { 1919 if ((len + strlen(tmp) >= pr_aptpl_buf_len)) {
1920 printk(KERN_ERR "Unable to update renaming" 1920 printk(KERN_ERR "Unable to update renaming"
1921 " APTPL metadata\n"); 1921 " APTPL metadata\n");
1922 spin_unlock(&T10_RES(su_dev)->registration_lock); 1922 spin_unlock(&T10_RES(su_dev)->registration_lock);
@@ -1934,7 +1934,7 @@ static int __core_scsi3_update_aptpl_buf(
1934 TPG_TFO(tpg)->tpg_get_tag(tpg), 1934 TPG_TFO(tpg)->tpg_get_tag(tpg),
1935 lun->lun_sep->sep_rtpi, lun->unpacked_lun, reg_count); 1935 lun->lun_sep->sep_rtpi, lun->unpacked_lun, reg_count);
1936 1936
1937 if ((len + strlen(tmp) > pr_aptpl_buf_len)) { 1937 if ((len + strlen(tmp) >= pr_aptpl_buf_len)) {
1938 printk(KERN_ERR "Unable to update renaming" 1938 printk(KERN_ERR "Unable to update renaming"
1939 " APTPL metadata\n"); 1939 " APTPL metadata\n");
1940 spin_unlock(&T10_RES(su_dev)->registration_lock); 1940 spin_unlock(&T10_RES(su_dev)->registration_lock);
@@ -1986,7 +1986,7 @@ static int __core_scsi3_write_aptpl_to_file(
1986 memset(iov, 0, sizeof(struct iovec)); 1986 memset(iov, 0, sizeof(struct iovec));
1987 memset(path, 0, 512); 1987 memset(path, 0, 512);
1988 1988
1989 if (strlen(&wwn->unit_serial[0]) > 512) { 1989 if (strlen(&wwn->unit_serial[0]) >= 512) {
1990 printk(KERN_ERR "WWN value for struct se_device does not fit" 1990 printk(KERN_ERR "WWN value for struct se_device does not fit"
1991 " into path buffer\n"); 1991 " into path buffer\n");
1992 return -1; 1992 return -1;
diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c
index 59b8b9c5ad72..179063d81cdd 100644
--- a/drivers/target/target_core_tmr.c
+++ b/drivers/target/target_core_tmr.c
@@ -75,10 +75,16 @@ void core_tmr_release_req(
75{ 75{
76 struct se_device *dev = tmr->tmr_dev; 76 struct se_device *dev = tmr->tmr_dev;
77 77
78 if (!dev) {
79 kmem_cache_free(se_tmr_req_cache, tmr);
80 return;
81 }
82
78 spin_lock(&dev->se_tmr_lock); 83 spin_lock(&dev->se_tmr_lock);
79 list_del(&tmr->tmr_list); 84 list_del(&tmr->tmr_list);
80 kmem_cache_free(se_tmr_req_cache, tmr);
81 spin_unlock(&dev->se_tmr_lock); 85 spin_unlock(&dev->se_tmr_lock);
86
87 kmem_cache_free(se_tmr_req_cache, tmr);
82} 88}
83 89
84static void core_tmr_handle_tas_abort( 90static void core_tmr_handle_tas_abort(
diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
index 4dafeb8b5638..4b9b7169bdd9 100644
--- a/drivers/target/target_core_transport.c
+++ b/drivers/target/target_core_transport.c
@@ -536,13 +536,13 @@ EXPORT_SYMBOL(transport_register_session);
536void transport_deregister_session_configfs(struct se_session *se_sess) 536void transport_deregister_session_configfs(struct se_session *se_sess)
537{ 537{
538 struct se_node_acl *se_nacl; 538 struct se_node_acl *se_nacl;
539 539 unsigned long flags;
540 /* 540 /*
541 * Used by struct se_node_acl's under ConfigFS to locate active struct se_session 541 * Used by struct se_node_acl's under ConfigFS to locate active struct se_session
542 */ 542 */
543 se_nacl = se_sess->se_node_acl; 543 se_nacl = se_sess->se_node_acl;
544 if ((se_nacl)) { 544 if ((se_nacl)) {
545 spin_lock_irq(&se_nacl->nacl_sess_lock); 545 spin_lock_irqsave(&se_nacl->nacl_sess_lock, flags);
546 list_del(&se_sess->sess_acl_list); 546 list_del(&se_sess->sess_acl_list);
547 /* 547 /*
548 * If the session list is empty, then clear the pointer. 548 * If the session list is empty, then clear the pointer.
@@ -556,7 +556,7 @@ void transport_deregister_session_configfs(struct se_session *se_sess)
556 se_nacl->acl_sess_list.prev, 556 se_nacl->acl_sess_list.prev,
557 struct se_session, sess_acl_list); 557 struct se_session, sess_acl_list);
558 } 558 }
559 spin_unlock_irq(&se_nacl->nacl_sess_lock); 559 spin_unlock_irqrestore(&se_nacl->nacl_sess_lock, flags);
560 } 560 }
561} 561}
562EXPORT_SYMBOL(transport_deregister_session_configfs); 562EXPORT_SYMBOL(transport_deregister_session_configfs);
diff --git a/drivers/target/tcm_fc/tcm_fc.h b/drivers/target/tcm_fc/tcm_fc.h
index defff32b7880..7b82f1b7fef8 100644
--- a/drivers/target/tcm_fc/tcm_fc.h
+++ b/drivers/target/tcm_fc/tcm_fc.h
@@ -144,7 +144,7 @@ enum ft_cmd_state {
144 */ 144 */
145struct ft_cmd { 145struct ft_cmd {
146 enum ft_cmd_state state; 146 enum ft_cmd_state state;
147 u16 lun; /* LUN from request */ 147 u32 lun; /* LUN from request */
148 struct ft_sess *sess; /* session held for cmd */ 148 struct ft_sess *sess; /* session held for cmd */
149 struct fc_seq *seq; /* sequence in exchange mgr */ 149 struct fc_seq *seq; /* sequence in exchange mgr */
150 struct se_cmd se_cmd; /* Local TCM I/O descriptor */ 150 struct se_cmd se_cmd; /* Local TCM I/O descriptor */
diff --git a/drivers/target/tcm_fc/tfc_cmd.c b/drivers/target/tcm_fc/tfc_cmd.c
index c056a1132ae1..b2a106729d49 100644
--- a/drivers/target/tcm_fc/tfc_cmd.c
+++ b/drivers/target/tcm_fc/tfc_cmd.c
@@ -94,29 +94,6 @@ void ft_dump_cmd(struct ft_cmd *cmd, const char *caller)
94 16, 4, cmd->cdb, MAX_COMMAND_SIZE, 0); 94 16, 4, cmd->cdb, MAX_COMMAND_SIZE, 0);
95} 95}
96 96
97/*
98 * Get LUN from CDB.
99 */
100static int ft_get_lun_for_cmd(struct ft_cmd *cmd, u8 *lunp)
101{
102 u64 lun;
103
104 lun = lunp[1];
105 switch (lunp[0] >> 6) {
106 case 0:
107 break;
108 case 1:
109 lun |= (lunp[0] & 0x3f) << 8;
110 break;
111 default:
112 return -1;
113 }
114 if (lun >= TRANSPORT_MAX_LUNS_PER_TPG)
115 return -1;
116 cmd->lun = lun;
117 return transport_get_lun_for_cmd(&cmd->se_cmd, NULL, lun);
118}
119
120static void ft_queue_cmd(struct ft_sess *sess, struct ft_cmd *cmd) 97static void ft_queue_cmd(struct ft_sess *sess, struct ft_cmd *cmd)
121{ 98{
122 struct se_queue_obj *qobj; 99 struct se_queue_obj *qobj;
@@ -418,6 +395,7 @@ static void ft_send_tm(struct ft_cmd *cmd)
418{ 395{
419 struct se_tmr_req *tmr; 396 struct se_tmr_req *tmr;
420 struct fcp_cmnd *fcp; 397 struct fcp_cmnd *fcp;
398 struct ft_sess *sess;
421 u8 tm_func; 399 u8 tm_func;
422 400
423 fcp = fc_frame_payload_get(cmd->req_frame, sizeof(*fcp)); 401 fcp = fc_frame_payload_get(cmd->req_frame, sizeof(*fcp));
@@ -425,13 +403,6 @@ static void ft_send_tm(struct ft_cmd *cmd)
425 switch (fcp->fc_tm_flags) { 403 switch (fcp->fc_tm_flags) {
426 case FCP_TMF_LUN_RESET: 404 case FCP_TMF_LUN_RESET:
427 tm_func = TMR_LUN_RESET; 405 tm_func = TMR_LUN_RESET;
428 if (ft_get_lun_for_cmd(cmd, fcp->fc_lun) < 0) {
429 ft_dump_cmd(cmd, __func__);
430 transport_send_check_condition_and_sense(&cmd->se_cmd,
431 cmd->se_cmd.scsi_sense_reason, 0);
432 ft_sess_put(cmd->sess);
433 return;
434 }
435 break; 406 break;
436 case FCP_TMF_TGT_RESET: 407 case FCP_TMF_TGT_RESET:
437 tm_func = TMR_TARGET_WARM_RESET; 408 tm_func = TMR_TARGET_WARM_RESET;
@@ -463,6 +434,36 @@ static void ft_send_tm(struct ft_cmd *cmd)
463 return; 434 return;
464 } 435 }
465 cmd->se_cmd.se_tmr_req = tmr; 436 cmd->se_cmd.se_tmr_req = tmr;
437
438 switch (fcp->fc_tm_flags) {
439 case FCP_TMF_LUN_RESET:
440 cmd->lun = scsilun_to_int((struct scsi_lun *)fcp->fc_lun);
441 if (transport_get_lun_for_tmr(&cmd->se_cmd, cmd->lun) < 0) {
442 /*
443 * Make sure to clean up newly allocated TMR request
444 * since "unable to handle TMR request because failed
445 * to get to LUN"
446 */
447 FT_TM_DBG("Failed to get LUN for TMR func %d, "
448 "se_cmd %p, unpacked_lun %d\n",
449 tm_func, &cmd->se_cmd, cmd->lun);
450 ft_dump_cmd(cmd, __func__);
451 sess = cmd->sess;
452 transport_send_check_condition_and_sense(&cmd->se_cmd,
453 cmd->se_cmd.scsi_sense_reason, 0);
454 transport_generic_free_cmd(&cmd->se_cmd, 0, 1, 0);
455 ft_sess_put(sess);
456 return;
457 }
458 break;
459 case FCP_TMF_TGT_RESET:
460 case FCP_TMF_CLR_TASK_SET:
461 case FCP_TMF_ABT_TASK_SET:
462 case FCP_TMF_CLR_ACA:
463 break;
464 default:
465 return;
466 }
466 transport_generic_handle_tmr(&cmd->se_cmd); 467 transport_generic_handle_tmr(&cmd->se_cmd);
467} 468}
468 469
@@ -635,7 +636,8 @@ static void ft_send_cmd(struct ft_cmd *cmd)
635 636
636 fc_seq_exch(cmd->seq)->lp->tt.seq_set_resp(cmd->seq, ft_recv_seq, cmd); 637 fc_seq_exch(cmd->seq)->lp->tt.seq_set_resp(cmd->seq, ft_recv_seq, cmd);
637 638
638 ret = ft_get_lun_for_cmd(cmd, fcp->fc_lun); 639 cmd->lun = scsilun_to_int((struct scsi_lun *)fcp->fc_lun);
640 ret = transport_get_lun_for_cmd(&cmd->se_cmd, NULL, cmd->lun);
639 if (ret < 0) { 641 if (ret < 0) {
640 ft_dump_cmd(cmd, __func__); 642 ft_dump_cmd(cmd, __func__);
641 transport_send_check_condition_and_sense(&cmd->se_cmd, 643 transport_send_check_condition_and_sense(&cmd->se_cmd,
diff --git a/drivers/target/tcm_fc/tfc_io.c b/drivers/target/tcm_fc/tfc_io.c
index 4c3c0efbe13f..8c4a24077d9d 100644
--- a/drivers/target/tcm_fc/tfc_io.c
+++ b/drivers/target/tcm_fc/tfc_io.c
@@ -203,7 +203,7 @@ int ft_queue_data_in(struct se_cmd *se_cmd)
203 /* XXX For now, initiator will retry */ 203 /* XXX For now, initiator will retry */
204 if (printk_ratelimit()) 204 if (printk_ratelimit())
205 printk(KERN_ERR "%s: Failed to send frame %p, " 205 printk(KERN_ERR "%s: Failed to send frame %p, "
206 "xid <0x%x>, remaining <0x%x>, " 206 "xid <0x%x>, remaining %zu, "
207 "lso_max <0x%x>\n", 207 "lso_max <0x%x>\n",
208 __func__, fp, ep->xid, 208 __func__, fp, ep->xid,
209 remaining, lport->lso_max); 209 remaining, lport->lso_max);
diff --git a/drivers/target/tcm_fc/tfc_sess.c b/drivers/target/tcm_fc/tfc_sess.c
index a3bd57f2ea32..7491e21cc6ae 100644
--- a/drivers/target/tcm_fc/tfc_sess.c
+++ b/drivers/target/tcm_fc/tfc_sess.c
@@ -229,7 +229,7 @@ static struct ft_sess *ft_sess_create(struct ft_tport *tport, u32 port_id,
229 return NULL; 229 return NULL;
230 230
231 sess->se_sess = transport_init_session(); 231 sess->se_sess = transport_init_session();
232 if (!sess->se_sess) { 232 if (IS_ERR(sess->se_sess)) {
233 kfree(sess); 233 kfree(sess);
234 return NULL; 234 return NULL;
235 } 235 }
@@ -332,7 +332,7 @@ void ft_sess_close(struct se_session *se_sess)
332 lport = sess->tport->lport; 332 lport = sess->tport->lport;
333 port_id = sess->port_id; 333 port_id = sess->port_id;
334 if (port_id == -1) { 334 if (port_id == -1) {
335 mutex_lock(&ft_lport_lock); 335 mutex_unlock(&ft_lport_lock);
336 return; 336 return;
337 } 337 }
338 FT_SESS_DBG("port_id %x\n", port_id); 338 FT_SESS_DBG("port_id %x\n", port_id);