Use our nitems() macro when param.h is available.
Replacements specific to arm, mips, pc98, powerpc and sparc64. Discussed in: freebsd-current
This commit is contained in:
parent
2f7a2b9d79
commit
33495e5daf
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=298352
@ -69,8 +69,7 @@ static struct aml8726_clkmsr_clk {
|
||||
|
||||
#define AML_CLKMSR_CLK81 0
|
||||
|
||||
#define AML_CLKMSR_NCLKS (sizeof(aml8726_clkmsr_clks) \
|
||||
/ sizeof(aml8726_clkmsr_clks[0]))
|
||||
#define AML_CLKMSR_NCLKS nitems(aml8726_clkmsr_clks)
|
||||
|
||||
struct aml8726_clkmsr_softc {
|
||||
device_t dev;
|
||||
|
@ -100,7 +100,7 @@ struct db_variable db_regs[] = {
|
||||
{ "irq_sp", &nil, db_access_irq_sp, },
|
||||
};
|
||||
|
||||
struct db_variable *db_eregs = db_regs + sizeof(db_regs)/sizeof(db_regs[0]);
|
||||
struct db_variable *db_eregs = db_regs + nitems(db_regs);
|
||||
|
||||
int
|
||||
db_access_und_sp(struct db_variable *vp, db_expr_t *valp, int rw)
|
||||
|
@ -320,7 +320,7 @@ at91_pmc_clock_add(const char *name, uint32_t irq,
|
||||
else
|
||||
clk->parent = parent;
|
||||
|
||||
for (i = 0; i < sizeof(clock_list) / sizeof(clock_list[0]); i++) {
|
||||
for (i = 0; i < nitems(clock_list); i++) {
|
||||
if (clock_list[i] == NULL) {
|
||||
clock_list[i] = clk;
|
||||
return (clk);
|
||||
@ -358,7 +358,7 @@ at91_pmc_clock_ref(const char *name)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < sizeof(clock_list) / sizeof(clock_list[0]); i++) {
|
||||
for (i = 0; i < nitems(clock_list); i++) {
|
||||
if (clock_list[i] == NULL)
|
||||
break;
|
||||
if (strcmp(name, clock_list[i]->name) == 0)
|
||||
@ -484,7 +484,7 @@ static const unsigned int at91_main_clock_tbl[] = {
|
||||
12000000, 12288000, 13560000, 14318180, 14745600,
|
||||
16000000, 17344700, 18432000, 20000000
|
||||
};
|
||||
#define MAIN_CLOCK_TBL_LEN (sizeof(at91_main_clock_tbl) / sizeof(*at91_main_clock_tbl))
|
||||
#define MAIN_CLOCK_TBL_LEN nitems(at91_main_clock_tbl)
|
||||
#endif
|
||||
|
||||
static unsigned int
|
||||
|
@ -150,13 +150,13 @@ count_l2clk(void)
|
||||
sar_fab_freq = FAB_FREQ_FIELD(sar_reg);
|
||||
|
||||
/* Check if CPU frequency field has correct value */
|
||||
array_size = sizeof(cpu_clock_table) / sizeof(cpu_clock_table[0]);
|
||||
array_size = nitems(cpu_clock_table);
|
||||
if (sar_cpu_freq >= array_size)
|
||||
panic("Reserved value in cpu frequency configuration field: "
|
||||
"%d", sar_cpu_freq);
|
||||
|
||||
/* Check if fabric frequency field has correct value */
|
||||
array_size = sizeof(freq_conf_table) / sizeof(freq_conf_table[0]);
|
||||
array_size = nitems(freq_conf_table);
|
||||
if (sar_fab_freq >= array_size)
|
||||
panic("Reserved value in fabric frequency configuration field: "
|
||||
"%d", sar_fab_freq);
|
||||
|
@ -470,7 +470,7 @@ cpsw_init_slots(struct cpsw_softc *sc)
|
||||
STAILQ_INIT(&sc->avail);
|
||||
|
||||
/* Put the slot descriptors onto the global avail list. */
|
||||
for (i = 0; i < sizeof(sc->_slots) / sizeof(sc->_slots[0]); i++) {
|
||||
for (i = 0; i < nitems(sc->_slots); i++) {
|
||||
slot = &sc->_slots[i];
|
||||
slot->bd_offset = cpsw_cpdma_bd_offset(i);
|
||||
STAILQ_INSERT_TAIL(&sc->avail, slot, next);
|
||||
@ -480,7 +480,7 @@ cpsw_init_slots(struct cpsw_softc *sc)
|
||||
static int
|
||||
cpsw_add_slots(struct cpsw_softc *sc, struct cpsw_queue *queue, int requested)
|
||||
{
|
||||
const int max_slots = sizeof(sc->_slots) / sizeof(sc->_slots[0]);
|
||||
const int max_slots = nitems(sc->_slots);
|
||||
struct cpsw_slot *slot;
|
||||
int i;
|
||||
|
||||
@ -917,7 +917,7 @@ cpsw_detach(device_t dev)
|
||||
cpsw_intr_detach(sc);
|
||||
|
||||
/* Free dmamaps and mbufs */
|
||||
for (i = 0; i < sizeof(sc->_slots) / sizeof(sc->_slots[0]); ++i)
|
||||
for (i = 0; i < nitems(sc->_slots); ++i)
|
||||
cpsw_free_slot(sc, &sc->_slots[i]);
|
||||
|
||||
/* Free null mbuf. */
|
||||
|
@ -473,7 +473,7 @@ gethwvtrans(uint32_t hwbase, uint32_t size)
|
||||
};
|
||||
int i;
|
||||
|
||||
for (i = 0; i < sizeof hwvtrans / sizeof *hwvtrans; i++) {
|
||||
for (i = 0; i < nitems(hwvtrans); i++) {
|
||||
if (hwbase >= hwvtrans[i].hwbase &&
|
||||
hwbase + size <= hwvtrans[i].hwbase + hwvtrans[i].size)
|
||||
return &hwvtrans[i];
|
||||
|
@ -117,7 +117,7 @@ struct db_variable db_regs[] = {
|
||||
{ "cs", DB_OFFSET(cause), db_frame },
|
||||
{ "pc", DB_OFFSET(pc), db_frame },
|
||||
};
|
||||
struct db_variable *db_eregs = db_regs + sizeof(db_regs)/sizeof(db_regs[0]);
|
||||
struct db_variable *db_eregs = db_regs + nitems(db_regs);
|
||||
|
||||
int (*do_db_log_stack_trace_cmd)(char *);
|
||||
|
||||
|
@ -585,7 +585,7 @@ map_gen_mode_num(int type, int color, int mode)
|
||||
};
|
||||
int i;
|
||||
|
||||
for (i = 0; i < sizeof(mode_map)/sizeof(mode_map[0]); ++i) {
|
||||
for (i = 0; i < nitems(mode_map); ++i) {
|
||||
if (mode_map[i].from == mode)
|
||||
return mode_map[i].to;
|
||||
}
|
||||
|
@ -446,8 +446,7 @@ pckbd_init(int unit, keyboard_t **kbdp, void *arg, int flags)
|
||||
keymap = &default_keymap;
|
||||
accmap = &default_accentmap;
|
||||
fkeymap = default_fkeytab;
|
||||
fkeymap_size =
|
||||
sizeof(default_fkeytab)/sizeof(default_fkeytab[0]);
|
||||
fkeymap_size = nitems(default_fkeytab);
|
||||
|
||||
state->kbdc = kbdc_open(data[0]);
|
||||
if (state->kbdc == NULL)
|
||||
|
@ -819,7 +819,7 @@ scterm_scan_esc(scr_stat *scp, term_stat *tcp, u_char c)
|
||||
v2 = tcp->param[2];
|
||||
switch (n) {
|
||||
case 1: /* flags only */
|
||||
if (v0 < sizeof(cattrs)/sizeof(cattrs[0]))
|
||||
if (v0 < nitems(cattrs))
|
||||
v0 = cattrs[v0];
|
||||
else /* backward compatibility */
|
||||
v0 = cattrs[v0 & 0x3];
|
||||
@ -884,7 +884,7 @@ scterm_scan_esc(scr_stat *scp, term_stat *tcp, u_char c)
|
||||
v0 = 0;
|
||||
/* FALL THROUGH */
|
||||
case 1:
|
||||
if (v0 < sizeof(tcattrs)/sizeof(tcattrs[0]))
|
||||
if (v0 < nitems(tcattrs))
|
||||
sc_change_cursor_shape(scp,
|
||||
tcattrs[v0], -1, -1);
|
||||
break;
|
||||
|
@ -106,7 +106,7 @@ struct db_variable db_regs[] = {
|
||||
{ "esr", DB_OFFSET(cpu.booke.esr), db_frame },
|
||||
#endif
|
||||
};
|
||||
struct db_variable *db_eregs = db_regs + sizeof (db_regs)/sizeof (db_regs[0]);
|
||||
struct db_variable *db_eregs = db_regs + nitems(db_regs);
|
||||
|
||||
/*
|
||||
* register variable handling
|
||||
|
@ -266,8 +266,8 @@ xicp_enable(device_t dev, u_int irq, u_int vector)
|
||||
|
||||
sc = device_get_softc(dev);
|
||||
|
||||
KASSERT(sc->nintvecs + 1 < sizeof(sc->intvecs)/sizeof(sc->intvecs[0]),
|
||||
("Too many XICP interrupts"));
|
||||
KASSERT(sc->nintvecs + 1 < nitems(sc->intvecs),
|
||||
("Too many XICP interrupts"));
|
||||
|
||||
mtx_lock(&sc->sc_mtx);
|
||||
sc->intvecs[sc->nintvecs].irq = irq;
|
||||
|
@ -74,7 +74,7 @@ struct db_variable db_regs[] = {
|
||||
{ "tpc", DB_OFFSET(tf_tpc), db_frame },
|
||||
{ "tstate", DB_OFFSET(tf_tstate), db_frame },
|
||||
};
|
||||
struct db_variable *db_eregs = db_regs + sizeof(db_regs)/sizeof(db_regs[0]);
|
||||
struct db_variable *db_eregs = db_regs + nitems(db_regs);
|
||||
|
||||
static int
|
||||
db_frame(struct db_variable *vp, db_expr_t *valuep, int op)
|
||||
|
@ -357,8 +357,7 @@ elf_reloc(linker_file_t lf, Elf_Addr relocbase, const void *data, int type,
|
||||
return (0);
|
||||
|
||||
if (rtype == R_SPARC_JMP_SLOT || rtype == R_SPARC_COPY ||
|
||||
rtype >= sizeof(reloc_target_bitmask) /
|
||||
sizeof(*reloc_target_bitmask)) {
|
||||
rtype >= nitems(reloc_target_bitmask)) {
|
||||
printf("kldload: unexpected relocation type %ld\n", rtype);
|
||||
return (-1);
|
||||
}
|
||||
|
@ -215,8 +215,8 @@ static const int trap_sig[] = {
|
||||
-1, /* kernel stack fault */
|
||||
};
|
||||
|
||||
CTASSERT(sizeof(trap_msg) / sizeof(*trap_msg) == T_MAX);
|
||||
CTASSERT(sizeof(trap_sig) / sizeof(*trap_sig) == T_MAX);
|
||||
CTASSERT(nitems(trap_msg) == T_MAX);
|
||||
CTASSERT(nitems(trap_sig) == T_MAX);
|
||||
|
||||
CTASSERT(sizeof(struct trapframe) == 256);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user