target: Core cleanups from AGrover (round 1)
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / target / loopback / tcm_loop.c
index dee2a2c909f5386671f593428cbfa837f37e65a6..2f19e192649354a59089e229c831575d05312735 100644 (file)
@@ -118,11 +118,11 @@ static struct se_cmd *tcm_loop_allocate_core_cmd(
         * Signal BIDI usage with T_TASK(cmd)->t_tasks_bidi
         */
        if (scsi_bidi_cmnd(sc))
-               T_TASK(se_cmd)->t_tasks_bidi = 1;
+               se_cmd->t_task->t_tasks_bidi = 1;
        /*
         * Locate the struct se_lun pointer and attach it to struct se_cmd
         */
-       if (transport_get_lun_for_cmd(se_cmd, NULL, tl_cmd->sc->device->lun) < 0) {
+       if (transport_get_lun_for_cmd(se_cmd, tl_cmd->sc->device->lun) < 0) {
                kmem_cache_free(tcm_loop_cmd_cache, tl_cmd);
                set_host_byte(sc, DID_NO_CONNECT);
                return NULL;
@@ -176,7 +176,7 @@ static int tcm_loop_new_cmd_map(struct se_cmd *se_cmd)
                 * For BIDI commands, pass in the extra READ buffer
                 * to transport_generic_map_mem_to_cmd() below..
                 */
-               if (T_TASK(se_cmd)->t_tasks_bidi) {
+               if (se_cmd->t_task->t_tasks_bidi) {
                        struct scsi_data_buffer *sdb = scsi_in(sc);
 
                        mem_bidi_ptr = (void *)sdb->table.sgl;
@@ -386,7 +386,7 @@ static int tcm_loop_device_reset(struct scsi_cmnd *sc)
         */
        se_cmd->se_tmr_req = core_tmr_alloc_req(se_cmd, (void *)tl_tmr,
                                TMR_LUN_RESET);
-       if (!se_cmd->se_tmr_req)
+       if (IS_ERR(se_cmd->se_tmr_req))
                goto release;
        /*
         * Locate the underlying TCM struct se_lun from sc->device->lun
@@ -1017,6 +1017,7 @@ static int tcm_loop_make_nexus(
        struct se_portal_group *se_tpg;
        struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba;
        struct tcm_loop_nexus *tl_nexus;
+       int ret = -ENOMEM;
 
        if (tl_tpg->tl_hba->tl_nexus) {
                printk(KERN_INFO "tl_tpg->tl_hba->tl_nexus already exists\n");
@@ -1033,8 +1034,10 @@ static int tcm_loop_make_nexus(
         * Initialize the struct se_session pointer
         */
        tl_nexus->se_sess = transport_init_session();
-       if (!tl_nexus->se_sess)
+       if (IS_ERR(tl_nexus->se_sess)) {
+               ret = PTR_ERR(tl_nexus->se_sess);
                goto out;
+       }
        /*
         * Since we are running in 'demo mode' this call with generate a
         * 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(
 
 out:
        kfree(tl_nexus);
-       return -ENOMEM;
+       return ret;
 }
 
 static int tcm_loop_drop_nexus(
@@ -1140,7 +1143,7 @@ static ssize_t tcm_loop_tpg_store_nexus(
         * the fabric protocol_id set in tcm_loop_make_scsi_hba(), and call
         * tcm_loop_make_nexus()
         */
-       if (strlen(page) > TL_WWN_ADDR_LEN) {
+       if (strlen(page) >= TL_WWN_ADDR_LEN) {
                printk(KERN_ERR "Emulated NAA Sas Address: %s, exceeds"
                                " max: %d\n", page, TL_WWN_ADDR_LEN);
                return -EINVAL;
@@ -1321,7 +1324,7 @@ struct se_wwn *tcm_loop_make_scsi_hba(
        return ERR_PTR(-EINVAL);
 
 check_len:
-       if (strlen(name) > TL_WWN_ADDR_LEN) {
+       if (strlen(name) >= TL_WWN_ADDR_LEN) {
                printk(KERN_ERR "Emulated NAA %s Address: %s, exceeds"
                        " max: %d\n", name, tcm_loop_dump_proto_id(tl_hba),
                        TL_WWN_ADDR_LEN);
@@ -1399,9 +1402,9 @@ static int tcm_loop_register_configfs(void)
         * Register the top level struct config_item_type with TCM core
         */
        fabric = target_fabric_configfs_init(THIS_MODULE, "loopback");
-       if (!fabric) {
+       if (IS_ERR(fabric)) {
                printk(KERN_ERR "tcm_loop_register_configfs() failed!\n");
-               return -1;
+               return PTR_ERR(fabric);
        }
        /*
         * Setup the fabric API of function pointers used by target_core_mod