Skip to content

Commit 87d10f3

Browse files
Tobias KlauserLinus Torvalds
authored andcommitted
[PATCH] drivers/mtd: Use ARRAY_SIZE macro
Use ARRAY_SIZE macro instead of sizeof(x)/sizeof(x[0]) and remove duplicates of the macro. Signed-off-by: Tobias Klauser <tklauser@nuerscht.ch> Cc: Thomas Gleixner <tglx@linutronix.de> Acked-by: David Woodhouse <dwmw2@infradead.org> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent 54af6b4 commit 87d10f3

22 files changed

Lines changed: 31 additions & 45 deletions

‎drivers/mtd/chips/amd_flash.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ static struct mtd_info *amd_flash_probe(struct map_info *map)
664664
printk("%s: Probing for AMD compatible flash...\n", map->name);
665665

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

702702
mtd->eraseregions = kmalloc(sizeof(struct mtd_erase_region_info) *

‎drivers/mtd/chips/jedec_probe.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2035,7 +2035,7 @@ static int jedec_probe_chip(struct map_info *map, __u32 base,
20352035
DEBUG(MTD_DEBUG_LEVEL3,
20362036
"Search for id:(%02x %02x) interleave(%d) type(%d)\n",
20372037
cfi->mfr, cfi->id, cfi_interleave(cfi), cfi->device_type);
2038-
for (i=0; i<sizeof(jedec_table)/sizeof(jedec_table[0]); i++) {
2038+
for (i = 0; i < ARRAY_SIZE(jedec_table); i++) {
20392039
if ( jedec_match( base, map, cfi, &jedec_table[i] ) ) {
20402040
DEBUG( MTD_DEBUG_LEVEL3,
20412041
"MTD %s(): matched device 0x%x,0x%x unlock_addrs: 0x%.4x 0x%.4x\n",

‎drivers/mtd/devices/lart.c‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -581,8 +581,6 @@ static int flash_write (struct mtd_info *mtd,loff_t to,size_t len,size_t *retlen
581581

582582
/***************************************************************************************************/
583583

584-
#define NB_OF(x) (sizeof (x) / sizeof (x[0]))
585-
586584
static struct mtd_info mtd;
587585

588586
static struct mtd_erase_region_info erase_regions[] = {
@@ -640,7 +638,7 @@ int __init lart_flash_init (void)
640638
mtd.flags = MTD_CAP_NORFLASH;
641639
mtd.size = FLASH_BLOCKSIZE_PARAM * FLASH_NUMBLOCKS_16m_PARAM + FLASH_BLOCKSIZE_MAIN * FLASH_NUMBLOCKS_16m_MAIN;
642640
mtd.erasesize = FLASH_BLOCKSIZE_MAIN;
643-
mtd.numeraseregions = NB_OF (erase_regions);
641+
mtd.numeraseregions = ARRAY_SIZE(erase_regions);
644642
mtd.eraseregions = erase_regions;
645643
mtd.erase = flash_erase;
646644
mtd.read = flash_read;
@@ -670,9 +668,9 @@ int __init lart_flash_init (void)
670668
result,mtd.eraseregions[result].numblocks);
671669

672670
#ifdef HAVE_PARTITIONS
673-
printk ("\npartitions = %d\n",NB_OF (lart_partitions));
671+
printk ("\npartitions = %d\n", ARRAY_SIZE(lart_partitions));
674672

675-
for (result = 0; result < NB_OF (lart_partitions); result++)
673+
for (result = 0; result < ARRAY_SIZE(lart_partitions); result++)
676674
printk (KERN_DEBUG
677675
"\n\n"
678676
"lart_partitions[%d].name = %s\n"
@@ -687,7 +685,7 @@ int __init lart_flash_init (void)
687685
#ifndef HAVE_PARTITIONS
688686
result = add_mtd_device (&mtd);
689687
#else
690-
result = add_mtd_partitions (&mtd,lart_partitions,NB_OF (lart_partitions));
688+
result = add_mtd_partitions (&mtd,lart_partitions, ARRAY_SIZE(lart_partitions));
691689
#endif
692690

693691
return (result);

‎drivers/mtd/devices/ms02-nv.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ static int __init ms02nv_init(void)
308308
break;
309309
}
310310

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

‎drivers/mtd/maps/alchemy-flash.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,6 @@ static struct mtd_partition alchemy_partitions[] = {
126126
}
127127
};
128128

129-
#define NB_OF(x) (sizeof(x)/sizeof(x[0]))
130-
131129
static struct mtd_info *mymtd;
132130

133131
int __init alchemy_mtd_init(void)
@@ -154,7 +152,7 @@ int __init alchemy_mtd_init(void)
154152
* Static partition definition selection
155153
*/
156154
parts = alchemy_partitions;
157-
nb_parts = NB_OF(alchemy_partitions);
155+
nb_parts = ARRAY_SIZE(alchemy_partitions);
158156
alchemy_map.size = window_size;
159157

160158
/*

‎drivers/mtd/maps/cfi_flagadm.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ struct mtd_partition flagadm_parts[] = {
8686
}
8787
};
8888

89-
#define PARTITION_COUNT (sizeof(flagadm_parts)/sizeof(struct mtd_partition))
89+
#define PARTITION_COUNT ARRAY_SIZE(flagadm_parts)
9090

9191
static struct mtd_info *mymtd;
9292

‎drivers/mtd/maps/dbox2-flash.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ static struct mtd_partition partition_info[]= {
5757
}
5858
};
5959

60-
#define NUM_PARTITIONS (sizeof(partition_info) / sizeof(partition_info[0]))
60+
#define NUM_PARTITIONS ARRAY_SIZE(partition_info)
6161

6262
#define WINDOW_ADDR 0x10000000
6363
#define WINDOW_SIZE 0x800000

‎drivers/mtd/maps/dilnetpc.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ static struct mtd_partition partition_info[]=
300300
},
301301
};
302302

303-
#define NUM_PARTITIONS (sizeof(partition_info)/sizeof(partition_info[0]))
303+
#define NUM_PARTITIONS ARRAY_SIZE(partition_info)
304304

305305
static struct mtd_info *mymtd;
306306
static struct mtd_info *lowlvl_parts[NUM_PARTITIONS];
@@ -345,7 +345,7 @@ static struct mtd_partition higlvl_partition_info[]=
345345
},
346346
};
347347

348-
#define NUM_HIGHLVL_PARTITIONS (sizeof(higlvl_partition_info)/sizeof(partition_info[0]))
348+
#define NUM_HIGHLVL_PARTITIONS ARRAY_SIZE(higlvl_partition_info)
349349

350350

351351
static int dnp_adnp_probe(void)

‎drivers/mtd/maps/dmv182.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ static struct mtd_info *this_mtd;
9999
static int __init init_svme182(void)
100100
{
101101
struct mtd_partition *partitions;
102-
int num_parts = sizeof(svme182_partitions) / sizeof(struct mtd_partition);
102+
int num_parts = ARRAY_SIZE(svme182_partitions);
103103

104104
partitions = svme182_partitions;
105105

‎drivers/mtd/maps/h720x-flash.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static struct mtd_partition h720x_partitions[] = {
5959
}
6060
};
6161

62-
#define NUM_PARTITIONS (sizeof(h720x_partitions)/sizeof(h720x_partitions[0]))
62+
#define NUM_PARTITIONS ARRAY_SIZE(h720x_partitions)
6363

6464
static int nr_mtd_parts;
6565
static struct mtd_partition *mtd_parts;

0 commit comments

Comments
 (0)