u64 node_name = 0;
 
        list_for_each_entry(fcport, &ha->fcports, list) {
-               if (starget->id == fcport->os_target_id) {
+               if (fcport->rport &&
+                   starget->id == fcport->rport->scsi_target_id) {
                        node_name = wwn_to_u64(fcport->node_name);
                        break;
                }
        u64 port_name = 0;
 
        list_for_each_entry(fcport, &ha->fcports, list) {
-               if (starget->id == fcport->os_target_id) {
+               if (fcport->rport &&
+                   starget->id == fcport->rport->scsi_target_id) {
                        port_name = wwn_to_u64(fcport->port_name);
                        break;
                }
        uint32_t port_id = ~0U;
 
        list_for_each_entry(fcport, &ha->fcports, list) {
-               if (starget->id == fcport->os_target_id) {
+               if (fcport->rport &&
+                   starget->id == fcport->rport->scsi_target_id) {
                        port_id = fcport->d_id.b.domain << 16 |
                            fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
                        break;
 
        if (fcport->port_type == FCT_TARGET)
                rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
        fc_remote_port_rolechg(rport, rport_ids.roles);
-
-       if (rport->scsi_target_id != -1 &&
-           rport->scsi_target_id < ha->host->max_id)
-               fcport->os_target_id = rport->scsi_target_id;
 }
 
 /*