Commit 4cba277f authored by Christoph Hellwig's avatar Christoph Hellwig Committed by James Bottomley

[PATCH] scsi_scan.c coding style fixes

Just some random styleups I made while walking over the file
for the devfs work.
parent ab84a4a7
...@@ -376,15 +376,15 @@ static void print_inquiry(unsigned char *inq_result) ...@@ -376,15 +376,15 @@ static void print_inquiry(unsigned char *inq_result)
} }
/** /**
* scsi_alloc_sdev - allocate and setup a Scsi_Device * scsi_alloc_sdev - allocate and setup a scsi_Device
* *
* Description: * Description:
* Allocate, initialize for io, and return a pointer to a Scsi_Device. * Allocate, initialize for io, and return a pointer to a scsi_Device.
* Stores the @shost, @channel, @id, and @lun in the Scsi_Device, and * Stores the @shost, @channel, @id, and @lun in the scsi_Device, and
* adds Scsi_Device to the appropriate list. * adds scsi_Device to the appropriate list.
* *
* Return value: * Return value:
* Scsi_Device pointer, or NULL on failure. * scsi_Device pointer, or NULL on failure.
**/ **/
static struct scsi_device *scsi_alloc_sdev(struct Scsi_Host *shost, static struct scsi_device *scsi_alloc_sdev(struct Scsi_Host *shost,
uint channel, uint id, uint lun) uint channel, uint id, uint lun)
...@@ -465,9 +465,7 @@ static struct scsi_device *scsi_alloc_sdev(struct Scsi_Host *shost, ...@@ -465,9 +465,7 @@ static struct scsi_device *scsi_alloc_sdev(struct Scsi_Host *shost,
return sdev; return sdev;
out_free_queue: out_free_queue:
if (sdev->request_queue)
scsi_free_queue(sdev->request_queue); scsi_free_queue(sdev->request_queue);
out_free_dev: out_free_dev:
kfree(sdev); kfree(sdev);
out: out:
...@@ -476,8 +474,8 @@ static struct scsi_device *scsi_alloc_sdev(struct Scsi_Host *shost, ...@@ -476,8 +474,8 @@ static struct scsi_device *scsi_alloc_sdev(struct Scsi_Host *shost,
} }
/** /**
* scsi_free_sdev - cleanup and free a Scsi_Device * scsi_free_sdev - cleanup and free a scsi_device
* @sdev: cleanup and free this Scsi_Device * @sdev: cleanup and free this scsi_device
* *
* Description: * Description:
* Undo the actions in scsi_alloc_sdev, including removing @sdev from * Undo the actions in scsi_alloc_sdev, including removing @sdev from
...@@ -499,8 +497,7 @@ static void scsi_free_sdev(struct scsi_device *sdev) ...@@ -499,8 +497,7 @@ static void scsi_free_sdev(struct scsi_device *sdev)
spin_lock_irqsave(sdev->host->host_lock, flags); spin_lock_irqsave(sdev->host->host_lock, flags);
list_del(&sdev->starved_entry); list_del(&sdev->starved_entry);
if (sdev->single_lun) { if (sdev->single_lun) {
sdev->sdev_target->starget_refcnt--; if (--sdev->sdev_target->starget_refcnt == 0)
if (sdev->sdev_target->starget_refcnt == 0)
kfree(sdev->sdev_target); kfree(sdev->sdev_target);
} }
spin_unlock_irqrestore(sdev->host->host_lock, flags); spin_unlock_irqrestore(sdev->host->host_lock, flags);
...@@ -1482,25 +1479,25 @@ static void scsi_sequential_lun_scan(struct Scsi_Host *shost, uint channel, ...@@ -1482,25 +1479,25 @@ static void scsi_sequential_lun_scan(struct Scsi_Host *shost, uint channel,
#ifdef CONFIG_SCSI_REPORT_LUNS #ifdef CONFIG_SCSI_REPORT_LUNS
/** /**
* scsilun_to_int: convert a ScsiLun to an int * scsilun_to_int: convert a scsi_lun to an int
* @scsilun: ScsiLun to be converted. * @scsilun: struct scsi_lun to be converted.
* *
* Description: * Description:
* Convert @scsilun from a ScsiLun to a four byte host byte-ordered * Convert @scsilun from a struct scsi_lun to a four byte host byte-ordered
* integer, and return the result. The caller must check for * integer, and return the result. The caller must check for
* truncation before using this function. * truncation before using this function.
* *
* Notes: * Notes:
* The ScsiLun is assumed to be four levels, with each level * The struct scsi_lun is assumed to be four levels, with each level
* effectively containing a SCSI byte-ordered (big endian) short; the * effectively containing a SCSI byte-ordered (big endian) short; the
* addressing bits of each level are ignored (the highest two bits). * addressing bits of each level are ignored (the highest two bits).
* For a description of the LUN format, post SCSI-3 see the SCSI * For a description of the LUN format, post SCSI-3 see the SCSI
* Architecture Model, for SCSI-3 see the SCSI Controller Commands. * Architecture Model, for SCSI-3 see the SCSI Controller Commands.
* *
* Given a ScsiLun of: 0a 04 0b 03 00 00 00 00, this function returns * Given a struct scsi_lun of: 0a 04 0b 03 00 00 00 00, this function returns
* the integer: 0x0b030a04 * the integer: 0x0b030a04
**/ **/
static int scsilun_to_int(ScsiLun *scsilun) static int scsilun_to_int(struct scsi_lun *scsilun)
{ {
int i; int i;
unsigned int lun; unsigned int lun;
...@@ -1511,7 +1508,6 @@ static int scsilun_to_int(ScsiLun *scsilun) ...@@ -1511,7 +1508,6 @@ static int scsilun_to_int(ScsiLun *scsilun)
scsilun->scsi_lun[i + 1]) << (i * 8)); scsilun->scsi_lun[i + 1]) << (i * 8));
return lun; return lun;
} }
#endif
/** /**
* scsi_report_lun_scan - Scan using SCSI REPORT LUN results * scsi_report_lun_scan - Scan using SCSI REPORT LUN results
...@@ -1528,18 +1524,16 @@ static int scsilun_to_int(ScsiLun *scsilun) ...@@ -1528,18 +1524,16 @@ static int scsilun_to_int(ScsiLun *scsilun)
* 0: scan completed (or no memory, so further scanning is futile) * 0: scan completed (or no memory, so further scanning is futile)
* 1: no report lun scan, or not configured * 1: no report lun scan, or not configured
**/ **/
static int scsi_report_lun_scan(Scsi_Device *sdev, int bflags) static int scsi_report_lun_scan(struct scsi_device *sdev, int bflags)
{ {
#ifdef CONFIG_SCSI_REPORT_LUNS
char devname[64]; char devname[64];
unsigned char scsi_cmd[MAX_COMMAND_SIZE]; unsigned char scsi_cmd[MAX_COMMAND_SIZE];
unsigned int length; unsigned int length;
unsigned int lun; unsigned int lun;
unsigned int num_luns; unsigned int num_luns;
unsigned int retries; unsigned int retries;
ScsiLun *fcp_cur_lun, *lun_data; struct scsi_lun *lunp, *lun_data;
Scsi_Request *sreq; struct scsi_request *sreq;
char *data; char *data;
/* /*
...@@ -1551,15 +1545,14 @@ static int scsi_report_lun_scan(Scsi_Device *sdev, int bflags) ...@@ -1551,15 +1545,14 @@ static int scsi_report_lun_scan(Scsi_Device *sdev, int bflags)
return 0; return 0;
sreq = scsi_allocate_request(sdev); sreq = scsi_allocate_request(sdev);
if (sreq == NULL) { if (!sreq)
printk(ALLOC_FAILURE_MSG, __FUNCTION__); goto out;
return 0;
} sprintf(devname, "host %d channel %d id %d",
sdev->host->host_no, sdev->channel, sdev->id);
sprintf(devname, "host %d channel %d id %d", sdev->host->host_no,
sdev->channel, sdev->id);
/* /*
* Allocate enough to hold the header (the same size as one ScsiLun) * Allocate enough to hold the header (the same size as one scsi_lun)
* plus the max number of luns we are requesting. * plus the max number of luns we are requesting.
* *
* Reallocating and trying again (with the exact amount we need) * Reallocating and trying again (with the exact amount we need)
...@@ -1568,24 +1561,19 @@ static int scsi_report_lun_scan(Scsi_Device *sdev, int bflags) ...@@ -1568,24 +1561,19 @@ static int scsi_report_lun_scan(Scsi_Device *sdev, int bflags)
* kmalloc - we don't want a kmalloc() failure of a huge value to * kmalloc - we don't want a kmalloc() failure of a huge value to
* prevent us from finding any LUNs on this target. * prevent us from finding any LUNs on this target.
*/ */
length = (max_scsi_report_luns + 1) * sizeof(ScsiLun); length = (max_scsi_report_luns + 1) * sizeof(struct scsi_lun);
lun_data = (ScsiLun *) kmalloc(length, GFP_ATOMIC | lun_data = kmalloc(length, GFP_ATOMIC |
(sdev->host->unchecked_isa_dma ? (sdev->host->unchecked_isa_dma ? __GFP_DMA : 0));
GFP_DMA : 0)); if (!lun_data)
if (lun_data == NULL) { goto out_release_request;
printk(ALLOC_FAILURE_MSG, __FUNCTION__);
scsi_release_request(sreq);
/*
* We are out of memory, don't try scanning any further.
*/
return 0;
}
scsi_cmd[0] = REPORT_LUNS; scsi_cmd[0] = REPORT_LUNS;
/* /*
* bytes 1 - 5: reserved, set to zero. * bytes 1 - 5: reserved, set to zero.
*/ */
memset(&scsi_cmd[1], 0, 5); memset(&scsi_cmd[1], 0, 5);
/* /*
* bytes 6 - 9: length of the command. * bytes 6 - 9: length of the command.
*/ */
...@@ -1609,19 +1597,18 @@ static int scsi_report_lun_scan(Scsi_Device *sdev, int bflags) ...@@ -1609,19 +1597,18 @@ static int scsi_report_lun_scan(Scsi_Device *sdev, int bflags)
* should come through as a check condition, and will not generate * should come through as a check condition, and will not generate
* a retry. * a retry.
*/ */
retries = 0; for (retries = 0; retries < 3; retries++) {
while (retries++ < 3) {
SCSI_LOG_SCAN_BUS(3, printk (KERN_INFO "scsi scan: Sending" SCSI_LOG_SCAN_BUS(3, printk (KERN_INFO "scsi scan: Sending"
" REPORT LUNS to %s (try %d)\n", devname, " REPORT LUNS to %s (try %d)\n", devname,
retries)); retries));
scsi_wait_req(sreq, (void *) scsi_cmd, (void *) lun_data, scsi_wait_req(sreq, scsi_cmd, lun_data, length,
length, SCSI_TIMEOUT + 4 * HZ, 3); SCSI_TIMEOUT + 4*HZ, 3);
SCSI_LOG_SCAN_BUS(3, printk (KERN_INFO "scsi scan: REPORT LUNS" SCSI_LOG_SCAN_BUS(3, printk (KERN_INFO "scsi scan: REPORT LUNS"
" %s (try %d) result 0x%x\n", sreq->sr_result " %s (try %d) result 0x%x\n", sreq->sr_result
? "failed" : "successful", retries, ? "failed" : "successful", retries,
sreq->sr_result)); sreq->sr_result));
if (sreq->sr_result == 0 if (sreq->sr_result == 0 ||
|| sreq->sr_sense_buffer[2] != UNIT_ATTENTION) sreq->sr_sense_buffer[2] != UNIT_ATTENTION)
break; break;
} }
...@@ -1629,7 +1616,7 @@ static int scsi_report_lun_scan(Scsi_Device *sdev, int bflags) ...@@ -1629,7 +1616,7 @@ static int scsi_report_lun_scan(Scsi_Device *sdev, int bflags)
/* /*
* The device probably does not support a REPORT LUN command * The device probably does not support a REPORT LUN command
*/ */
kfree((char *) lun_data); kfree(lun_data);
scsi_release_request(sreq); scsi_release_request(sreq);
return 1; return 1;
} }
...@@ -1641,31 +1628,32 @@ static int scsi_report_lun_scan(Scsi_Device *sdev, int bflags) ...@@ -1641,31 +1628,32 @@ static int scsi_report_lun_scan(Scsi_Device *sdev, int bflags)
data = (char *) lun_data->scsi_lun; data = (char *) lun_data->scsi_lun;
length = ((data[0] << 24) | (data[1] << 16) | length = ((data[0] << 24) | (data[1] << 16) |
(data[2] << 8) | (data[3] << 0)); (data[2] << 8) | (data[3] << 0));
if ((length / sizeof(ScsiLun)) > max_scsi_report_luns) {
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)" printk(KERN_WARNING "scsi: On %s only %d (max_scsi_report_luns)"
" of %d luns reported, try increasing" " of %d luns reported, try increasing"
" max_scsi_report_luns.\n", devname, " max_scsi_report_luns.\n", devname,
max_scsi_report_luns, length / sizeof(ScsiLun)); max_scsi_report_luns, num_luns);
num_luns = max_scsi_report_luns; num_luns = max_scsi_report_luns;
} else }
num_luns = (length / sizeof(ScsiLun));
SCSI_LOG_SCAN_BUS(3, printk (KERN_INFO "scsi scan: REPORT LUN scan of" SCSI_LOG_SCAN_BUS(3, printk (KERN_INFO "scsi scan: REPORT LUN scan of"
" host %d channel %d id %d\n", sdev->host->host_no, " host %d channel %d id %d\n", sdev->host->host_no,
sdev->channel, sdev->id)); sdev->channel, sdev->id));
/* /*
* Scan the luns in lun_data. The entry at offset 0 is really * 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. * the header, so start at 1 and go up to and including num_luns.
*/ */
for (fcp_cur_lun = &lun_data[1]; for (lunp = &lun_data[1]; lunp <= &lun_data[num_luns]; lunp++) {
fcp_cur_lun <= &lun_data[num_luns]; fcp_cur_lun++) { lun = scsilun_to_int(lunp);
lun = scsilun_to_int(fcp_cur_lun);
/* /*
* Check if the unused part of fcp_cur_lun is non-zero, * Check if the unused part of lunp is non-zero, and so
* and so does not fit in lun. * does not fit in lun.
*/ */
if (memcmp(&fcp_cur_lun->scsi_lun[sizeof(lun)], if (memcmp(&lunp->scsi_lun[sizeof(lun)], "\0\0\0\0", 4)) {
"\0\0\0\0", 4) != 0) {
int i; int i;
/* /*
...@@ -1674,8 +1662,8 @@ static int scsi_report_lun_scan(Scsi_Device *sdev, int bflags) ...@@ -1674,8 +1662,8 @@ static int scsi_report_lun_scan(Scsi_Device *sdev, int bflags)
* integer LUN value. * integer LUN value.
*/ */
printk(KERN_WARNING "scsi: %s lun 0x", devname); printk(KERN_WARNING "scsi: %s lun 0x", devname);
data = (char *) fcp_cur_lun->scsi_lun; data = (char *)lunp->scsi_lun;
for (i = 0; i < sizeof(ScsiLun); i++) for (i = 0; i < sizeof(struct scsi_lun); i++)
printk("%02x", data[i]); printk("%02x", data[i]);
printk(" has a LUN larger than currently supported.\n"); printk(" has a LUN larger than currently supported.\n");
} else if (lun == 0) { } else if (lun == 0) {
...@@ -1703,15 +1691,22 @@ static int scsi_report_lun_scan(Scsi_Device *sdev, int bflags) ...@@ -1703,15 +1691,22 @@ static int scsi_report_lun_scan(Scsi_Device *sdev, int bflags)
} }
} }
kfree((char *) lun_data); kfree(lun_data);
return 0; return 0;
out_release_request:
scsi_release_request(sreq);
out:
/*
* We are out of memory, don't try scanning any further.
*/
printk(ALLOC_FAILURE_MSG, __FUNCTION__);
return 0;
}
#else #else
return 1; # define scsi_report_lun_scan(sdev, blags) (1)
#endif /* CONFIG_SCSI_REPORT_LUNS */ #endif /* CONFIG_SCSI_REPORT_LUNS */
}
struct scsi_device *scsi_add_device(struct Scsi_Host *shost, struct scsi_device *scsi_add_device(struct Scsi_Host *shost,
uint channel, uint id, uint lun) uint channel, uint id, uint lun)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment