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

+31
-45
lines changed

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;

drivers/mtd/maps/netsc520.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ static struct mtd_partition partition_info[]={
7676
.size = 0x80000
7777
},
7878
};
79-
#define NUM_PARTITIONS (sizeof(partition_info)/sizeof(partition_info[0]))
79+
#define NUM_PARTITIONS ARRAY_SIZE(partition_info)
8080

8181
#define WINDOW_SIZE 0x00100000
8282
#define WINDOW_ADDR 0x00200000
@@ -88,7 +88,7 @@ static struct map_info netsc520_map = {
8888
.phys = WINDOW_ADDR,
8989
};
9090

91-
#define NUM_FLASH_BANKS (sizeof(netsc520_map)/sizeof(struct map_info))
91+
#define NUM_FLASH_BANKS ARRAY_SIZE(netsc520_map)
9292

9393
static struct mtd_info *mymtd;
9494

drivers/mtd/maps/nettel.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ static struct mtd_partition nettel_amd_partitions[] = {
128128
}
129129
};
130130

131-
#define NUM_AMD_PARTITIONS \
132-
(sizeof(nettel_amd_partitions)/sizeof(nettel_amd_partitions[0]))
131+
#define NUM_AMD_PARTITIONS ARRAY_SIZE(nettel_amd_partitions)
133132

134133
/****************************************************************************/
135134

drivers/mtd/maps/ocotea.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ static struct mtd_partition ocotea_large_partitions[] = {
5858
}
5959
};
6060

61-
#define NB_OF(x) (sizeof(x)/sizeof(x[0]))
62-
6361
int __init init_ocotea(void)
6462
{
6563
u8 fpga0_reg;
@@ -97,7 +95,7 @@ int __init init_ocotea(void)
9795
if (flash) {
9896
flash->owner = THIS_MODULE;
9997
add_mtd_partitions(flash, ocotea_small_partitions,
100-
NB_OF(ocotea_small_partitions));
98+
ARRAY_SIZE(ocotea_small_partitions));
10199
} else {
102100
printk("map probe failed for flash\n");
103101
return -ENXIO;
@@ -118,7 +116,7 @@ int __init init_ocotea(void)
118116
if (flash) {
119117
flash->owner = THIS_MODULE;
120118
add_mtd_partitions(flash, ocotea_large_partitions,
121-
NB_OF(ocotea_large_partitions));
119+
ARRAY_SIZE(ocotea_large_partitions));
122120
} else {
123121
printk("map probe failed for flash\n");
124122
return -ENXIO;

drivers/mtd/maps/pcmciamtd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ static void pcmciamtd_config(dev_link_t *link)
616616
} else if(mem_type == 2) {
617617
mtd = do_map_probe("map_rom", &dev->pcmcia_map);
618618
} else {
619-
for(i = 0; i < sizeof(probes) / sizeof(char *); i++) {
619+
for(i = 0; i < ARRAY_SIZE(probes); i++) {
620620
DEBUG(1, "Trying %s", probes[i]);
621621
mtd = do_map_probe(probes[i], &dev->pcmcia_map);
622622
if(mtd)

drivers/mtd/maps/redwood.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,7 @@ struct map_info redwood_flash_map = {
121121
};
122122

123123

124-
#define NUM_REDWOOD_FLASH_PARTITIONS \
125-
(sizeof(redwood_flash_partitions)/sizeof(redwood_flash_partitions[0]))
124+
#define NUM_REDWOOD_FLASH_PARTITIONS ARRAY_SIZE(redwood_flash_partitions)
126125

127126
static struct mtd_info *redwood_mtd;
128127

drivers/mtd/maps/sbc8240.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ static struct map_info sbc8240_map[2] = {
6666
}
6767
};
6868

69-
#define NUM_FLASH_BANKS (sizeof(sbc8240_map) / sizeof(struct map_info))
69+
#define NUM_FLASH_BANKS ARRAY_SIZE(sbc8240_map)
7070

7171
/*
7272
* The following defines the partition layout of SBC8240 boards.
@@ -125,8 +125,6 @@ static struct mtd_partition sbc8240_fs_partitions [] = {
125125
}
126126
};
127127

128-
#define NB_OF(x) (sizeof (x) / sizeof (x[0]))
129-
130128
/* trivial struct to describe partition information */
131129
struct mtd_part_def
132130
{
@@ -190,10 +188,10 @@ int __init init_sbc8240_mtd (void)
190188
#ifdef CONFIG_MTD_PARTITIONS
191189
sbc8240_part_banks[0].mtd_part = sbc8240_uboot_partitions;
192190
sbc8240_part_banks[0].type = "static image";
193-
sbc8240_part_banks[0].nums = NB_OF(sbc8240_uboot_partitions);
191+
sbc8240_part_banks[0].nums = ARRAY_SIZE(sbc8240_uboot_partitions);
194192
sbc8240_part_banks[1].mtd_part = sbc8240_fs_partitions;
195193
sbc8240_part_banks[1].type = "static file system";
196-
sbc8240_part_banks[1].nums = NB_OF(sbc8240_fs_partitions);
194+
sbc8240_part_banks[1].nums = ARRAY_SIZE(sbc8240_fs_partitions);
197195

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

drivers/mtd/maps/sc520cdp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ static struct map_info sc520cdp_map[] = {
107107
},
108108
};
109109

110-
#define NUM_FLASH_BANKS (sizeof(sc520cdp_map)/sizeof(struct map_info))
110+
#define NUM_FLASH_BANKS ARRAY_SIZE(sc520cdp_map)
111111

112112
static struct mtd_info *mymtd[NUM_FLASH_BANKS];
113113
static struct mtd_info *merged_mtd;

drivers/mtd/maps/scx200_docflash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static struct mtd_partition partition_info[] = {
7070
.size = 0x80000
7171
},
7272
};
73-
#define NUM_PARTITIONS (sizeof(partition_info)/sizeof(partition_info[0]))
73+
#define NUM_PARTITIONS ARRAY_SIZE(partition_info)
7474
#endif
7575

7676

drivers/mtd/maps/sharpsl-flash.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ static struct mtd_partition sharpsl_partitions[1] = {
4949
}
5050
};
5151

52-
#define NB_OF(x) (sizeof(x)/sizeof(x[0]))
53-
5452
int __init init_sharpsl(void)
5553
{
5654
struct mtd_partition *parts;
@@ -92,7 +90,7 @@ int __init init_sharpsl(void)
9290
}
9391

9492
parts = sharpsl_partitions;
95-
nb_parts = NB_OF(sharpsl_partitions);
93+
nb_parts = ARRAY_SIZE(sharpsl_partitions);
9694

9795
printk(KERN_NOTICE "Using %s partision definition\n", part_type);
9896
add_mtd_partitions(mymtd, parts, nb_parts);

drivers/mtd/maps/ts5500_flash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static struct mtd_partition ts5500_partitions[] = {
6464
}
6565
};
6666

67-
#define NUM_PARTITIONS (sizeof(ts5500_partitions)/sizeof(struct mtd_partition))
67+
#define NUM_PARTITIONS ARRAY_SIZE(ts5500_partitions)
6868

6969
static struct mtd_info *mymtd;
7070

drivers/mtd/maps/uclinux.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ struct mtd_partition uclinux_romfs[] = {
3737
{ .name = "ROMfs" }
3838
};
3939

40-
#define NUM_PARTITIONS (sizeof(uclinux_romfs) / sizeof(uclinux_romfs[0]))
40+
#define NUM_PARTITIONS ARRAY_SIZE(uclinux_romfs)
4141

4242
/****************************************************************************/
4343

drivers/mtd/nand/au1550nd.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ static const struct mtd_partition partition_info[] = {
5555
.size = MTDPART_SIZ_FULL
5656
}
5757
};
58-
#define NB_OF(x) (sizeof(x)/sizeof(x[0]))
59-
6058

6159
/**
6260
* au_read_byte - read one byte from the chip
@@ -462,7 +460,7 @@ int __init au1xxx_nand_init (void)
462460
}
463461

464462
/* Register the partitions */
465-
add_mtd_partitions(au1550_mtd, partition_info, NB_OF(partition_info));
463+
add_mtd_partitions(au1550_mtd, partition_info, ARRAY_SIZE(partition_info));
466464

467465
return 0;
468466

0 commit comments

Comments
 (0)