kfree(lun_data); return 1; 
ret = 1; goto out_err; 
static int scsi_report_lun_scan(struct scsi_target *starget, int bflags,				int rescan){	char devname[64];	unsigned char scsi_cmd[MAX_COMMAND_SIZE];	unsigned int length;	unsigned int lun;	unsigned int num_luns;	unsigned int retries;	int result;	struct scsi_lun *lunp, *lun_data;	u8 *data;	struct scsi_sense_hdr sshdr;	struct scsi_device *sdev;	struct Scsi_Host *shost = dev_to_shost(&starget->dev);	/*	 * Only support SCSI-3 and up devices if BLIST_NOREPORTLUN is not set.	 * Also allow SCSI-2 if BLIST_REPORTLUN2 is set and host adapter does	 * support more than 8 LUNs.	 */	if ((bflags & BLIST_NOREPORTLUN) || 	     starget->scsi_level < SCSI_2 ||	    (starget->scsi_level < SCSI_3 && 	     (!(bflags & BLIST_REPORTLUN2) || shost->max_lun <= 8)) )		return 1;	if (bflags & BLIST_NOLUN)		return 0;	if (!(sdev = scsi_device_lookup_by_target(starget, 0))) {		sdev = scsi_alloc_sdev(starget, 0, NULL);		if (!sdev)			return 0;		if (scsi_device_get(sdev))			return 0;	}	sprintf(devname, "host %d channel %d id %d",		shost->host_no, sdev->channel, sdev->id);	/*	 * Allocate enough to hold the header (the same size as one scsi_lun)	 * plus the max number of luns we are requesting.	 *	 * Reallocating and trying again (with the exact amount we need)	 * would be nice, but then we need to somehow limit the size	 * allocated based on the available memory and the limits of	 * kmalloc - we don't want a kmalloc() failure of a huge value to	 * prevent us from finding any LUNs on this target.	 */	length = (max_scsi_report_luns + 1) * sizeof(struct scsi_lun);	lun_data = kmalloc(length, GFP_ATOMIC |			   (sdev->host->unchecked_isa_dma ? __GFP_DMA : 0));	if (!lun_data) {		printk(ALLOC_FAILURE_MSG, __FUNCTION__);		goto out;	}	scsi_cmd[0] = REPORT_LUNS;	/*	 * bytes 1 - 5: reserved, set to zero.	 */	memset(&scsi_cmd[1], 0, 5);	/*	 * bytes 6 - 9: length of the command.	 */	scsi_cmd[6] = (unsigned char) (length >> 24) & 0xff;	scsi_cmd[7] = (unsigned char) (length >> 16) & 0xff;	scsi_cmd[8] = (unsigned char) (length >> 8) & 0xff;	scsi_cmd[9] = (unsigned char) length & 0xff;	scsi_cmd[10] = 0;	/* reserved */	scsi_cmd[11] = 0;	/* control */	/*	 * We can get a UNIT ATTENTION, for example a power on/reset, so	 * retry a few times (like sd.c does for TEST UNIT READY).	 * Experience shows some combinations of adapter/devices get at	 * least two power on/resets.	 *	 * Illegal requests (for devices that do not support REPORT LUNS)	 * should come through as a check condition, and will not generate	 * a retry.	 */	for (retries = 0; retries < 3; retries++) {		SCSI_LOG_SCAN_BUS(3, printk (KERN_INFO "scsi scan: Sending"				" REPORT LUNS to %s (try %d)\n", devname,				retries));		result = scsi_execute_req(sdev, scsi_cmd, DMA_FROM_DEVICE,					  lun_data, length, &sshdr,					  SCSI_TIMEOUT + 4 * HZ, 3);		SCSI_LOG_SCAN_BUS(3, printk (KERN_INFO "scsi scan: REPORT LUNS"				" %s (try %d) result 0x%x\n", result				?  "failed" : "successful", retries, result));		if (result == 0)			break;		else if (scsi_sense_valid(&sshdr)) {			if (sshdr.sense_key != UNIT_ATTENTION)				break;		}	}	if (result) {		/*		 * The device probably does not support a REPORT LUN command		 */		kfree(lun_data);		return 1;	}	/*	 * Get the length from the first four bytes of lun_data.	 */	data = (u8 *) lun_data->scsi_lun;	length = ((data[0] << 24) | (data[1] << 16) |		  (data[2] << 8) | (data[3] << 0));	num_luns = (length / sizeof(struct scsi_lun));	if (num_luns > max_scsi_report_luns) {		printk(KERN_WARNING "scsi: On %s only %d (max_scsi_report_luns)"		       " of %d luns reported, try increasing"		       " max_scsi_report_luns.\n", devname,		       max_scsi_report_luns, num_luns);		num_luns = max_scsi_report_luns;	}	SCSI_LOG_SCAN_BUS(3, sdev_printk (KERN_INFO, sdev,		"scsi scan: REPORT LUN scan\n"));	/*	 * Scan the luns in lun_data. The entry at offset 0 is really	 * the header, so start at 1 and go up to and including num_luns.	 */	for (lunp = &lun_data[1]; lunp <= &lun_data[num_luns]; lunp++) {		lun = scsilun_to_int(lunp);		/*		 * Check if the unused part of lunp is non-zero, and so		 * does not fit in lun.		 */		if (memcmp(&lunp->scsi_lun[sizeof(lun)], "\0\0\0\0", 4)) {			int i;			/*			 * Output an error displaying the LUN in byte order,			 * this differs from what linux would print for the			 * integer LUN value.			 */			printk(KERN_WARNING "scsi: %s lun 0x", devname);			data = (char *)lunp->scsi_lun;			for (i = 0; i < sizeof(struct scsi_lun); i++)				printk("%02x", data[i]);			printk(" has a LUN larger than currently supported.\n");		} else if (lun > sdev->host->max_lun) {			printk(KERN_WARNING "scsi: %s lun%d has a LUN larger"			       " than allowed by the host adapter\n",			       devname, lun);		} else {			int res;			res = scsi_probe_and_add_lun(starget,				lun, NULL, NULL, rescan, NULL);			if (res == SCSI_SCAN_NO_RESPONSE) {				/*				 * Got some results, but now none, abort.				 */				sdev_printk(KERN_ERR, sdev,					"Unexpected response"				        " from lun %d while scanning, scan"				        " aborted\n", lun);				break;			}		}	}	kfree(lun_data); out:	scsi_device_put(sdev);	if (sdev->sdev_state == SDEV_CREATED)		/*		 * the sdev we used didn't appear in the report luns scan		 */		scsi_destroy_sdev(sdev);	return 0;}
10457	/local/tlutelli/issta_data/temp/c/2005_temp/2005/10457/2ef8919830a262f10fb5e4a685e95f71a64bce6c/scsi_scan.c/clean/drivers/scsi/scsi_scan.c