if (swl) kfree(swl);  if (new_fcport) kfree(new_fcport); 
kfree(swl); kfree(new_fcport); 
qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports){	int		rval;	uint16_t	loop_id;	fc_port_t	*fcport, *new_fcport, *fcptemp;	int		found;	sw_info_t	*swl;	int		swl_idx;	int		first_dev, last_dev;	port_id_t	wrap, nxt_d_id;	rval = QLA_SUCCESS;	/* Try GID_PT to get device list, else GAN. */	swl = kmalloc(sizeof(sw_info_t) * MAX_FIBRE_DEVICES, GFP_ATOMIC);	if (swl == NULL) {		/*EMPTY*/		DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "		    "on GA_NXT\n", ha->host_no));	} else {		memset(swl, 0, sizeof(sw_info_t) * MAX_FIBRE_DEVICES);		if (qla2x00_gid_pt(ha, swl) != QLA_SUCCESS) {			kfree(swl);			swl = NULL;		} else if (qla2x00_gpn_id(ha, swl) != QLA_SUCCESS) {			kfree(swl);			swl = NULL;		} else if (qla2x00_gnn_id(ha, swl) != QLA_SUCCESS) {			kfree(swl);			swl = NULL;		}	}	swl_idx = 0;	/* Allocate temporary fcport for any new fcports discovered. */	new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);	if (new_fcport == NULL) {		if (swl)			kfree(swl);		return (QLA_MEMORY_ALLOC_FAILED);	}	new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);	/* Set start port ID scan at adapter ID. */	first_dev = 1;	last_dev = 0;	/* Starting free loop ID. */	loop_id = ha->min_external_loopid;	for (; loop_id <= ha->last_loop_id; loop_id++) {		if (qla2x00_is_reserved_id(ha, loop_id))			continue;		if (atomic_read(&ha->loop_down_timer) ||		    test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))			break;		if (swl != NULL) {			if (last_dev) {				wrap.b24 = new_fcport->d_id.b24;			} else {				new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;				memcpy(new_fcport->node_name,				    swl[swl_idx].node_name, WWN_SIZE);				memcpy(new_fcport->port_name,				    swl[swl_idx].port_name, WWN_SIZE);				if (swl[swl_idx].d_id.b.rsvd_1 != 0) {					last_dev = 1;				}				swl_idx++;			}		} else {			/* Send GA_NXT to the switch */			rval = qla2x00_ga_nxt(ha, new_fcport);			if (rval != QLA_SUCCESS) {				qla_printk(KERN_WARNING, ha,				    "SNS scan failed -- assuming zero-entry "				    "result...\n");				list_for_each_entry_safe(fcport, fcptemp,				    new_fcports, list) {					list_del(&fcport->list);					kfree(fcport);				}				rval = QLA_SUCCESS;				break;			}		}		/* If wrap on switch device list, exit. */		if (first_dev) {			wrap.b24 = new_fcport->d_id.b24;			first_dev = 0;		} else if (new_fcport->d_id.b24 == wrap.b24) {			DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",			    ha->host_no, new_fcport->d_id.b.domain,			    new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));			break;		}		/* Bypass if host adapter. */		if (new_fcport->d_id.b24 == ha->d_id.b24)			continue;		/* Bypass if same domain and area of adapter. */		if (((new_fcport->d_id.b24 & 0xffff00) ==		    (ha->d_id.b24 & 0xffff00)) && ha->current_topology ==			ISP_CFG_FL)			    continue;		/* Bypass reserved domain fields. */		if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)			continue;		/* Locate matching device in database. */		found = 0;		list_for_each_entry(fcport, &ha->fcports, list) {			if (memcmp(new_fcport->port_name, fcport->port_name,			    WWN_SIZE))				continue;			found++;			/*			 * If address the same and state FCS_ONLINE, nothing			 * changed.			 */			if (fcport->d_id.b24 == new_fcport->d_id.b24 &&			    atomic_read(&fcport->state) == FCS_ONLINE) {				break;			}			/*			 * If device was not a fabric device before.			 */			if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {				fcport->d_id.b24 = new_fcport->d_id.b24;				fcport->loop_id = FC_NO_LOOP_ID;				fcport->flags |= (FCF_FABRIC_DEVICE |				    FCF_LOGIN_NEEDED);				fcport->flags &= ~FCF_PERSISTENT_BOUND;				break;			}			/*			 * Port ID changed or device was marked to be updated;			 * Log it out if still logged in and mark it for			 * relogin later.			 */			fcport->d_id.b24 = new_fcport->d_id.b24;			fcport->flags |= FCF_LOGIN_NEEDED;			if (fcport->loop_id != FC_NO_LOOP_ID &&			    (fcport->flags & FCF_TAPE_PRESENT) == 0 &&			    fcport->port_type != FCT_INITIATOR &&			    fcport->port_type != FCT_BROADCAST) {				ha->isp_ops.fabric_logout(ha, fcport->loop_id,				    fcport->d_id.b.domain, fcport->d_id.b.area,				    fcport->d_id.b.al_pa);				fcport->loop_id = FC_NO_LOOP_ID;			}			break;		}		if (found)			continue;		/* If device was not in our fcports list, then add it. */		list_add_tail(&new_fcport->list, new_fcports);		/* Allocate a new replacement fcport. */		nxt_d_id.b24 = new_fcport->d_id.b24;		new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);		if (new_fcport == NULL) {			if (swl)				kfree(swl);			return (QLA_MEMORY_ALLOC_FAILED);		}		new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);		new_fcport->d_id.b24 = nxt_d_id.b24;	}	if (swl)		kfree(swl);	if (new_fcport)		kfree(new_fcport);	if (!list_empty(new_fcports))		ha->device_flags |= DFLG_FABRIC_DEVICES;	return (rval);}
10457	/local/tlutelli/issta_data/temp/c/2005_temp/2005/10457/c9475cb0c358ff0dd473544280d92482df491913/qla_init.c/buggy/drivers/scsi/qla2xxx/qla_init.c