Commit b1503cda1e78cad4dca522ddbb4c69f4c6869bcd

Authored by malc
1 parent 5626b017

Use the ARRAY_SIZE() macro where appropriate.

Change from v1:
  Avoid changing the existing coding style in certain files.

Signed-off-by: Stuart Brady <stuart.brady@gmail.com>

git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6120 c046a42c-6fe2-441c-8c8c-71466251a162
audio/audio.c
... ... @@ -1556,7 +1556,7 @@ void AUD_help (void)
1556 1556 size_t i;
1557 1557  
1558 1558 audio_process_options ("AUDIO", audio_options);
1559   - for (i = 0; i < sizeof (drvtab) / sizeof (drvtab[0]); i++) {
  1559 + for (i = 0; i < ARRAY_SIZE (drvtab); i++) {
1560 1560 struct audio_driver *d = drvtab[i];
1561 1561 if (d->options) {
1562 1562 audio_process_options (d->name, d->options);
... ... @@ -1569,7 +1569,7 @@ void AUD_help (void)
1569 1569  
1570 1570 printf ("Available drivers:\n");
1571 1571  
1572   - for (i = 0; i < sizeof (drvtab) / sizeof (drvtab[0]); i++) {
  1572 + for (i = 0; i < ARRAY_SIZE (drvtab); i++) {
1573 1573 struct audio_driver *d = drvtab[i];
1574 1574  
1575 1575 printf ("Name: %s\n", d->name);
... ... @@ -1746,7 +1746,7 @@ AudioState *AUD_init (void)
1746 1746 if (drvname) {
1747 1747 int found = 0;
1748 1748  
1749   - for (i = 0; i < sizeof (drvtab) / sizeof (drvtab[0]); i++) {
  1749 + for (i = 0; i < ARRAY_SIZE (drvtab); i++) {
1750 1750 if (!strcmp (drvname, drvtab[i]->name)) {
1751 1751 done = !audio_driver_init (s, drvtab[i]);
1752 1752 found = 1;
... ... @@ -1761,7 +1761,7 @@ AudioState *AUD_init (void)
1761 1761 }
1762 1762  
1763 1763 if (!done) {
1764   - for (i = 0; !done && i < sizeof (drvtab) / sizeof (drvtab[0]); i++) {
  1764 + for (i = 0; !done && i < ARRAY_SIZE (drvtab); i++) {
1765 1765 if (drvtab[i]->can_be_default) {
1766 1766 done = !audio_driver_init (s, drvtab[i]);
1767 1767 }
... ...
audio/fmodaudio.c
... ... @@ -564,7 +564,7 @@ static void *fmod_audio_init (void)
564 564  
565 565 if (drv) {
566 566 int found = 0;
567   - for (i = 0; i < sizeof (drvtab) / sizeof (drvtab[0]); i++) {
  567 + for (i = 0; i < ARRAY_SIZE (drvtab); i++) {
568 568 if (!strcmp (drv, drvtab[i].name)) {
569 569 output_type = drvtab[i].type;
570 570 found = 1;
... ... @@ -574,7 +574,7 @@ static void *fmod_audio_init (void)
574 574 if (!found) {
575 575 dolog ("Unknown FMOD driver `%s'\n", drv);
576 576 dolog ("Valid drivers:\n");
577   - for (i = 0; i < sizeof (drvtab) / sizeof (drvtab[0]); i++) {
  577 + for (i = 0; i < ARRAY_SIZE (drvtab); i++) {
578 578 dolog (" %s\n", drvtab[i].name);
579 579 }
580 580 }
... ...
darwin-user/commpage.c
... ... @@ -191,7 +191,7 @@ void commpage_init(void)
191 191  
192 192 /* XXX: commpage data not handled */
193 193  
194   - for(i = 0; i < sizeof(commpage_entries)/sizeof(commpage_entries[0]); i++)
  194 + for(i = 0; i < ARRAY_SIZE(commpage_entries); i++)
195 195 install_commpage_backdoor_for_entry(commpage_entries[i]);
196 196 #else
197 197 /* simply map our pages so they can be executed
... ... @@ -329,7 +329,7 @@ do_commpage(void *cpu_env, int num, uint32_t arg1, uint32_t arg2, uint32_t arg3,
329 329  
330 330 num = num-COMMPAGE_START-2;
331 331  
332   - for(i = 0; i < sizeof(commpage_entries)/sizeof(commpage_entries[0]); i++) {
  332 + for(i = 0; i < ARRAY_SIZE(commpage_entries); i++) {
333 333 if( num == commpage_code_num(&commpage_entries[i]) )
334 334 {
335 335 DPRINTF("commpage: %s %s\n", commpage_entries[i].name, commpage_is_indirect(&commpage_entries[i]) ? "[indirect]" : "[direct]");
... ...
darwin-user/syscall.c
... ... @@ -135,7 +135,7 @@ void static inline print_description_msg_header(mach_msg_header_t *hdr)
135 135 { 4241876, "lu_message_reply_id" }, /* lookupd */
136 136 };
137 137  
138   - for(i = 0; i < sizeof(msg_name)/sizeof(msg_name[0]); i++) {
  138 + for(i = 0; i < ARRAY_SIZE(msg_name); i++) {
139 139 if(msg_name[i].number == hdr->msgh_id)
140 140 {
141 141 name = msg_name[i].name;
... ... @@ -210,7 +210,7 @@ static inline void print_mach_msg_return(mach_msg_return_t ret)
210 210 DPRINTF("MACH_MSG_SUCCESS\n");
211 211 else
212 212 {
213   - for( i = 0; i < sizeof(msg_name)/sizeof(msg_name[0]); i++) {
  213 + for( i = 0; i < ARRAY_SIZE(msg_name); i++) {
214 214 if(msg_name[i].code == ret) {
215 215 DPRINTF("%s\n", msg_name[i].name);
216 216 found = 1;
... ...
hw/ac97.c
... ... @@ -1196,7 +1196,7 @@ static void ac97_save (QEMUFile *f, void *opaque)
1196 1196 qemu_put_be32s (f, &s->glob_sta);
1197 1197 qemu_put_be32s (f, &s->cas);
1198 1198  
1199   - for (i = 0; i < sizeof (s->bm_regs) / sizeof (s->bm_regs[0]); ++i) {
  1199 + for (i = 0; i < ARRAY_SIZE (s->bm_regs); ++i) {
1200 1200 AC97BusMasterRegs *r = &s->bm_regs[i];
1201 1201 qemu_put_be32s (f, &r->bdbar);
1202 1202 qemu_put_8s (f, &r->civ);
... ... @@ -1235,7 +1235,7 @@ static int ac97_load (QEMUFile *f, void *opaque, int version_id)
1235 1235 qemu_get_be32s (f, &s->glob_sta);
1236 1236 qemu_get_be32s (f, &s->cas);
1237 1237  
1238   - for (i = 0; i < sizeof (s->bm_regs) / sizeof (s->bm_regs[0]); ++i) {
  1238 + for (i = 0; i < ARRAY_SIZE (s->bm_regs); ++i) {
1239 1239 AC97BusMasterRegs *r = &s->bm_regs[i];
1240 1240 qemu_get_be32s (f, &r->bdbar);
1241 1241 qemu_get_8s (f, &r->civ);
... ...
hw/dma.c
... ... @@ -37,8 +37,6 @@
37 37 #define ldebug(...)
38 38 #endif
39 39  
40   -#define LENOFA(a) ((int) (sizeof(a)/sizeof(a[0])))
41   -
42 40 struct dma_regs {
43 41 int now[2];
44 42 uint16_t base[2];
... ... @@ -479,7 +477,7 @@ static void dma_init2(struct dma_cont *d, int base, int dshift,
479 477 register_ioport_write (base + (i << dshift), 1, 1, write_chan, d);
480 478 register_ioport_read (base + (i << dshift), 1, 1, read_chan, d);
481 479 }
482   - for (i = 0; i < LENOFA (page_port_list); i++) {
  480 + for (i = 0; i < ARRAY_SIZE (page_port_list); i++) {
483 481 register_ioport_write (page_base + page_port_list[i], 1, 1,
484 482 write_page, d);
485 483 register_ioport_read (page_base + page_port_list[i], 1, 1,
... ... @@ -499,7 +497,7 @@ static void dma_init2(struct dma_cont *d, int base, int dshift,
499 497 }
500 498 qemu_register_reset(dma_reset, d);
501 499 dma_reset(d);
502   - for (i = 0; i < LENOFA (d->regs); ++i) {
  500 + for (i = 0; i < ARRAY_SIZE (d->regs); ++i) {
503 501 d->regs[i].transfer_handler = dma_phony_handler;
504 502 }
505 503 }
... ...
hw/e1000.c
... ... @@ -763,7 +763,7 @@ static uint32_t (*macreg_readops[])(E1000State *, int) = {
763 763 [MTA ... MTA+127] = &mac_readreg,
764 764 [VFTA ... VFTA+127] = &mac_readreg,
765 765 };
766   -enum { NREADOPS = sizeof(macreg_readops) / sizeof(*macreg_readops) };
  766 +enum { NREADOPS = ARRAY_SIZE(macreg_readops) };
767 767  
768 768 #define putreg(x) [x] = mac_writereg
769 769 static void (*macreg_writeops[])(E1000State *, int, uint32_t) = {
... ... @@ -779,7 +779,7 @@ static void (*macreg_writeops[])(E1000State *, int, uint32_t) = {
779 779 [MTA ... MTA+127] = &mac_writereg,
780 780 [VFTA ... VFTA+127] = &mac_writereg,
781 781 };
782   -enum { NWRITEOPS = sizeof(macreg_writeops) / sizeof(*macreg_writeops) };
  782 +enum { NWRITEOPS = ARRAY_SIZE(macreg_writeops) };
783 783  
784 784 static void
785 785 e1000_mmio_writel(void *opaque, target_phys_addr_t addr, uint32_t val)
... ... @@ -854,13 +854,13 @@ static const int mac_regtosave[] = {
854 854 TDT, TORH, TORL, TOTH, TOTL, TPR, TPT, TXDCTL, WUFC,
855 855 VET,
856 856 };
857   -enum { MAC_NSAVE = sizeof mac_regtosave/sizeof *mac_regtosave };
  857 +enum { MAC_NSAVE = ARRAY_SIZE(mac_regtosave) };
858 858  
859 859 static const struct {
860 860 int size;
861 861 int array0;
862 862 } mac_regarraystosave[] = { {32, RA}, {128, MTA}, {128, VFTA} };
863   -enum { MAC_NARRAYS = sizeof mac_regarraystosave/sizeof *mac_regarraystosave };
  863 +enum { MAC_NARRAYS = ARRAY_SIZE(mac_regarraystosave) };
864 864  
865 865 static void
866 866 nic_save(QEMUFile *f, void *opaque)
... ...
hw/fdc.c
... ... @@ -1851,7 +1851,7 @@ static fdctrl_t *fdctrl_init_common (qemu_irq irq, int dma_chann,
1851 1851 int i, j;
1852 1852  
1853 1853 /* Fill 'command_to_handler' lookup table */
1854   - for (i = sizeof(handlers)/sizeof(handlers[0]) - 1; i >= 0; i--) {
  1854 + for (i = ARRAY_SIZE(handlers) - 1; i >= 0; i--) {
1855 1855 for (j = 0; j < sizeof(command_to_handler); j++) {
1856 1856 if ((j & handlers[i].mask) == handlers[i].value)
1857 1857 command_to_handler[j] = i;
... ...
hw/max7310.c
... ... @@ -180,7 +180,7 @@ static int max7310_load(QEMUFile *f, void *opaque, int version_id)
180 180 static void max7310_gpio_set(void *opaque, int line, int level)
181 181 {
182 182 struct max7310_s *s = (struct max7310_s *) opaque;
183   - if (line >= sizeof(s->handler) / sizeof(*s->handler) || line < 0)
  183 + if (line >= ARRAY_SIZE(s->handler) || line < 0)
184 184 hw_error("bad GPIO line");
185 185  
186 186 if (level)
... ... @@ -199,7 +199,7 @@ struct i2c_slave *max7310_init(i2c_bus *bus)
199 199 s->i2c.recv = max7310_rx;
200 200 s->i2c.send = max7310_tx;
201 201 s->gpio_in = qemu_allocate_irqs(max7310_gpio_set, s,
202   - sizeof(s->handler) / sizeof(*s->handler));
  202 + ARRAY_SIZE(s->handler));
203 203  
204 204 max7310_reset(&s->i2c);
205 205  
... ... @@ -217,7 +217,7 @@ qemu_irq *max7310_gpio_in_get(i2c_slave *i2c)
217 217 void max7310_gpio_out_set(i2c_slave *i2c, int line, qemu_irq handler)
218 218 {
219 219 struct max7310_s *s = (struct max7310_s *) i2c;
220   - if (line >= sizeof(s->handler) / sizeof(*s->handler) || line < 0)
  220 + if (line >= ARRAY_SIZE(s->handler) || line < 0)
221 221 hw_error("bad GPIO line");
222 222  
223 223 s->handler[line] = handler;
... ...
hw/nseries.c
... ... @@ -432,7 +432,7 @@ static uint32_t mipid_txrx(void *opaque, uint32_t cmd, int len)
432 432 cpu_abort(cpu_single_env, "%s: FIXME: bad SPI word width %i\n",
433 433 __FUNCTION__, len);
434 434  
435   - if (s->p >= sizeof(s->resp) / sizeof(*s->resp))
  435 + if (s->p >= ARRAY_SIZE(s->resp))
436 436 ret = 0;
437 437 else
438 438 ret = s->resp[s->p ++];
... ... @@ -840,7 +840,7 @@ static void n800_setup_nolo_tags(void *sram_base)
840 840  
841 841 /* OMAP STI console? Pin out settings? */
842 842 ADD_TAG(0x6e01, 414);
843   - for (i = 0; i < sizeof(n800_pinout) / 4; i ++)
  843 + for (i = 0; i < ARRAY_SIZE(n800_pinout); i ++)
844 844 stl_raw(v ++, n800_pinout[i]);
845 845  
846 846 /* Kernel memsize? */
... ...
hw/rc4030.c
... ... @@ -269,7 +269,7 @@ static void rc4030_writel(void *opaque, target_phys_addr_t addr, uint32_t val)
269 269 static int current = 0;
270 270 target_phys_addr_t dest = 0 + dests[current];
271 271 uint8_t buf;
272   - current = (current + 1) % (sizeof(dests)/sizeof(dests[0]));
  272 + current = (current + 1) % (ARRAY_SIZE(dests));
273 273 buf = s->cache_bwin - 1;
274 274 cpu_physical_memory_rw(dest, &buf, 1, 1);
275 275 }
... ... @@ -403,7 +403,7 @@ static void update_jazz_irq(rc4030State *s)
403 403 if (s->isr_jazz != 0) {
404 404 uint32_t irq = 0;
405 405 printf("jazz pending:");
406   - for (irq = 0; irq < sizeof(irq_names)/sizeof(irq_names[0]); irq++) {
  406 + for (irq = 0; irq < ARRAY_SIZE(irq_names); irq++) {
407 407 if (s->isr_jazz & (1 << irq)) {
408 408 printf(" %s", irq_names[irq]);
409 409 if (!(s->imr_jazz & (1 << irq))) {
... ...
hw/sb16.c
... ... @@ -27,8 +27,6 @@
27 27 #include "isa.h"
28 28 #include "qemu-timer.h"
29 29  
30   -#define LENOFA(a) ((int) (sizeof(a)/sizeof(a[0])))
31   -
32 30 #define dolog(...) AUD_log ("sb16", __VA_ARGS__)
33 31  
34 32 /* #define DEBUG */
... ... @@ -1440,11 +1438,11 @@ int SB16_init (AudioState *audio, qemu_irq *pic)
1440 1438 dolog ("warning: Could not create auxiliary timer\n");
1441 1439 }
1442 1440  
1443   - for (i = 0; i < LENOFA (dsp_write_ports); i++) {
  1441 + for (i = 0; i < ARRAY_SIZE (dsp_write_ports); i++) {
1444 1442 register_ioport_write (s->port + dsp_write_ports[i], 1, 1, dsp_write, s);
1445 1443 }
1446 1444  
1447   - for (i = 0; i < LENOFA (dsp_read_ports); i++) {
  1445 + for (i = 0; i < ARRAY_SIZE (dsp_read_ports); i++) {
1448 1446 register_ioport_read (s->port + dsp_read_ports[i], 1, 1, dsp_read, s);
1449 1447 }
1450 1448  
... ...
hw/sh_intc.c
... ... @@ -17,7 +17,6 @@
17 17 //#define DEBUG_INTC_SOURCES
18 18  
19 19 #define INTC_A7(x) ((x) & 0x1fffffff)
20   -#define INTC_ARRAY(x) (sizeof(x) / sizeof(x[0]))
21 20  
22 21 void sh_intc_toggle_source(struct intc_source *source,
23 22 int enable_adj, int assert_adj)
... ... @@ -327,7 +326,7 @@ static void sh_intc_register_source(struct intc_desc *desc,
327 326 for (i = 0; i < desc->nr_mask_regs; i++) {
328 327 struct intc_mask_reg *mr = desc->mask_regs + i;
329 328  
330   - for (k = 0; k < INTC_ARRAY(mr->enum_ids); k++) {
  329 + for (k = 0; k < ARRAY_SIZE(mr->enum_ids); k++) {
331 330 if (mr->enum_ids[k] != source)
332 331 continue;
333 332  
... ... @@ -342,7 +341,7 @@ static void sh_intc_register_source(struct intc_desc *desc,
342 341 for (i = 0; i < desc->nr_prio_regs; i++) {
343 342 struct intc_prio_reg *pr = desc->prio_regs + i;
344 343  
345   - for (k = 0; k < INTC_ARRAY(pr->enum_ids); k++) {
  344 + for (k = 0; k < ARRAY_SIZE(pr->enum_ids); k++) {
346 345 if (pr->enum_ids[k] != source)
347 346 continue;
348 347  
... ... @@ -357,7 +356,7 @@ static void sh_intc_register_source(struct intc_desc *desc,
357 356 for (i = 0; i < nr_groups; i++) {
358 357 struct intc_group *gr = groups + i;
359 358  
360   - for (k = 0; k < INTC_ARRAY(gr->enum_ids); k++) {
  359 + for (k = 0; k < ARRAY_SIZE(gr->enum_ids); k++) {
361 360 if (gr->enum_ids[k] != source)
362 361 continue;
363 362  
... ... @@ -400,7 +399,7 @@ void sh_intc_register_sources(struct intc_desc *desc,
400 399 s = sh_intc_source(desc, gr->enum_id);
401 400 s->next_enum_id = gr->enum_ids[0];
402 401  
403   - for (k = 1; k < INTC_ARRAY(gr->enum_ids); k++) {
  402 + for (k = 1; k < ARRAY_SIZE(gr->enum_ids); k++) {
404 403 if (!gr->enum_ids[k])
405 404 continue;
406 405  
... ...
hw/sh_intc.h
... ... @@ -32,7 +32,7 @@ struct intc_prio_reg {
32 32 unsigned long value;
33 33 };
34 34  
35   -#define _INTC_ARRAY(a) a, sizeof(a)/sizeof(*a)
  35 +#define _INTC_ARRAY(a) a, ARRAY_SIZE(a)
36 36  
37 37 struct intc_source {
38 38 unsigned short vect;
... ...
hw/sm501.c
... ... @@ -514,7 +514,7 @@ static uint32_t get_local_mem_size_index(uint32_t size)
514 514 uint32_t norm_size = 0;
515 515 int i, index = 0;
516 516  
517   - for (i = 0; i < sizeof(sm501_mem_local_size)/sizeof(uint32_t); i++) {
  517 + for (i = 0; i < ARRAY_SIZE(sm501_mem_local_size); i++) {
518 518 uint32_t new_size = sm501_mem_local_size[i];
519 519 if (new_size >= size) {
520 520 if (norm_size == 0 || norm_size > new_size) {
... ...
hw/usb-net.c
... ... @@ -628,14 +628,13 @@ static int ndis_query(USBNetState *s, uint32_t oid,
628 628 uint8_t *inbuf, unsigned int inlen, uint8_t *outbuf,
629 629 size_t outlen)
630 630 {
631   - unsigned int i, count;
  631 + unsigned int i;
632 632  
633 633 switch (oid) {
634 634 /* general oids (table 4-1) */
635 635 /* mandatory */
636 636 case OID_GEN_SUPPORTED_LIST:
637   - count = sizeof(oid_supported_list) / sizeof(uint32_t);
638   - for (i = 0; i < count; i++)
  637 + for (i = 0; i < ARRAY_SIZE(oid_supported_list); i++)
639 638 ((le32 *) outbuf)[i] = cpu_to_le32(oid_supported_list[i]);
640 639 return sizeof(oid_supported_list);
641 640  
... ...
hw/vmware_vga.c
... ... @@ -817,7 +817,7 @@ static void vmsvga_value_write(void *opaque, uint32_t address, uint32_t value)
817 817 s->guest = value;
818 818 #ifdef VERBOSE
819 819 if (value >= GUEST_OS_BASE && value < GUEST_OS_BASE +
820   - sizeof(vmsvga_guest_id) / sizeof(*vmsvga_guest_id))
  820 + ARRAY_SIZE(vmsvga_guest_id))
821 821 printf("%s: guest runs %s.\n", __FUNCTION__,
822 822 vmsvga_guest_id[value - GUEST_OS_BASE]);
823 823 #endif
... ...
linux-user/strace.c
... ... @@ -263,7 +263,7 @@ static const struct syscallname scnames[] = {
263 263 #include "strace.list"
264 264 };
265 265  
266   -static int nsyscalls = sizeof(scnames)/sizeof(struct syscallname);
  266 +static int nsyscalls = ARRAY_SIZE(scnames);
267 267  
268 268 /*
269 269 * The public interface to this module.
... ...
target-cris/translate.c
... ... @@ -612,7 +612,7 @@ static inline void t_gen_swapr(TCGv d, TCGv s)
612 612  
613 613 tcg_gen_shli_tl(t, org_s, bitrev[0].shift);
614 614 tcg_gen_andi_tl(d, t, bitrev[0].mask);
615   - for (i = 1; i < sizeof bitrev / sizeof bitrev[0]; i++) {
  615 + for (i = 1; i < ARRAY_SIZE(bitrev); i++) {
616 616 if (bitrev[i].shift >= 0) {
617 617 tcg_gen_shli_tl(t, org_s, bitrev[i].shift);
618 618 } else {
... ... @@ -3158,7 +3158,7 @@ cris_decoder(DisasContext *dc)
3158 3158 dc->postinc = EXTRACT_FIELD(dc->ir, 10, 10);
3159 3159  
3160 3160 /* Large switch for all insns. */
3161   - for (i = 0; i < sizeof decinfo / sizeof decinfo[0]; i++) {
  3161 + for (i = 0; i < ARRAY_SIZE(decinfo); i++) {
3162 3162 if ((dc->opcode & decinfo[i].mask) == decinfo[i].bits)
3163 3163 {
3164 3164 insn_len = decinfo[i].dec(dc);
... ...
target-i386/helper.c
... ... @@ -274,7 +274,7 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model)
274 274 int family = -1, model = -1, stepping = -1;
275 275  
276 276 def = NULL;
277   - for (i = 0; i < sizeof(x86_defs) / sizeof(x86_def_t); i++) {
  277 + for (i = 0; i < ARRAY_SIZE(x86_defs); i++) {
278 278 if (strcmp(name, x86_defs[i].name) == 0) {
279 279 def = &x86_defs[i];
280 280 break;
... ... @@ -364,7 +364,7 @@ void x86_cpu_list (FILE *f, int (*cpu_fprintf)(FILE *f, const char *fmt, ...))
364 364 {
365 365 unsigned int i;
366 366  
367   - for (i = 0; i < sizeof(x86_defs) / sizeof(x86_def_t); i++)
  367 + for (i = 0; i < ARRAY_SIZE(x86_defs); i++)
368 368 (*cpu_fprintf)(f, "x86 %16s\n", x86_defs[i].name);
369 369 }
370 370  
... ...
target-mips/translate_init.c
... ... @@ -421,7 +421,7 @@ static const mips_def_t *cpu_mips_find_by_name (const char *name)
421 421 {
422 422 int i;
423 423  
424   - for (i = 0; i < sizeof(mips_defs) / sizeof(mips_defs[0]); i++) {
  424 + for (i = 0; i < ARRAY_SIZE(mips_defs); i++) {
425 425 if (strcasecmp(name, mips_defs[i].name) == 0) {
426 426 return &mips_defs[i];
427 427 }
... ... @@ -433,7 +433,7 @@ void mips_cpu_list (FILE *f, int (*cpu_fprintf)(FILE *f, const char *fmt, ...))
433 433 {
434 434 int i;
435 435  
436   - for (i = 0; i < sizeof(mips_defs) / sizeof(mips_defs[0]); i++) {
  436 + for (i = 0; i < ARRAY_SIZE(mips_defs); i++) {
437 437 (*cpu_fprintf)(f, "MIPS '%s'\n",
438 438 mips_defs[i].name);
439 439 }
... ...
target-ppc/translate_init.c
... ... @@ -9455,7 +9455,7 @@ static const ppc_def_t *ppc_find_by_pvr (uint32_t pvr)
9455 9455 int i, best, match, best_match, max;
9456 9456  
9457 9457 ret = NULL;
9458   - max = sizeof(ppc_defs) / sizeof(ppc_def_t);
  9458 + max = ARRAY_SIZE(ppc_defs);
9459 9459 best = -1;
9460 9460 pvr_rev = pvr & 0xFFFF;
9461 9461 /* We want all specified bits to match */
... ... @@ -9510,7 +9510,7 @@ const ppc_def_t *cpu_ppc_find_by_name (const char *name)
9510 9510 return ppc_find_by_pvr(strtoul(name, NULL, 16));
9511 9511 }
9512 9512 ret = NULL;
9513   - max = sizeof(ppc_defs) / sizeof(ppc_def_t);
  9513 + max = ARRAY_SIZE(ppc_defs);
9514 9514 for (i = 0; i < max; i++) {
9515 9515 if (strcasecmp(name, ppc_defs[i].name) == 0) {
9516 9516 ret = &ppc_defs[i];
... ... @@ -9525,7 +9525,7 @@ void ppc_cpu_list (FILE *f, int (*cpu_fprintf)(FILE *f, const char *fmt, ...))
9525 9525 {
9526 9526 int i, max;
9527 9527  
9528   - max = sizeof(ppc_defs) / sizeof(ppc_def_t);
  9528 + max = ARRAY_SIZE(ppc_defs);
9529 9529 for (i = 0; i < max; i++) {
9530 9530 (*cpu_fprintf)(f, "PowerPC %-16s PVR %08x\n",
9531 9531 ppc_defs[i].name, ppc_defs[i].pvr);
... ...
target-sh4/translate.c
... ... @@ -240,7 +240,7 @@ static const sh4_def_t *cpu_sh4_find_by_name(const char *name)
240 240 if (strcasecmp(name, "any") == 0)
241 241 return &sh4_defs[0];
242 242  
243   - for (i = 0; i < sizeof(sh4_defs) / sizeof(*sh4_defs); i++)
  243 + for (i = 0; i < ARRAY_SIZE(sh4_defs); i++)
244 244 if (strcasecmp(name, sh4_defs[i].name) == 0)
245 245 return &sh4_defs[i];
246 246  
... ... @@ -251,7 +251,7 @@ void sh4_cpu_list(FILE *f, int (*cpu_fprintf)(FILE *f, const char *fmt, ...))
251 251 {
252 252 int i;
253 253  
254   - for (i = 0; i < sizeof(sh4_defs) / sizeof(*sh4_defs); i++)
  254 + for (i = 0; i < ARRAY_SIZE(sh4_defs); i++)
255 255 (*cpu_fprintf)(f, "%s\n", sh4_defs[i].name);
256 256 }
257 257  
... ...
target-sparc/helper.c
... ... @@ -1240,7 +1240,7 @@ static int cpu_sparc_find_by_name(sparc_def_t *cpu_def, const char *cpu_model)
1240 1240 long long iu_version;
1241 1241 uint32_t fpu_version, mmu_version, nwindows;
1242 1242  
1243   - for (i = 0; i < sizeof(sparc_defs) / sizeof(sparc_def_t); i++) {
  1243 + for (i = 0; i < ARRAY_SIZE(sparc_defs); i++) {
1244 1244 if (strcasecmp(name, sparc_defs[i].name) == 0) {
1245 1245 def = &sparc_defs[i];
1246 1246 }
... ... @@ -1336,7 +1336,7 @@ void sparc_cpu_list(FILE *f, int (*cpu_fprintf)(FILE *f, const char *fmt, ...))
1336 1336 {
1337 1337 unsigned int i;
1338 1338  
1339   - for (i = 0; i < sizeof(sparc_defs) / sizeof(sparc_def_t); i++) {
  1339 + for (i = 0; i < ARRAY_SIZE(sparc_defs); i++) {
1340 1340 (*cpu_fprintf)(f, "Sparc %16s IU " TARGET_FMT_lx " FPU %08x MMU %08x NWINS %d ",
1341 1341 sparc_defs[i].name,
1342 1342 sparc_defs[i].iu_version,
... ...
tcg/ppc/tcg-target.c
... ... @@ -212,7 +212,7 @@ static void patch_reloc(uint8_t *code_ptr, int type,
212 212 /* maximum number of register used for input function arguments */
213 213 static int tcg_target_get_call_iarg_regs_count(int flags)
214 214 {
215   - return sizeof (tcg_target_call_iarg_regs) / sizeof (tcg_target_call_iarg_regs[0]);
  215 + return ARRAY_SIZE (tcg_target_call_iarg_regs);
216 216 }
217 217  
218 218 /* parse target specific constraints */
... ...
tcg/ppc64/tcg-target.c
... ... @@ -199,7 +199,7 @@ static void patch_reloc (uint8_t *code_ptr, int type,
199 199 /* maximum number of register used for input function arguments */
200 200 static int tcg_target_get_call_iarg_regs_count (int flags)
201 201 {
202   - return sizeof (tcg_target_call_iarg_regs) / sizeof (tcg_target_call_iarg_regs[0]);
  202 + return ARRAY_SIZE (tcg_target_call_iarg_regs);
203 203 }
204 204  
205 205 /* parse target specific constraints */
... ...
... ... @@ -1048,7 +1048,7 @@ static void configure_alarms(char const *opt)
1048 1048 {
1049 1049 int i;
1050 1050 int cur = 0;
1051   - int count = (sizeof(alarm_timers) / sizeof(*alarm_timers)) - 1;
  1051 + int count = ARRAY_SIZE(alarm_timers) - 1;
1052 1052 char *arg;
1053 1053 char *name;
1054 1054 struct qemu_alarm_timer tmp;
... ...