Changeset 3624

Show
Ignore:
Timestamp:
10/01/08 14:52:52 (3 months ago)
Author:
hailfinger
Message:

The ARRAY_SIZE macro is convenient, yet mostly unused. Switch lots of
code to use it. That makes the code more readable and also less
error-prone.

Abuild tested.

Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@…>
Acked-by: Peter Stuge <peter@…>

Location:
trunk/coreboot-v2/src
Files:
166 modified

Legend:

Unmodified
Added
Removed
  • trunk/coreboot-v2/src/arch/i386/boot/acpi.c

    r3053 r3624  
    4545        int i; 
    4646         
    47         int entries_num = sizeof(rsdt->entry)/sizeof(rsdt->entry[0]); 
     47        int entries_num = ARRAY_SIZE(rsdt->entry); 
    4848         
    4949        for (i=0; i<entries_num; i++) { 
  • trunk/coreboot-v2/src/arch/i386/boot/coreboot_table.c

    r3588 r3624  
    185185        }; 
    186186        unsigned int i; 
    187         for(i = 0; i < sizeof(strings)/sizeof(strings[0]); i++) { 
     187        for(i = 0; i < ARRAY_SIZE(strings); i++) { 
    188188                struct lb_string *rec; 
    189189                size_t len; 
  • trunk/coreboot-v2/src/arch/i386/lib/cpu.c

    r2590 r3624  
    124124        const char *name; 
    125125        name = "<invalid cpu vendor>"; 
    126         if ((vendor < (sizeof(x86_vendor_name)/sizeof(x86_vendor_name[0]))) && 
     126        if ((vendor < (ARRAY_SIZE(x86_vendor_name))) && 
    127127                (x86_vendor_name[vendor] != 0))  
    128128        { 
     
    186186        } 
    187187        cpu->vendor = X86_VENDOR_UNKNOWN; 
    188         for(i = 0; i < sizeof(x86_vendors)/sizeof(x86_vendors[0]); i++) { 
     188        for(i = 0; i < ARRAY_SIZE(x86_vendors); i++) { 
    189189                if (memcmp(vendor_name, x86_vendors[i].name, 12) == 0) { 
    190190                        cpu->vendor = x86_vendors[i].vendor; 
  • trunk/coreboot-v2/src/arch/i386/lib/exception.c

    r1786 r3624  
    378378        gdb_stub_registers[PS] = info->eflags; 
    379379        signo = GDB_UNKNOWN; 
    380         if (info->vector < sizeof(exception_to_signal)/sizeof(exception_to_signal[0])) { 
     380        if (info->vector < ARRAY_SIZE(exception_to_signal)) { 
    381381                signo = exception_to_signal[info->vector]; 
    382382        } 
  • trunk/coreboot-v2/src/arch/i386/smp/ioapic.c

    r1560 r3624  
    6868        l[4] = 1; 
    6969#endif /* i786 */ 
    70         for (i = 0; i < sizeof(ioapicregvalues) / sizeof(ioapicregvalues[0]); 
     70        for (i = 0; i < ARRAY_SIZE(ioapicregvalues); 
    7171             i++, a++) { 
    7272                l[0] = (a->reg * 2) + 0x10; 
  • trunk/coreboot-v2/src/arch/ppc/boot/coreboot_table.c

    r3057 r3624  
    117117        }; 
    118118        unsigned int i; 
    119         for(i = 0; i < sizeof(strings)/sizeof(strings[0]); i++) { 
     119        for(i = 0; i < ARRAY_SIZE(strings); i++) { 
    120120                struct lb_string *rec; 
    121121                size_t len; 
  • trunk/coreboot-v2/src/cpu/amd/model_10xxx/init_cpus.c

    r3435 r3624  
    523523 
    524524        /* copy the default resource map from node 0 */ 
    525         for(i = 0; i < sizeof(pci_reg)/sizeof(pci_reg[0]); i++) { 
     525        for(i = 0; i < ARRAY_SIZE(pci_reg); i++) { 
    526526                u32 value; 
    527527                u16 reg; 
     
    853853        platform = get_platform_type(); 
    854854 
    855         for(i = 0; i < sizeof(fam10_msr_default)/sizeof(fam10_msr_default[0]); i++) { 
     855        for(i = 0; i < ARRAY_SIZE(fam10_msr_default); i++) { 
    856856                if ((fam10_msr_default[i].revision & revision) && 
    857857                    (fam10_msr_default[i].platform & platform)) { 
     
    890890        AMD_SetupPSIVID_d(platform, node);      /* Set PSIVID offset which is not table driven */ 
    891891 
    892         for(i = 0; i < sizeof(fam10_pci_default)/sizeof(fam10_pci_default[0]); i++) { 
     892        for(i = 0; i < ARRAY_SIZE(fam10_pci_default); i++) { 
    893893                if ((fam10_pci_default[i].revision & revision) && 
    894894                    (fam10_pci_default[i].platform & platform)) { 
     
    904904        } 
    905905 
    906         for(i = 0; i < sizeof(fam10_htphy_default)/sizeof(fam10_htphy_default[0]); i++) { 
     906        for(i = 0; i < ARRAY_SIZE(fam10_htphy_default); i++) { 
    907907                if ((fam10_htphy_default[i].revision & revision) && 
    908908                    (fam10_htphy_default[i].platform & platform)) { 
  • trunk/coreboot-v2/src/cpu/amd/sc520/sc520.c

    r3053 r3624  
    152152                int idx; 
    153153#if 0 
    154                 for(rambits = 0, i = 0; i < sizeof(ramregs)/sizeof(ramregs[0]); i++) { 
     154                for(rambits = 0, i = 0; i < ARRAY_SIZE(ramregs); i++) { 
    155155                        unsigned char reg; 
    156156                        reg = pci_read_config8(mc_dev, ramregs[i]); 
  • trunk/coreboot-v2/src/cpu/emulation/qemu-x86/northbridge.c

    r3509 r3624  
    8181                int i, idx; 
    8282 
    83                 for(rambits = 0, i = 0; i < sizeof(ramregs)/sizeof(ramregs[0]); i++) { 
     83                for(rambits = 0, i = 0; i < ARRAY_SIZE(ramregs); i++) { 
    8484                        unsigned char reg; 
    8585                        reg = pci_read_config8(mc_dev, ramregs[i]); 
  • trunk/coreboot-v2/src/drivers/ati/ragexl/xlinit.c

    r3053 r3624  
    282282        aty_st_le32(0xFC, 0x00000000, info); 
    283283 
    284         for (i=0; i<sizeof(lcd_tbl)/sizeof(lcd_tbl_t); i++) { 
     284        for (i=0; i<ARRAY_SIZE(lcd_tbl); i++) { 
    285285                aty_st_lcd(lcd_tbl[i].lcd_reg, lcd_tbl[i].val, info); 
    286286        } 
     
    548548        type = chip_id & CFG_CHIP_TYPE; 
    549549        rev = (chip_id & CFG_CHIP_REV)>>24; 
    550         for (j = 0; j < (sizeof(aty_chips)/sizeof(*aty_chips)); j++) 
     550        for (j = 0; j < ARRAY_SIZE(aty_chips); j++) 
    551551                if (type == aty_chips[j].chip_type && 
    552552                        (rev & aty_chips[j].rev_mask) == aty_chips[j].rev_val) { 
  • trunk/coreboot-v2/src/mainboard/a-trend/atc-6220/auto.c

    r3052 r3624  
    2727#include <arch/romcc_io.h> 
    2828#include <arch/hlt.h> 
     29#include <stdlib.h> 
    2930#include "pc80/serial.c" 
    3031#include "arch/i386/lib/console.c" 
     
    6869        enable_smbus(); 
    6970        /* dump_spd_registers(&memctrl[0]); */ 
    70         sdram_initialize(sizeof(memctrl) / sizeof(memctrl[0]), memctrl); 
     71        sdram_initialize(ARRAY_SIZE(memctrl), memctrl); 
    7172        /* ram_check(0, 640 * 1024); */ 
    7273} 
  • trunk/coreboot-v2/src/mainboard/agami/aruma/auto.c

    r2120 r3624  
    77#include <cpu/x86/lapic.h> 
    88#include <arch/cpu.h> 
     9#include <stdlib.h> 
    910#include "option_table.h" 
    1011#include "pc80/mc146818rtc_early.c" 
     
    172173 
    173174        memreset_setup(); 
    174         sdram_initialize(sizeof(cpu)/sizeof(cpu[0]), cpu); 
     175        sdram_initialize(ARRAY_SIZE(cpu), cpu); 
    175176 
    176177#if 0 
  • trunk/coreboot-v2/src/mainboard/agami/aruma/get_bus_conf.c

    r2154 r3624  
    44#include <string.h> 
    55#include <stdint.h> 
     6#include <stdlib.h> 
    67#if CONFIG_LOGICAL_CPUS==1 
    78#include <cpu/amd/dualcore.h> 
     
    6364        get_bus_conf_done = 1; 
    6465 
    65         hc_possible_num = sizeof(pci1234) / sizeof(pci1234[0]); 
     66        hc_possible_num = ARRAY_SIZE(pci1234); 
    6667 
    6768        get_sblk_pci1234(); 
  • trunk/coreboot-v2/src/mainboard/agami/aruma/resourcemap.c

    r2606 r3624  
    266266        }; 
    267267        int max; 
    268         max = sizeof(register_values)/sizeof(register_values[0]); 
     268        max = ARRAY_SIZE(register_values); 
    269269        setup_resource_map(register_values, max); 
    270270} 
  • trunk/coreboot-v2/src/mainboard/amd/dbm690t/get_bus_conf.c

    r3590 r3624  
    2323#include <string.h> 
    2424#include <stdint.h> 
     25#include <stdlib.h> 
    2526#if CONFIG_LOGICAL_CPUS==1 
    2627#include <cpu/amd/dualcore.h> 
     
    7374        get_bus_conf_done = 1; 
    7475 
    75         sysconf.hc_possible_num = sizeof(pci1234x) / sizeof(pci1234x[0]); 
     76        sysconf.hc_possible_num = ARRAY_SIZE(pci1234x); 
    7677        for (i = 0; i < sysconf.hc_possible_num; i++) { 
    7778                sysconf.pci1234[i] = pci1234x[i]; 
  • trunk/coreboot-v2/src/mainboard/amd/dbm690t/resourcemap.c

    r3590 r3624  
    274274 
    275275        int max; 
    276         max = sizeof(register_values) / sizeof(register_values[0]); 
     276        max = ARRAY_SIZE(register_values); 
    277277        setup_resource_map(register_values, max); 
    278278} 
  • trunk/coreboot-v2/src/mainboard/amd/serengeti_cheetah/get_bus_conf.c

    r2439 r3624  
    1010#include <cpu/amd/amdk8_sysconf.h> 
    1111 
     12#include <stdlib.h> 
    1213#include "mb_sysconf.h" 
    1314 
     
    9192        m = sysconf.mb; 
    9293 
    93         sysconf.hc_possible_num = sizeof(pci1234x)/sizeof(pci1234x[0]);  
     94        sysconf.hc_possible_num = ARRAY_SIZE(pci1234x);  
    9495        for(i=0;i<sysconf.hc_possible_num; i++) { 
    9596                sysconf.pci1234[i] = pci1234x[i]; 
  • trunk/coreboot-v2/src/mainboard/amd/serengeti_cheetah/resourcemap.c

    r2439 r3624  
    259259 
    260260        int max; 
    261         max