Skip to content

Commit

Permalink
[SCSI] drivers/scsi: Use ARRAY_SIZE macro
Browse files Browse the repository at this point in the history
Use ARRAY_SIZE macro instead of sizeof(x)/sizeof(x[0]) and remove
duplicates of the macro.

Signed-off-by: Tobias Klauser <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: James Bottomley <[email protected]>
  • Loading branch information
Tobias Klauser authored and James Bottomley committed Jun 10, 2006
1 parent 9dc399d commit 6391a11
Show file tree
Hide file tree
Showing 47 changed files with 167 additions and 200 deletions.
6 changes: 3 additions & 3 deletions drivers/scsi/3w-xxxx.c
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ static int tw_decode_sense(TW_Device_Extension *tw_dev, int request_id, int fill
/* Attempt to return intelligent sense information */
if (fill_sense) {
if ((command->status == 0xc7) || (command->status == 0xcb)) {
for (i=0;i<(sizeof(tw_sense_table)/sizeof(tw_sense_table[0]));i++) {
for (i = 0; i < ARRAY_SIZE(tw_sense_table); i++) {
if (command->flags == tw_sense_table[i][0]) {

/* Valid bit and 'current errors' */
Expand Down Expand Up @@ -625,7 +625,7 @@ static int tw_aen_complete(TW_Device_Extension *tw_dev, int request_id)
if (aen == 0x0ff) {
printk(KERN_WARNING "3w-xxxx: scsi%d: AEN: INFO: AEN queue overflow.\n", tw_dev->host->host_no);
} else {
table_max = sizeof(tw_aen_string)/sizeof(char *);
table_max = ARRAY_SIZE(tw_aen_string);
if ((aen & 0x0ff) < table_max) {
if ((tw_aen_string[aen & 0xff][strlen(tw_aen_string[aen & 0xff])-1]) == '#') {
printk(KERN_WARNING "3w-xxxx: scsi%d: AEN: %s%d.\n", tw_dev->host->host_no, tw_aen_string[aen & 0xff], aen >> 8);
Expand Down Expand Up @@ -786,7 +786,7 @@ static int tw_aen_drain_queue(TW_Device_Extension *tw_dev)
if (aen == 0x0ff) {
printk(KERN_WARNING "3w-xxxx: AEN: INFO: AEN queue overflow.\n");
} else {
table_max = sizeof(tw_aen_string)/sizeof(char *);
table_max = ARRAY_SIZE(tw_aen_string);
if ((aen & 0x0ff) < table_max) {
if ((tw_aen_string[aen & 0xff][strlen(tw_aen_string[aen & 0xff])-1]) == '#') {
printk(KERN_WARNING "3w-xxxx: AEN: %s%d.\n", tw_aen_string[aen & 0xff], aen >> 8);
Expand Down
19 changes: 8 additions & 11 deletions drivers/scsi/53c700.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ NCR_700_detect(struct scsi_host_template *tpnt,
BUG_ON(!dma_is_consistent(pScript) && L1_CACHE_BYTES < dma_get_cache_alignment());
hostdata->slots = (struct NCR_700_command_slot *)(memory + SLOTS_OFFSET);
hostdata->dev = dev;

pSlots = pScript + SLOTS_OFFSET;

/* Fill in the missing routines from the host template */
Expand All @@ -332,19 +332,18 @@ NCR_700_detect(struct scsi_host_template *tpnt,
tpnt->slave_destroy = NCR_700_slave_destroy;
tpnt->change_queue_depth = NCR_700_change_queue_depth;
tpnt->change_queue_type = NCR_700_change_queue_type;

if(tpnt->name == NULL)
tpnt->name = "53c700";
if(tpnt->proc_name == NULL)
tpnt->proc_name = "53c700";


host = scsi_host_alloc(tpnt, 4);
if (!host)
return NULL;
memset(hostdata->slots, 0, sizeof(struct NCR_700_command_slot)
* NCR_700_COMMAND_SLOTS_PER_HOST);
for(j = 0; j < NCR_700_COMMAND_SLOTS_PER_HOST; j++) {
for (j = 0; j < NCR_700_COMMAND_SLOTS_PER_HOST; j++) {
dma_addr_t offset = (dma_addr_t)((unsigned long)&hostdata->slots[j].SG[0]
- (unsigned long)&hostdata->slots[0].SG[0]);
hostdata->slots[j].pSG = (struct NCR_700_SG_List *)((unsigned long)(pSlots + offset));
Expand All @@ -355,14 +354,12 @@ NCR_700_detect(struct scsi_host_template *tpnt,
hostdata->slots[j].state = NCR_700_SLOT_FREE;
}

for(j = 0; j < sizeof(SCRIPT)/sizeof(SCRIPT[0]); j++) {
for (j = 0; j < ARRAY_SIZE(SCRIPT); j++)
script[j] = bS_to_host(SCRIPT[j]);
}

/* adjust all labels to be bus physical */
for(j = 0; j < PATCHES; j++) {
for (j = 0; j < PATCHES; j++)
script[LABELPATCHES[j]] = bS_to_host(pScript + SCRIPT[LABELPATCHES[j]]);
}
/* now patch up fixed addresses. */
script_patch_32(script, MessageLocation,
pScript + MSGOUT_OFFSET);
Expand All @@ -385,17 +382,17 @@ NCR_700_detect(struct scsi_host_template *tpnt,
host->hostdata[0] = (unsigned long)hostdata;
/* kick the chip */
NCR_700_writeb(0xff, host, CTEST9_REG);
if(hostdata->chip710)
if (hostdata->chip710)
hostdata->rev = (NCR_700_readb(host, CTEST8_REG)>>4) & 0x0f;
else
hostdata->rev = (NCR_700_readb(host, CTEST7_REG)>>4) & 0x0f;
hostdata->fast = (NCR_700_readb(host, CTEST9_REG) == 0);
if(banner == 0) {
if (banner == 0) {
printk(KERN_NOTICE "53c700: Version " NCR_700_VERSION " By [email protected]\n");
banner = 1;
}
printk(KERN_NOTICE "scsi%d: %s rev %d %s\n", host->host_no,
hostdata->chip710 ? "53c710" :
hostdata->chip710 ? "53c710" :
(hostdata->fast ? "53c700-66" : "53c700"),
hostdata->rev, hostdata->differential ?
"(Differential)" : "");
Expand Down
14 changes: 7 additions & 7 deletions drivers/scsi/53c7xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ int CmdPageStart = (0 - Ent_dsa_zero - sizeof(struct NCR53c7x0_cmd)) & 0xff;
static char *setup_strings[] =
{"","","","","","","",""};

#define MAX_SETUP_STRINGS (sizeof(setup_strings) / sizeof(char *))
#define MAX_SETUP_STRINGS ARRAY_SIZE(setup_strings)
#define SETUP_BUFFER_SIZE 200
static char setup_buffer[SETUP_BUFFER_SIZE];
static char setup_used[MAX_SETUP_STRINGS];
Expand Down Expand Up @@ -2190,15 +2190,15 @@ static const struct {
*/


static void
static void
synchronous (struct Scsi_Host *host, int target, char *msg) {
struct NCR53c7x0_hostdata *hostdata = (struct NCR53c7x0_hostdata *)
host->hostdata[0];
int desire, divisor, i, limit;
unsigned char scntl3, sxfer;
/* The diagnostic message fits on one line, even with max. width integers */
char buf[80];
char buf[80];

/* Desired transfer clock in Hz */
desire = 1000000000L / (msg[3] * 4);
/* Scale the available SCSI clock by 10 so we get tenths */
Expand All @@ -2209,14 +2209,14 @@ synchronous (struct Scsi_Host *host, int target, char *msg) {
msg[4] = 8;

if (hostdata->options & OPTION_DEBUG_SDTR)
printk("scsi%d : optimal synchronous divisor of %d.%01d\n",
printk("scsi%d : optimal synchronous divisor of %d.%01d\n",
host->host_no, divisor / 10, divisor % 10);

limit = (sizeof(syncs) / sizeof(syncs[0]) -1);
limit = ARRAY_SIZE(syncs) - 1;
for (i = 0; (i < limit) && (divisor > syncs[i].div); ++i);

if (hostdata->options & OPTION_DEBUG_SDTR)
printk("scsi%d : selected synchronous divisor of %d.%01d\n",
printk("scsi%d : selected synchronous divisor of %d.%01d\n",
host->host_no, syncs[i].div / 10, syncs[i].div % 10);

msg[3] = ((1000000000L / hostdata->scsi_clock) * syncs[i].div / 10 / 4);
Expand Down
8 changes: 4 additions & 4 deletions drivers/scsi/NCR53c406a.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,16 +213,16 @@ static void *addresses[] = {
(void *) 0xd8000,
(void *) 0xc8000
};
#define ADDRESS_COUNT (sizeof( addresses ) / sizeof( unsigned ))
#define ADDRESS_COUNT ARRAY_SIZE(addresses)
#endif /* USE_BIOS */

/* possible i/o port addresses */
static unsigned short ports[] = { 0x230, 0x330, 0x280, 0x290, 0x330, 0x340, 0x300, 0x310, 0x348, 0x350 };
#define PORT_COUNT (sizeof( ports ) / sizeof( unsigned short ))
#define PORT_COUNT ARRAY_SIZE(ports)

/* possible interrupt channels */
static unsigned short intrs[] = { 10, 11, 12, 15 };
#define INTR_COUNT (sizeof( intrs ) / sizeof( unsigned short ))
#define INTR_COUNT ARRAY_SIZE(intrs)

/* signatures for NCR 53c406a based controllers */
#if USE_BIOS
Expand All @@ -236,7 +236,7 @@ struct signature {
{
"Copyright (C) Acculogic, Inc.\r\n2.8M Diskette Extension Bios ver 4.04.03 03/01/1993", 61, 82},};

#define SIGNATURE_COUNT (sizeof( signatures ) / sizeof( struct signature ))
#define SIGNATURE_COUNT ARRAY_SIZE(signatures)
#endif /* USE_BIOS */

/* ============================================================ */
Expand Down
18 changes: 8 additions & 10 deletions drivers/scsi/aacraid/aachba.c
Original file line number Diff line number Diff line change
Expand Up @@ -641,13 +641,13 @@ static void setinqstr(struct aac_dev *dev, void *data, int tindex)
cp[sizeof(str->pid)] = c;
} else {
struct aac_driver_ident *mp = aac_get_driver_ident(dev->cardtype);
inqstrcpy (mp->vname, str->vid);

inqstrcpy (mp->vname, str->vid);
/* last six chars reserved for vol type */
inqstrcpy (mp->model, str->pid);
}

if (tindex < (sizeof(container_types)/sizeof(char *))){
if (tindex < ARRAY_SIZE(container_types)){
char *findit = str->pid;

for ( ; *findit != ' '; findit++); /* walk till we find a space */
Expand Down Expand Up @@ -1576,7 +1576,7 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
* see: <vendor>.c i.e. aac.c
*/
if (scmd_id(scsicmd) == host->this_id) {
setinqstr(dev, (void *) (inq_data.inqd_vid), (sizeof(container_types)/sizeof(char *)));
setinqstr(dev, (void *) (inq_data.inqd_vid), ARRAY_SIZE(container_types));
inq_data.inqd_pdt = INQD_PDT_PROC; /* Processor device */
aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data));
scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
Expand Down Expand Up @@ -2381,7 +2381,7 @@ static struct aac_srb_status_info srb_status_info[] = {
{ SRB_STATUS_SUCCESS, "Success"},
{ SRB_STATUS_ABORTED, "Aborted Command"},
{ SRB_STATUS_ABORT_FAILED, "Abort Failed"},
{ SRB_STATUS_ERROR, "Error Event"},
{ SRB_STATUS_ERROR, "Error Event"},
{ SRB_STATUS_BUSY, "Device Busy"},
{ SRB_STATUS_INVALID_REQUEST, "Invalid Request"},
{ SRB_STATUS_INVALID_PATH_ID, "Invalid Path ID"},
Expand All @@ -2400,7 +2400,7 @@ static struct aac_srb_status_info srb_status_info[] = {
{ SRB_STATUS_BAD_SRB_BLOCK_LENGTH,"Bad Srb Block Length"},
{ SRB_STATUS_REQUEST_FLUSHED, "Request Flushed"},
{ SRB_STATUS_DELAYED_RETRY, "Delayed Retry"},
{ SRB_STATUS_INVALID_LUN, "Invalid LUN"},
{ SRB_STATUS_INVALID_LUN, "Invalid LUN"},
{ SRB_STATUS_INVALID_TARGET_ID, "Invalid TARGET ID"},
{ SRB_STATUS_BAD_FUNCTION, "Bad Function"},
{ SRB_STATUS_ERROR_RECOVERY, "Error Recovery"},
Expand All @@ -2415,11 +2415,9 @@ char *aac_get_status_string(u32 status)
{
int i;

for(i=0; i < (sizeof(srb_status_info)/sizeof(struct aac_srb_status_info)); i++ ){
if(srb_status_info[i].status == status){
for (i = 0; i < ARRAY_SIZE(srb_status_info); i++)
if (srb_status_info[i].status == status)
return srb_status_info[i].str;
}
}

return "Bad Status Code";
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/scsi/aacraid/commctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
default:
data_dir = DMA_NONE;
}
if (user_srbcmd->sg.count > (sizeof(sg_list)/sizeof(sg_list[0]))) {
if (user_srbcmd->sg.count > ARRAY_SIZE(sg_list)) {
dprintk((KERN_DEBUG"aacraid: too many sg entries %d\n",
le32_to_cpu(srbcmd->sg.count)));
rcode = -EINVAL;
Expand Down
31 changes: 14 additions & 17 deletions drivers/scsi/aha1542.c
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ static int __init do_setup(char *str)

int count=setup_idx;

get_options(str, sizeof(ints)/sizeof(int), ints);
get_options(str, ARRAY_SIZE(ints), ints);
aha1542_setup(str,ints);

return count<setup_idx;
Expand Down Expand Up @@ -1072,8 +1072,7 @@ static int __init aha1542_detect(struct scsi_host_template * tpnt)
int slot = 0;
int pos = 0;

for (indx = 0; (slot != MCA_NOTFOUND) &&
(indx < sizeof(bases)/sizeof(bases[0])); indx++) {
for (indx = 0; (slot != MCA_NOTFOUND) && (indx < ARRAY_SIZE(bases)); indx++) {

if (bases[indx])
continue;
Expand All @@ -1083,10 +1082,9 @@ static int __init aha1542_detect(struct scsi_host_template * tpnt)
if (slot == MCA_NOTFOUND)
break;


/* Found one */
pos = mca_read_stored_pos(slot, 3);

/* Decode address */
if (pos & 0x80) {
if (pos & 0x02) {
Expand Down Expand Up @@ -1118,23 +1116,22 @@ static int __init aha1542_detect(struct scsi_host_template * tpnt)
mca_set_adapter_name(slot, "Adapter AHA-1640");
mca_set_adapter_procfn(slot, NULL, NULL);
mca_mark_as_used(slot);

/* Go on */
slot++;
}

}
#endif

/*
* Hunt for ISA Plug'n'Pray Adaptecs (AHA1535)
*/

if(isapnp)
{
struct pnp_dev *pdev = NULL;
for(indx = 0; indx <sizeof(bases)/sizeof(bases[0]);indx++)
{
for(indx = 0; indx < ARRAY_SIZE(bases); indx++) {
if(bases[indx])
continue;
pdev = pnp_find_dev(NULL, ISAPNP_VENDOR('A', 'D', 'P'),
Expand All @@ -1144,29 +1141,29 @@ static int __init aha1542_detect(struct scsi_host_template * tpnt)
/*
* Activate the PnP card
*/

if(pnp_device_attach(pdev)<0)
continue;

if(pnp_activate_dev(pdev)<0) {
pnp_device_detach(pdev);
continue;
}

if(!pnp_port_valid(pdev, 0)) {
pnp_device_detach(pdev);
continue;
}

bases[indx] = pnp_port_start(pdev, 0);

/* The card can be queried for its DMA, we have
the DMA set up that is enough */

printk(KERN_INFO "ISAPnP found an AHA1535 at I/O 0x%03X\n", bases[indx]);
}
}
for (indx = 0; indx < sizeof(bases) / sizeof(bases[0]); indx++)
for (indx = 0; indx < ARRAY_SIZE(bases); indx++)
if (bases[indx] != 0 && request_region(bases[indx], 4, "aha1542")) {
shpnt = scsi_register(tpnt,
sizeof(struct aha1542_hostdata));
Expand Down
2 changes: 1 addition & 1 deletion drivers/scsi/aic7xxx/aic7770.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ struct aic7770_identity aic7770_ident_table[] =
ahc_aic7770_EISA_setup
}
};
const int ahc_num_aic7770_devs = NUM_ELEMENTS(aic7770_ident_table);
const int ahc_num_aic7770_devs = ARRAY_SIZE(aic7770_ident_table);

struct aic7770_identity *
aic7770_find_device(uint32_t id)
Expand Down
2 changes: 0 additions & 2 deletions drivers/scsi/aic7xxx/aic79xx.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ struct scb_platform_data;
#define FALSE 0
#endif

#define NUM_ELEMENTS(array) (sizeof(array) / sizeof(*array))

#define ALL_CHANNELS '\0'
#define ALL_TARGETS_MASK 0xFFFF
#define INITIATOR_WILDCARD (~0)
Expand Down
10 changes: 5 additions & 5 deletions drivers/scsi/aic7xxx/aic79xx_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ char *ahd_chip_names[] =
"aic7902",
"aic7901A"
};
static const u_int num_chip_names = NUM_ELEMENTS(ahd_chip_names);
static const u_int num_chip_names = ARRAY_SIZE(ahd_chip_names);

/*
* Hardware error codes.
Expand All @@ -77,7 +77,7 @@ static struct ahd_hard_error_entry ahd_hard_errors[] = {
{ MPARERR, "Scratch or SCB Memory Parity Error" },
{ CIOPARERR, "CIOBUS Parity Error" },
};
static const u_int num_errors = NUM_ELEMENTS(ahd_hard_errors);
static const u_int num_errors = ARRAY_SIZE(ahd_hard_errors);

static struct ahd_phase_table_entry ahd_phase_table[] =
{
Expand All @@ -97,7 +97,7 @@ static struct ahd_phase_table_entry ahd_phase_table[] =
* In most cases we only wish to itterate over real phases, so
* exclude the last element from the count.
*/
static const u_int num_phases = NUM_ELEMENTS(ahd_phase_table) - 1;
static const u_int num_phases = ARRAY_SIZE(ahd_phase_table) - 1;

/* Our Sequencer Program */
#include "aic79xx_seq.h"
Expand Down Expand Up @@ -7259,7 +7259,7 @@ ahd_qinfifo_count(struct ahd_softc *ahd)
return (wrap_qinfifonext - wrap_qinpos);
else
return (wrap_qinfifonext
+ NUM_ELEMENTS(ahd->qinfifo) - wrap_qinpos);
+ ARRAY_SIZE(ahd->qinfifo) - wrap_qinpos);
}

void
Expand Down Expand Up @@ -8619,7 +8619,7 @@ ahd_check_patch(struct ahd_softc *ahd, struct patch **start_patch,
struct patch *last_patch;
u_int num_patches;

num_patches = sizeof(patches)/sizeof(struct patch);
num_patches = ARRAY_SIZE(patches);
last_patch = &patches[num_patches];
cur_patch = *start_patch;

Expand Down
Loading

0 comments on commit 6391a11

Please sign in to comment.