kernel: use our nitems() macro when it is available through param.h.

No functional change, only trivial cases are done in this sweep,

Discussed in:	freebsd-current
This commit is contained in:
Pedro F. Giffuni 2016-04-19 23:48:27 +00:00
parent 2464bbf05a
commit 02abd40029
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=298310
25 changed files with 45 additions and 58 deletions

View file

@ -1703,7 +1703,7 @@ static const unsigned char lxs_args[] = {
LINUX_AL(4) /* sendmmsg */
};
#define LINUX_AL_SIZE sizeof(lxs_args) / sizeof(lxs_args[0]) - 1
#define LINUX_AL_SIZE (nitems(lxs_args) - 1)
int
linux_socketcall(struct thread *td, struct linux_socketcall_args *args)

View file

@ -54,7 +54,7 @@ static struct db_variable db_vars[] = {
#endif
};
static struct db_variable *db_evars =
db_vars + sizeof(db_vars)/sizeof(db_vars[0]);
db_vars + nitems(db_vars);
static int
db_find_variable(struct db_variable **varp)

View file

@ -354,7 +354,7 @@ autofs_set_sigmask(sigset_t *oldset)
/* Remove the autofs set of signals from newset */
PROC_LOCK(curproc);
mtx_lock(&curproc->p_sigacts->ps_mtx);
for (i = 0 ; i < sizeof(autofs_sig_set)/sizeof(int) ; i++) {
for (i = 0 ; i < nitems(autofs_sig_set); i++) {
/*
* But make sure we leave the ones already masked
* by the process, i.e. remove the signal from the

View file

@ -1053,7 +1053,7 @@ nfs_sig_pending(sigset_t set)
{
int i;
for (i = 0 ; i < sizeof(newnfs_sig_set)/sizeof(int) ; i++)
for (i = 0 ; i < nitems(newnfs_sig_set); i++)
if (SIGISMEMBER(set, newnfs_sig_set[i]))
return (1);
return (0);
@ -1078,7 +1078,7 @@ newnfs_set_sigmask(struct thread *td, sigset_t *oldset)
/* Remove the NFS set of signals from newset */
PROC_LOCK(p);
mtx_lock(&p->p_sigacts->ps_mtx);
for (i = 0 ; i < sizeof(newnfs_sig_set)/sizeof(int) ; i++) {
for (i = 0 ; i < nitems(newnfs_sig_set); i++) {
/*
* But make sure we leave the ones already masked
* by the process, ie. remove the signal from the

View file

@ -141,7 +141,7 @@ bsd_parse_type(const char *type, uint8_t *fstype)
return (0);
}
for (i = 0;
i < sizeof(bsd_alias_match) / sizeof(bsd_alias_match[0]); i++) {
i < nitems(bsd_alias_match); i++) {
alias = g_part_alias_name(bsd_alias_match[i].alias);
if (strcasecmp(type, alias) == 0) {
*fstype = bsd_alias_match[i].type;

View file

@ -189,7 +189,7 @@ ebr_parse_type(const char *type, u_char *dp_typ)
return (0);
}
for (i = 0;
i < sizeof(ebr_alias_match) / sizeof(ebr_alias_match[0]); i++) {
i < nitems(ebr_alias_match); i++) {
alias = g_part_alias_name(ebr_alias_match[i].alias);
if (strcasecmp(type, alias) == 0) {
*dp_typ = ebr_alias_match[i].typ;
@ -604,7 +604,7 @@ g_part_ebr_type(struct g_part_table *basetable, struct g_part_entry *baseentry,
entry = (struct g_part_ebr_entry *)baseentry;
for (i = 0;
i < sizeof(ebr_alias_match) / sizeof(ebr_alias_match[0]); i++) {
i < nitems(ebr_alias_match); i++) {
if (ebr_alias_match[i].typ == entry->ent.dp_typ)
return (g_part_alias_name(ebr_alias_match[i].alias));
}

View file

@ -454,7 +454,7 @@ ldm_privhdr_check(struct ldm_db *db, struct g_consumer *cp, int is_gpt)
} else
last = pp->mediasize / pp->sectorsize - 1;
for (found = 0, i = is_gpt;
i < sizeof(ldm_ph_off) / sizeof(ldm_ph_off[0]); i++) {
i < nitems(ldm_ph_off); i++) {
offset = ldm_ph_off[i];
/*
* In the GPT case consumer is attached to the LDM metadata
@ -1469,7 +1469,7 @@ g_part_ldm_type(struct g_part_table *basetable, struct g_part_entry *baseentry,
entry = (struct g_part_ldm_entry *)baseentry;
for (i = 0;
i < sizeof(ldm_alias_match) / sizeof(ldm_alias_match[0]); i++) {
i < nitems(ldm_alias_match); i++) {
if (ldm_alias_match[i].typ == entry->type)
return (g_part_alias_name(ldm_alias_match[i].alias));
}

View file

@ -159,7 +159,7 @@ mbr_parse_type(const char *type, u_char *dp_typ)
return (0);
}
for (i = 0;
i < sizeof(mbr_alias_match) / sizeof(mbr_alias_match[0]); i++) {
i < nitems(mbr_alias_match); i++) {
alias = g_part_alias_name(mbr_alias_match[i].alias);
if (strcasecmp(type, alias) == 0) {
*dp_typ = mbr_alias_match[i].typ;
@ -561,7 +561,7 @@ g_part_mbr_type(struct g_part_table *basetable, struct g_part_entry *baseentry,
entry = (struct g_part_mbr_entry *)baseentry;
for (i = 0;
i < sizeof(mbr_alias_match) / sizeof(mbr_alias_match[0]); i++) {
i < nitems(mbr_alias_match); i++) {
if (mbr_alias_match[i].typ == entry->ent.dp_typ)
return (g_part_alias_name(mbr_alias_match[i].alias));
}

View file

@ -71,7 +71,7 @@ dumpsys_gen_pa_init(void)
int n, idx;
bzero(dump_map, sizeof(dump_map));
for (n = 0; n < sizeof(dump_map) / sizeof(dump_map[0]); n++) {
for (n = 0; n < nitems(dump_map); n++) {
idx = n * 2;
if (dump_avail[idx] == 0 && dump_avail[idx + 1] == 0)
break;

View file

@ -160,7 +160,7 @@ SYSCTL_NODE(_kern_sysclock, OID_AUTO, ffclock, CTLFLAG_RW, 0,
static char *sysclocks[] = {"feedback", "feed-forward"};
#define MAX_SYSCLOCK_NAME_LEN 16
#define NUM_SYSCLOCKS (sizeof(sysclocks) / sizeof(*sysclocks))
#define NUM_SYSCLOCKS nitems(sysclocks)
static int ffclock_version = 2;
SYSCTL_INT(_kern_sysclock_ffclock, OID_AUTO, version, CTLFLAG_RD,

View file

@ -357,8 +357,7 @@ sys_jail(struct thread *td, struct jail_args *uap)
int
kern_jail(struct thread *td, struct jail *j)
{
struct iovec optiov[2 * (4
+ sizeof(pr_allow_names) / sizeof(pr_allow_names[0])
struct iovec optiov[2 * (4 + nitems(pr_allow_names)
#ifdef INET
+ 1
#endif
@ -389,8 +388,7 @@ kern_jail(struct thread *td, struct jail *j)
/* Set permissions for top-level jails from sysctls. */
if (!jailed(td->td_ucred)) {
for (fi = 0; fi < sizeof(pr_allow_names) /
sizeof(pr_allow_names[0]); fi++) {
for (fi = 0; fi < nitems(pr_allow_names); fi++) {
optiov[opt.uio_iovcnt].iov_base =
(jail_default_allow & (1 << fi))
? pr_allow_names[fi] : pr_allow_nonames[fi];
@ -503,8 +501,8 @@ kern_jail(struct thread *td, struct jail *j)
}
opt.uio_iovcnt++;
#endif
KASSERT(opt.uio_iovcnt <= sizeof(optiov) / sizeof(optiov[0]),
("kern_jail: too many iovecs (%d)", opt.uio_iovcnt));
KASSERT(opt.uio_iovcnt <= nitems(optiov),
("kern_jail: too many iovecs (%d)", opt.uio_iovcnt));
error = kern_jail_set(td, &opt, JAIL_CREATE | JAIL_ATTACH);
free(u_path, M_TEMP);
return (error);
@ -651,16 +649,14 @@ kern_jail_set(struct thread *td, struct uio *optuio, int flags)
gotrsnum = 1;
pr_flags = ch_flags = 0;
for (fi = 0; fi < sizeof(pr_flag_names) / sizeof(pr_flag_names[0]);
fi++) {
for (fi = 0; fi < nitems(pr_flag_names); fi++) {
if (pr_flag_names[fi] == NULL)
continue;
vfs_flagopt(opts, pr_flag_names[fi], &pr_flags, 1 << fi);
vfs_flagopt(opts, pr_flag_nonames[fi], &ch_flags, 1 << fi);
}
ch_flags |= pr_flags;
for (fi = 0; fi < sizeof(pr_flag_jailsys) / sizeof(pr_flag_jailsys[0]);
fi++) {
for (fi = 0; fi < nitems(pr_flag_jailsys); fi++) {
error = vfs_copyopt(opts, pr_flag_jailsys[fi].name, &jsys,
sizeof(jsys));
if (error == ENOENT)
@ -716,8 +712,7 @@ kern_jail_set(struct thread *td, struct uio *optuio, int flags)
#endif
pr_allow = ch_allow = 0;
for (fi = 0; fi < sizeof(pr_allow_names) / sizeof(pr_allow_names[0]);
fi++) {
for (fi = 0; fi < nitems(pr_allow_names); fi++) {
vfs_flagopt(opts, pr_allow_names[fi], &pr_allow, 1 << fi);
vfs_flagopt(opts, pr_allow_nonames[fi], &ch_allow, 1 << fi);
}
@ -2136,8 +2131,7 @@ kern_jail_get(struct thread *td, struct uio *optuio, int flags)
sizeof(pr->pr_devfs_rsnum));
if (error != 0 && error != ENOENT)
goto done_deref;
for (fi = 0; fi < sizeof(pr_flag_names) / sizeof(pr_flag_names[0]);
fi++) {
for (fi = 0; fi < nitems(pr_flag_names); fi++) {
if (pr_flag_names[fi] == NULL)
continue;
i = (pr->pr_flags & (1 << fi)) ? 1 : 0;
@ -2149,8 +2143,7 @@ kern_jail_get(struct thread *td, struct uio *optuio, int flags)
if (error != 0 && error != ENOENT)
goto done_deref;
}
for (fi = 0; fi < sizeof(pr_flag_jailsys) / sizeof(pr_flag_jailsys[0]);
fi++) {
for (fi = 0; fi < nitems(pr_flag_jailsys); fi++) {
i = pr->pr_flags &
(pr_flag_jailsys[fi].disable | pr_flag_jailsys[fi].new);
i = pr_flag_jailsys[fi].disable &&
@ -2162,8 +2155,7 @@ kern_jail_get(struct thread *td, struct uio *optuio, int flags)
if (error != 0 && error != ENOENT)
goto done_deref;
}
for (fi = 0; fi < sizeof(pr_allow_names) / sizeof(pr_allow_names[0]);
fi++) {
for (fi = 0; fi < nitems(pr_allow_names); fi++) {
if (pr_allow_names[fi] == NULL)
continue;
i = (pr->pr_allow & (1 << fi)) ? 1 : 0;
@ -4694,12 +4686,10 @@ db_show_prison(struct prison *pr)
db_printf(" child = %p\n", LIST_FIRST(&pr->pr_children));
db_printf(" sibling = %p\n", LIST_NEXT(pr, pr_sibling));
db_printf(" flags = 0x%x", pr->pr_flags);
for (fi = 0; fi < sizeof(pr_flag_names) / sizeof(pr_flag_names[0]);
fi++)
for (fi = 0; fi < nitems(pr_flag_names); fi++)
if (pr_flag_names[fi] != NULL && (pr->pr_flags & (1 << fi)))
db_printf(" %s", pr_flag_names[fi]);
for (fi = 0; fi < sizeof(pr_flag_jailsys) / sizeof(pr_flag_jailsys[0]);
fi++) {
for (fi = 0; fi < nitems(pr_flag_jailsys); fi++) {
jsf = pr->pr_flags &
(pr_flag_jailsys[fi].disable | pr_flag_jailsys[fi].new);
db_printf(" %-16s= %s\n", pr_flag_jailsys[fi].name,
@ -4709,8 +4699,7 @@ db_show_prison(struct prison *pr)
: "inherit");
}
db_printf(" allow = 0x%x", pr->pr_allow);
for (fi = 0; fi < sizeof(pr_allow_names) / sizeof(pr_allow_names[0]);
fi++)
for (fi = 0; fi < nitems(pr_allow_names); fi++)
if (pr_allow_names[fi] != NULL && (pr->pr_allow & (1 << fi)))
db_printf(" %s", pr_allow_names[fi]);
db_printf("\n");

View file

@ -1163,8 +1163,7 @@ ktr_writerequest(struct thread *td, struct ktr_request *req)
mtx_unlock(&ktrace_mtx);
kth = &req->ktr_header;
KASSERT(((u_short)kth->ktr_type & ~KTR_DROP) <
sizeof(data_lengths) / sizeof(data_lengths[0]),
KASSERT(((u_short)kth->ktr_type & ~KTR_DROP) < nitems(data_lengths),
("data_lengths array overflow"));
datalen = data_lengths[(u_short)kth->ktr_type & ~KTR_DROP];
buflen = kth->ktr_len;

View file

@ -101,7 +101,7 @@ hashdestroy(void *vhashtbl, struct malloc_type *type, u_long hashmask)
static const int primes[] = { 1, 13, 31, 61, 127, 251, 509, 761, 1021, 1531,
2039, 2557, 3067, 3583, 4093, 4603, 5119, 5623, 6143,
6653, 7159, 7673, 8191, 12281, 16381, 24571, 32749 };
#define NPRIMES (sizeof(primes) / sizeof(primes[0]))
#define NPRIMES nitems(primes)
/*
* General routine to allocate a prime number sized hash table.

View file

@ -709,8 +709,7 @@ static struct witness_order_list_entry order_lists[] = {
*/
static struct witness_blessed blessed_list[] = {
};
static int blessed_count =
sizeof(blessed_list) / sizeof(struct witness_blessed);
static int blessed_count = nitems(blessed_list);
#endif
/*

View file

@ -1519,7 +1519,7 @@ sys_msgsys(td, uap)
if (!prison_allow(td->td_ucred, PR_ALLOW_SYSVIPC))
return (ENOSYS);
if (uap->which < 0 ||
uap->which >= sizeof(msgcalls)/sizeof(msgcalls[0]))
uap->which >= nitems(msgcalls))
return (EINVAL);
error = (*msgcalls[uap->which])(td, &uap->a2);
return (error);

View file

@ -1401,7 +1401,7 @@ sys_semsys(td, uap)
if (!prison_allow(td->td_ucred, PR_ALLOW_SYSVIPC))
return (ENOSYS);
if (uap->which < 0 ||
uap->which >= sizeof(semcalls)/sizeof(semcalls[0]))
uap->which >= nitems(semcalls))
return (EINVAL);
error = (*semcalls[uap->which])(td, &uap->a2);
return (error);

View file

@ -337,7 +337,7 @@ static struct domain localdomain = {
.dom_externalize = unp_externalize,
.dom_dispose = unp_dispose_so,
.dom_protosw = localsw,
.dom_protoswNPROTOSW = &localsw[sizeof(localsw)/sizeof(localsw[0])]
.dom_protoswNPROTOSW = &localsw[nitems(localsw)]
};
DOMAIN_SET(local);

View file

@ -1919,7 +1919,7 @@ static struct domain routedomain = {
.dom_family = PF_ROUTE,
.dom_name = "route",
.dom_protosw = routesw,
.dom_protoswNPROTOSW = &routesw[sizeof(routesw)/sizeof(routesw[0])]
.dom_protoswNPROTOSW = &routesw[nitems(routesw)]
};
VNET_DOMAIN_SET(route);

View file

@ -357,7 +357,7 @@ struct domain inetdomain = {
.dom_family = AF_INET,
.dom_name = "internet",
.dom_protosw = inetsw,
.dom_protoswNPROTOSW = &inetsw[sizeof(inetsw)/sizeof(inetsw[0])],
.dom_protoswNPROTOSW = &inetsw[nitems(inetsw)],
#ifdef RADIX_MPATH
.dom_rtattach = rn4_mpath_inithead,
#else

View file

@ -1896,7 +1896,7 @@ syncookie_generate(struct syncache_head *sch, struct syncache *sc)
/* Map our computed MSS into the 3-bit index. */
mss = min(tcp_mssopt(&sc->sc_inc), max(sc->sc_peer_mss, V_tcp_minmss));
for (i = sizeof(tcp_sc_msstab) / sizeof(*tcp_sc_msstab) - 1;
for (i = nitems(tcp_sc_msstab) - 1;
tcp_sc_msstab[i] > mss && i > 0;
i--)
;
@ -1908,7 +1908,7 @@ syncookie_generate(struct syncache_head *sch, struct syncache *sc)
*/
if (sc->sc_flags & SCF_WINSCALE) {
wscale = sc->sc_requested_s_scale;
for (i = sizeof(tcp_sc_wstab) / sizeof(*tcp_sc_wstab) - 1;
for (i = nitems(tcp_sc_wstab) - 1;
tcp_sc_wstab[i] > wscale && i > 0;
i--)
;

View file

@ -382,7 +382,7 @@ struct domain inet6domain = {
.dom_name = "internet6",
.dom_protosw = (struct protosw *)inet6sw,
.dom_protoswNPROTOSW = (struct protosw *)
&inet6sw[sizeof(inet6sw)/sizeof(inet6sw[0])],
&inet6sw[nitems(inet6sw)],
#ifdef RADIX_MPATH
.dom_rtattach = rn6_mpath_inithead,
#else

View file

@ -3365,7 +3365,7 @@ key_setdumpsa(struct secasvar *sav, u_int8_t type, u_int8_t satype,
goto fail;
result = m;
for (i = sizeof(dumporder)/sizeof(dumporder[0]) - 1; i >= 0; i--) {
for (i = nitems(dumporder) - 1; i >= 0; i--) {
m = NULL;
switch (dumporder[i]) {
case SADB_EXT_SA:
@ -7410,7 +7410,7 @@ key_parse(struct mbuf *m, struct socket *so)
*/
}
if (msg->sadb_msg_type >= sizeof(key_typesw)/sizeof(key_typesw[0]) ||
if (msg->sadb_msg_type >= nitems(key_typesw) ||
key_typesw[msg->sadb_msg_type] == NULL) {
PFKEYSTAT_INC(out_invmsgtype);
error = EINVAL;
@ -7562,8 +7562,8 @@ key_validate_ext(const struct sadb_ext *ext, int len)
return EINVAL;
/* if it does not match minimum/maximum length, bail */
if (ext->sadb_ext_type >= sizeof(minsize) / sizeof(minsize[0]) ||
ext->sadb_ext_type >= sizeof(maxsize) / sizeof(maxsize[0]))
if (ext->sadb_ext_type >= nitems(minsize) ||
ext->sadb_ext_type >= nitems(maxsize))
return EINVAL;
if (!minsize[ext->sadb_ext_type] || len < minsize[ext->sadb_ext_type])
return EINVAL;

View file

@ -564,7 +564,7 @@ struct domain keydomain = {
.dom_destroy = key_destroy,
#endif
.dom_protosw = keysw,
.dom_protoswNPROTOSW = &keysw[sizeof(keysw)/sizeof(keysw[0])]
.dom_protoswNPROTOSW = &keysw[nitems(keysw)]
};
VNET_DOMAIN_SET(key);

View file

@ -87,7 +87,7 @@ static struct domain natmdomain = {
.dom_name = "natm",
.dom_init = natm_init,
.dom_protosw = natmsw,
.dom_protoswNPROTOSW = &natmsw[sizeof(natmsw)/sizeof(natmsw[0])],
.dom_protoswNPROTOSW = &natmsw[nitems(natmsw)],
};
static struct netisr_handler natm_nh = {

View file

@ -68,7 +68,7 @@ static struct smb_dialect smb_dialects[] = {
{-1, NULL}
};
#define SMB_DIALECT_MAX (sizeof(smb_dialects) / sizeof(struct smb_dialect) - 2)
#define SMB_DIALECT_MAX (nitems(smb_dialects) - 2)
static u_int32_t
smb_vc_maxread(struct smb_vc *vcp)