Skip to content

Commit

Permalink
[PATCH] drivers/mtd: 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]>
Cc: Thomas Gleixner <[email protected]>
Acked-by: David Woodhouse <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Tobias Klauser authored and Linus Torvalds committed Mar 31, 2006
1 parent 54af6b4 commit 87d10f3
Show file tree
Hide file tree
Showing 22 changed files with 31 additions and 45 deletions.
4 changes: 2 additions & 2 deletions drivers/mtd/chips/amd_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ static struct mtd_info *amd_flash_probe(struct map_info *map)
printk("%s: Probing for AMD compatible flash...\n", map->name);

if ((table_pos[0] = probe_new_chip(mtd, 0, NULL, &temp, table,
sizeof(table)/sizeof(table[0])))
ARRAY_SIZE(table)))
== -1) {
printk(KERN_WARNING
"%s: Found no AMD compatible device at location zero\n",
Expand Down Expand Up @@ -696,7 +696,7 @@ static struct mtd_info *amd_flash_probe(struct map_info *map)
base += (1 << temp.chipshift)) {
int numchips = temp.numchips;
table_pos[numchips] = probe_new_chip(mtd, base, chips,
&temp, table, sizeof(table)/sizeof(table[0]));
&temp, table, ARRAY_SIZE(table));
}

mtd->eraseregions = kmalloc(sizeof(struct mtd_erase_region_info) *
Expand Down
2 changes: 1 addition & 1 deletion drivers/mtd/chips/jedec_probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -2035,7 +2035,7 @@ static int jedec_probe_chip(struct map_info *map, __u32 base,
DEBUG(MTD_DEBUG_LEVEL3,
"Search for id:(%02x %02x) interleave(%d) type(%d)\n",
cfi->mfr, cfi->id, cfi_interleave(cfi), cfi->device_type);
for (i=0; i<sizeof(jedec_table)/sizeof(jedec_table[0]); i++) {
for (i = 0; i < ARRAY_SIZE(jedec_table); i++) {
if ( jedec_match( base, map, cfi, &jedec_table[i] ) ) {
DEBUG( MTD_DEBUG_LEVEL3,
"MTD %s(): matched device 0x%x,0x%x unlock_addrs: 0x%.4x 0x%.4x\n",
Expand Down
10 changes: 4 additions & 6 deletions drivers/mtd/devices/lart.c
Original file line number Diff line number Diff line change
Expand Up @@ -581,8 +581,6 @@ static int flash_write (struct mtd_info *mtd,loff_t to,size_t len,size_t *retlen

/***************************************************************************************************/

#define NB_OF(x) (sizeof (x) / sizeof (x[0]))

static struct mtd_info mtd;

static struct mtd_erase_region_info erase_regions[] = {
Expand Down Expand Up @@ -640,7 +638,7 @@ int __init lart_flash_init (void)
mtd.flags = MTD_CAP_NORFLASH;
mtd.size = FLASH_BLOCKSIZE_PARAM * FLASH_NUMBLOCKS_16m_PARAM + FLASH_BLOCKSIZE_MAIN * FLASH_NUMBLOCKS_16m_MAIN;
mtd.erasesize = FLASH_BLOCKSIZE_MAIN;
mtd.numeraseregions = NB_OF (erase_regions);
mtd.numeraseregions = ARRAY_SIZE(erase_regions);
mtd.eraseregions = erase_regions;
mtd.erase = flash_erase;
mtd.read = flash_read;
Expand Down Expand Up @@ -670,9 +668,9 @@ int __init lart_flash_init (void)
result,mtd.eraseregions[result].numblocks);

#ifdef HAVE_PARTITIONS
printk ("\npartitions = %d\n",NB_OF (lart_partitions));
printk ("\npartitions = %d\n", ARRAY_SIZE(lart_partitions));

for (result = 0; result < NB_OF (lart_partitions); result++)
for (result = 0; result < ARRAY_SIZE(lart_partitions); result++)
printk (KERN_DEBUG
"\n\n"
"lart_partitions[%d].name = %s\n"
Expand All @@ -687,7 +685,7 @@ int __init lart_flash_init (void)
#ifndef HAVE_PARTITIONS
result = add_mtd_device (&mtd);
#else
result = add_mtd_partitions (&mtd,lart_partitions,NB_OF (lart_partitions));
result = add_mtd_partitions (&mtd,lart_partitions, ARRAY_SIZE(lart_partitions));
#endif

return (result);
Expand Down
2 changes: 1 addition & 1 deletion drivers/mtd/devices/ms02-nv.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ static int __init ms02nv_init(void)
break;
}

for (i = 0; i < (sizeof(ms02nv_addrs) / sizeof(*ms02nv_addrs)); i++)
for (i = 0; i < ARRAY_SIZE(ms02nv_addrs); i++)
if (!ms02nv_init_one(ms02nv_addrs[i] << stride))
count++;

Expand Down
4 changes: 1 addition & 3 deletions drivers/mtd/maps/alchemy-flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,6 @@ static struct mtd_partition alchemy_partitions[] = {
}
};

#define NB_OF(x) (sizeof(x)/sizeof(x[0]))

static struct mtd_info *mymtd;

int __init alchemy_mtd_init(void)
Expand All @@ -154,7 +152,7 @@ int __init alchemy_mtd_init(void)
* Static partition definition selection
*/
parts = alchemy_partitions;
nb_parts = NB_OF(alchemy_partitions);
nb_parts = ARRAY_SIZE(alchemy_partitions);
alchemy_map.size = window_size;

/*
Expand Down
2 changes: 1 addition & 1 deletion drivers/mtd/maps/cfi_flagadm.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ struct mtd_partition flagadm_parts[] = {
}
};

#define PARTITION_COUNT (sizeof(flagadm_parts)/sizeof(struct mtd_partition))
#define PARTITION_COUNT ARRAY_SIZE(flagadm_parts)

static struct mtd_info *mymtd;

Expand Down
2 changes: 1 addition & 1 deletion drivers/mtd/maps/dbox2-flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static struct mtd_partition partition_info[]= {
}
};

#define NUM_PARTITIONS (sizeof(partition_info) / sizeof(partition_info[0]))
#define NUM_PARTITIONS ARRAY_SIZE(partition_info)

#define WINDOW_ADDR 0x10000000
#define WINDOW_SIZE 0x800000
Expand Down
4 changes: 2 additions & 2 deletions drivers/mtd/maps/dilnetpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ static struct mtd_partition partition_info[]=
},
};

#define NUM_PARTITIONS (sizeof(partition_info)/sizeof(partition_info[0]))
#define NUM_PARTITIONS ARRAY_SIZE(partition_info)

static struct mtd_info *mymtd;
static struct mtd_info *lowlvl_parts[NUM_PARTITIONS];
Expand Down Expand Up @@ -345,7 +345,7 @@ static struct mtd_partition higlvl_partition_info[]=
},
};

#define NUM_HIGHLVL_PARTITIONS (sizeof(higlvl_partition_info)/sizeof(partition_info[0]))
#define NUM_HIGHLVL_PARTITIONS ARRAY_SIZE(higlvl_partition_info)


static int dnp_adnp_probe(void)
Expand Down
2 changes: 1 addition & 1 deletion drivers/mtd/maps/dmv182.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ static struct mtd_info *this_mtd;
static int __init init_svme182(void)
{
struct mtd_partition *partitions;
int num_parts = sizeof(svme182_partitions) / sizeof(struct mtd_partition);
int num_parts = ARRAY_SIZE(svme182_partitions);

partitions = svme182_partitions;

Expand Down
2 changes: 1 addition & 1 deletion drivers/mtd/maps/h720x-flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static struct mtd_partition h720x_partitions[] = {
}
};

#define NUM_PARTITIONS (sizeof(h720x_partitions)/sizeof(h720x_partitions[0]))
#define NUM_PARTITIONS ARRAY_SIZE(h720x_partitions)

static int nr_mtd_parts;
static struct mtd_partition *mtd_parts;
Expand Down
4 changes: 2 additions & 2 deletions drivers/mtd/maps/netsc520.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ static struct mtd_partition partition_info[]={
.size = 0x80000
},
};
#define NUM_PARTITIONS (sizeof(partition_info)/sizeof(partition_info[0]))
#define NUM_PARTITIONS ARRAY_SIZE(partition_info)

#define WINDOW_SIZE 0x00100000
#define WINDOW_ADDR 0x00200000
Expand All @@ -88,7 +88,7 @@ static struct map_info netsc520_map = {
.phys = WINDOW_ADDR,
};

#define NUM_FLASH_BANKS (sizeof(netsc520_map)/sizeof(struct map_info))
#define NUM_FLASH_BANKS ARRAY_SIZE(netsc520_map)

static struct mtd_info *mymtd;

Expand Down
3 changes: 1 addition & 2 deletions drivers/mtd/maps/nettel.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ static struct mtd_partition nettel_amd_partitions[] = {
}
};

#define NUM_AMD_PARTITIONS \
(sizeof(nettel_amd_partitions)/sizeof(nettel_amd_partitions[0]))
#define NUM_AMD_PARTITIONS ARRAY_SIZE(nettel_amd_partitions)

/****************************************************************************/

Expand Down
6 changes: 2 additions & 4 deletions drivers/mtd/maps/ocotea.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ static struct mtd_partition ocotea_large_partitions[] = {
}
};

#define NB_OF(x) (sizeof(x)/sizeof(x[0]))

int __init init_ocotea(void)
{
u8 fpga0_reg;
Expand Down Expand Up @@ -97,7 +95,7 @@ int __init init_ocotea(void)
if (flash) {
flash->owner = THIS_MODULE;
add_mtd_partitions(flash, ocotea_small_partitions,
NB_OF(ocotea_small_partitions));
ARRAY_SIZE(ocotea_small_partitions));
} else {
printk("map probe failed for flash\n");
return -ENXIO;
Expand All @@ -118,7 +116,7 @@ int __init init_ocotea(void)
if (flash) {
flash->owner = THIS_MODULE;
add_mtd_partitions(flash, ocotea_large_partitions,
NB_OF(ocotea_large_partitions));
ARRAY_SIZE(ocotea_large_partitions));
} else {
printk("map probe failed for flash\n");
return -ENXIO;
Expand Down
2 changes: 1 addition & 1 deletion drivers/mtd/maps/pcmciamtd.c
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ static void pcmciamtd_config(dev_link_t *link)
} else if(mem_type == 2) {
mtd = do_map_probe("map_rom", &dev->pcmcia_map);
} else {
for(i = 0; i < sizeof(probes) / sizeof(char *); i++) {
for(i = 0; i < ARRAY_SIZE(probes); i++) {
DEBUG(1, "Trying %s", probes[i]);
mtd = do_map_probe(probes[i], &dev->pcmcia_map);
if(mtd)
Expand Down
3 changes: 1 addition & 2 deletions drivers/mtd/maps/redwood.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ struct map_info redwood_flash_map = {
};


#define NUM_REDWOOD_FLASH_PARTITIONS \
(sizeof(redwood_flash_partitions)/sizeof(redwood_flash_partitions[0]))
#define NUM_REDWOOD_FLASH_PARTITIONS ARRAY_SIZE(redwood_flash_partitions)

static struct mtd_info *redwood_mtd;

Expand Down
8 changes: 3 additions & 5 deletions drivers/mtd/maps/sbc8240.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ static struct map_info sbc8240_map[2] = {
}
};

#define NUM_FLASH_BANKS (sizeof(sbc8240_map) / sizeof(struct map_info))
#define NUM_FLASH_BANKS ARRAY_SIZE(sbc8240_map)

/*
* The following defines the partition layout of SBC8240 boards.
Expand Down Expand Up @@ -125,8 +125,6 @@ static struct mtd_partition sbc8240_fs_partitions [] = {
}
};

#define NB_OF(x) (sizeof (x) / sizeof (x[0]))

/* trivial struct to describe partition information */
struct mtd_part_def
{
Expand Down Expand Up @@ -190,10 +188,10 @@ int __init init_sbc8240_mtd (void)
#ifdef CONFIG_MTD_PARTITIONS
sbc8240_part_banks[0].mtd_part = sbc8240_uboot_partitions;
sbc8240_part_banks[0].type = "static image";
sbc8240_part_banks[0].nums = NB_OF(sbc8240_uboot_partitions);
sbc8240_part_banks[0].nums = ARRAY_SIZE(sbc8240_uboot_partitions);
sbc8240_part_banks[1].mtd_part = sbc8240_fs_partitions;
sbc8240_part_banks[1].type = "static file system";
sbc8240_part_banks[1].nums = NB_OF(sbc8240_fs_partitions);
sbc8240_part_banks[1].nums = ARRAY_SIZE(sbc8240_fs_partitions);

for (i = 0; i < NUM_FLASH_BANKS; i++) {

Expand Down
2 changes: 1 addition & 1 deletion drivers/mtd/maps/sc520cdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ static struct map_info sc520cdp_map[] = {
},
};

#define NUM_FLASH_BANKS (sizeof(sc520cdp_map)/sizeof(struct map_info))
#define NUM_FLASH_BANKS ARRAY_SIZE(sc520cdp_map)

static struct mtd_info *mymtd[NUM_FLASH_BANKS];
static struct mtd_info *merged_mtd;
Expand Down
2 changes: 1 addition & 1 deletion drivers/mtd/maps/scx200_docflash.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static struct mtd_partition partition_info[] = {
.size = 0x80000
},
};
#define NUM_PARTITIONS (sizeof(partition_info)/sizeof(partition_info[0]))
#define NUM_PARTITIONS ARRAY_SIZE(partition_info)
#endif


Expand Down
4 changes: 1 addition & 3 deletions drivers/mtd/maps/sharpsl-flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ static struct mtd_partition sharpsl_partitions[1] = {
}
};

#define NB_OF(x) (sizeof(x)/sizeof(x[0]))

int __init init_sharpsl(void)
{
struct mtd_partition *parts;
Expand Down Expand Up @@ -92,7 +90,7 @@ int __init init_sharpsl(void)
}

parts = sharpsl_partitions;
nb_parts = NB_OF(sharpsl_partitions);
nb_parts = ARRAY_SIZE(sharpsl_partitions);

printk(KERN_NOTICE "Using %s partision definition\n", part_type);
add_mtd_partitions(mymtd, parts, nb_parts);
Expand Down
2 changes: 1 addition & 1 deletion drivers/mtd/maps/ts5500_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ static struct mtd_partition ts5500_partitions[] = {
}
};

#define NUM_PARTITIONS (sizeof(ts5500_partitions)/sizeof(struct mtd_partition))
#define NUM_PARTITIONS ARRAY_SIZE(ts5500_partitions)

static struct mtd_info *mymtd;

Expand Down
2 changes: 1 addition & 1 deletion drivers/mtd/maps/uclinux.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct mtd_partition uclinux_romfs[] = {
{ .name = "ROMfs" }
};

#define NUM_PARTITIONS (sizeof(uclinux_romfs) / sizeof(uclinux_romfs[0]))
#define NUM_PARTITIONS ARRAY_SIZE(uclinux_romfs)

/****************************************************************************/

Expand Down
4 changes: 1 addition & 3 deletions drivers/mtd/nand/au1550nd.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ static const struct mtd_partition partition_info[] = {
.size = MTDPART_SIZ_FULL
}
};
#define NB_OF(x) (sizeof(x)/sizeof(x[0]))


/**
* au_read_byte - read one byte from the chip
Expand Down Expand Up @@ -462,7 +460,7 @@ int __init au1xxx_nand_init (void)
}

/* Register the partitions */
add_mtd_partitions(au1550_mtd, partition_info, NB_OF(partition_info));
add_mtd_partitions(au1550_mtd, partition_info, ARRAY_SIZE(partition_info));

return 0;

Expand Down

0 comments on commit 87d10f3

Please sign in to comment.