On 29.06.2007 15:04, Uwe Hermann wrote:
Add an ARRAY_SIZE() macro which returns the size of an array, regardless of the data types of the individual array elements.
The macro is defined in lib.h, so code which uses it must include lib.h.
Signed-off-by: Uwe Hermann uwe@hermann-uwe.de
Acked-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Index: southbridge/amd/cs5536/cs5536.c
--- southbridge/amd/cs5536/cs5536.c (Revision 409) +++ southbridge/amd/cs5536/cs5536.c (Arbeitskopie) @@ -93,8 +93,6 @@ {FLASH_TYPE_NONE, 0, 0}, /* CS3, or Flash Device 3 */ };
-#define FlashInitTableLen (sizeof(FlashInitTable)/sizeof(FlashInitTable[0]))
u32 FlashPort[] = { MDD_LBAR_FLSH0, MDD_LBAR_FLSH1, @@ -149,7 +147,7 @@ int numEnabled = 0;
printk(BIOS_DEBUG, "chipset_flash_setup: Start\n");
- for (i = 0; i < FlashInitTableLen; i++) {
- for (i = 0; i < ARRAY_SIZE(FlashInitTable); i++) { if (FlashInitTable[i].fType != FLASH_TYPE_NONE) { printk(BIOS_DEBUG, "Enable CS%d\n", i); /* we need to configure the memory/IO mask */
Index: include/lib.h
--- include/lib.h (Revision 409) +++ include/lib.h (Arbeitskopie) @@ -21,6 +21,12 @@ #ifndef LIB_H #define LIB_H
+/**
- Return the size of a given array, no matter of which data type
- the individual array elements are.
- */
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
int log2(unsigned int n);
void udelay(unsigned int usecs); Index: superio/winbond/w83627hf/superio.c =================================================================== --- superio/winbond/w83627hf/superio.c (Revision 409) +++ superio/winbond/w83627hf/superio.c (Arbeitskopie) @@ -22,6 +22,7 @@ */
#include <io.h> +#include <lib.h> #include <device/device.h> #include <device/pnp.h> #include <console.h> @@ -99,7 +100,7 @@
};
- for(i = 0; i< sizeof(hwm_reg_values)/sizeof(hwm_reg_values[0]); i+=3 ) {
- for (i = 0; i < ARRAY_SIZE(hwm_reg_values); i += 3) { reg = hwm_reg_values[i]; value = pnp_read_index(base, reg); value &= 0xff & hwm_reg_values[i+1];
@@ -207,8 +208,7 @@
static void phase2_setup_scan_bus(struct device *dev) {
- pnp_enable_devices(dev, &ops,
sizeof(pnp_dev_info)/sizeof(pnp_dev_info[0]), pnp_dev_info);
- pnp_enable_devices(dev, &ops, ARRAY_SIZE(pnp_dev_info), pnp_dev_info);
}
static struct device_operations ops = { Index: mainboard/artecgroup/dbe61/initram.c =================================================================== --- mainboard/artecgroup/dbe61/initram.c (Revision 409) +++ mainboard/artecgroup/dbe61/initram.c (Arbeitskopie) @@ -120,7 +120,7 @@ static void dbe61_msr_init(void) { int i;
- for(i = 0; i < sizeof(dbe61_msr)/sizeof(dbe61_msr[0]); i++)
- for (i = 0; i < ARRAY_SIZE(dbe61_msr); i++) wrmsr(dbe61_msr[i].reg, dbe61_msr[i].msr);
}
Index: arch/x86/linuxbios_table.c
--- arch/x86/linuxbios_table.c (Revision 409) +++ arch/x86/linuxbios_table.c (Arbeitskopie) @@ -25,6 +25,7 @@ #include <device/device.h> #include <tables.h> #include <mc146818rtc.h> +#include <lib.h> //#include <cpu/cpu.h> //#include <pirq_routing.h> //#include <smp/mpspec.h> @@ -159,7 +160,7 @@ { LB_TAG_ASSEMBLER, (const u8 *)LINUXBIOS_ASSEMBLER }, }; unsigned int i;
- for(i = 0; i < sizeof(strings)/sizeof(strings[0]); i++) {
- for(i = 0; i < ARRAY_SIZE(strings); i++) { struct lb_string *rec; size_t len; rec = (struct lb_string *)lb_new_record(header);