aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sys/compat/linux/linux_socket.c2
-rw-r--r--sys/ddb/db_variables.c2
-rw-r--r--sys/fs/autofs/autofs.c2
-rw-r--r--sys/fs/nfs/nfs_commonkrpc.c4
-rw-r--r--sys/geom/part/g_part_bsd.c2
-rw-r--r--sys/geom/part/g_part_ebr.c4
-rw-r--r--sys/geom/part/g_part_ldm.c4
-rw-r--r--sys/geom/part/g_part_mbr.c4
-rw-r--r--sys/kern/kern_dump.c2
-rw-r--r--sys/kern/kern_ffclock.c2
-rw-r--r--sys/kern/kern_jail.c37
-rw-r--r--sys/kern/kern_ktrace.c3
-rw-r--r--sys/kern/subr_hash.c2
-rw-r--r--sys/kern/subr_witness.c3
-rw-r--r--sys/kern/sysv_msg.c2
-rw-r--r--sys/kern/sysv_sem.c2
-rw-r--r--sys/kern/uipc_usrreq.c2
-rw-r--r--sys/net/rtsock.c2
-rw-r--r--sys/netinet/in_proto.c2
-rw-r--r--sys/netinet/tcp_syncache.c4
-rw-r--r--sys/netinet6/in6_proto.c2
-rw-r--r--sys/netipsec/key.c8
-rw-r--r--sys/netipsec/keysock.c2
-rw-r--r--sys/netnatm/natm_proto.c2
-rw-r--r--sys/netsmb/smb_smb.c2
25 files changed, 45 insertions, 58 deletions
diff --git a/sys/compat/linux/linux_socket.c b/sys/compat/linux/linux_socket.c
index 741a45bb1bb5..105aec5230ab 100644
--- a/sys/compat/linux/linux_socket.c
+++ b/sys/compat/linux/linux_socket.c
@@ -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)
diff --git a/sys/ddb/db_variables.c b/sys/ddb/db_variables.c
index bd62db52f3cf..f48897adf147 100644
--- a/sys/ddb/db_variables.c
+++ b/sys/ddb/db_variables.c
@@ -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)
diff --git a/sys/fs/autofs/autofs.c b/sys/fs/autofs/autofs.c
index eee74ea43fa0..e339c80c196c 100644
--- a/sys/fs/autofs/autofs.c
+++ b/sys/fs/autofs/autofs.c
@@ -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
diff --git a/sys/fs/nfs/nfs_commonkrpc.c b/sys/fs/nfs/nfs_commonkrpc.c
index c1d50f4cfb2d..1a50ec8685fa 100644
--- a/sys/fs/nfs/nfs_commonkrpc.c
+++ b/sys/fs/nfs/nfs_commonkrpc.c
@@ -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
diff --git a/sys/geom/part/g_part_bsd.c b/sys/geom/part/g_part_bsd.c
index 5a5eabd31937..eaa5394b7c7c 100644
--- a/sys/geom/part/g_part_bsd.c
+++ b/sys/geom/part/g_part_bsd.c
@@ -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;
diff --git a/sys/geom/part/g_part_ebr.c b/sys/geom/part/g_part_ebr.c
index dfeda58538f3..e3e7e8f63db0 100644
--- a/sys/geom/part/g_part_ebr.c
+++ b/sys/geom/part/g_part_ebr.c
@@ -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));
}
diff --git a/sys/geom/part/g_part_ldm.c b/sys/geom/part/g_part_ldm.c
index 82bf76dad522..fec8e7716d41 100644
--- a/sys/geom/part/g_part_ldm.c
+++ b/sys/geom/part/g_part_ldm.c
@@ -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));
}
diff --git a/sys/geom/part/g_part_mbr.c b/sys/geom/part/g_part_mbr.c
index c340106ccb40..1bb9702a9ec6 100644
--- a/sys/geom/part/g_part_mbr.c
+++ b/sys/geom/part/g_part_mbr.c
@@ -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));
}
diff --git a/sys/kern/kern_dump.c b/sys/kern/kern_dump.c
index e3d338fd4e29..8e922a1e1bd7 100644
--- a/sys/kern/kern_dump.c
+++ b/sys/kern/kern_dump.c
@@ -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;
diff --git a/sys/kern/kern_ffclock.c b/sys/kern/kern_ffclock.c
index c168325b263c..d9101e8eeda4 100644
--- a/sys/kern/kern_ffclock.c
+++ b/sys/kern/kern_ffclock.c
@@ -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,
diff --git a/sys/kern/kern_jail.c b/sys/kern/kern_jail.c
index 6189d8ca6623..3e4f79833fc2 100644
--- a/sys/kern/kern_jail.c
+++ b/sys/kern/kern_jail.c
@@ -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");
diff --git a/sys/kern/kern_ktrace.c b/sys/kern/kern_ktrace.c
index 139fd31a9ac0..0e30fc9cd9c8 100644
--- a/sys/kern/kern_ktrace.c
+++ b/sys/kern/kern_ktrace.c
@@ -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;
diff --git a/sys/kern/subr_hash.c b/sys/kern/subr_hash.c
index fe8128691596..915f3f7bfe05 100644
--- a/sys/kern/subr_hash.c
+++ b/sys/kern/subr_hash.c
@@ -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.
diff --git a/sys/kern/subr_witness.c b/sys/kern/subr_witness.c
index 5ca1eb9814c6..29c83c0c4311 100644
--- a/sys/kern/subr_witness.c
+++ b/sys/kern/subr_witness.c
@@ -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
/*
diff --git a/sys/kern/sysv_msg.c b/sys/kern/sysv_msg.c
index 59357c492240..22845bb53d88 100644
--- a/sys/kern/sysv_msg.c
+++ b/sys/kern/sysv_msg.c
@@ -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);
diff --git a/sys/kern/sysv_sem.c b/sys/kern/sysv_sem.c
index 0063916c5194..d3546a186430 100644
--- a/sys/kern/sysv_sem.c
+++ b/sys/kern/sysv_sem.c
@@ -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);
diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c
index 4e5aa88a61c0..f0d282cebd7c 100644
--- a/sys/kern/uipc_usrreq.c
+++ b/sys/kern/uipc_usrreq.c
@@ -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);
diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c
index 810da1bad031..4a229136c1d2 100644
--- a/sys/net/rtsock.c
+++ b/sys/net/rtsock.c
@@ -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);
diff --git a/sys/netinet/in_proto.c b/sys/netinet/in_proto.c
index e7569c45f740..1d32caf42b90 100644
--- a/sys/netinet/in_proto.c
+++ b/sys/netinet/in_proto.c
@@ -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
diff --git a/sys/netinet/tcp_syncache.c b/sys/netinet/tcp_syncache.c
index 1cf27e1da923..91e4c5902570 100644
--- a/sys/netinet/tcp_syncache.c
+++ b/sys/netinet/tcp_syncache.c
@@ -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--)
;
diff --git a/sys/netinet6/in6_proto.c b/sys/netinet6/in6_proto.c
index cad09316cf94..68cb8fd7bdad 100644
--- a/sys/netinet6/in6_proto.c
+++ b/sys/netinet6/in6_proto.c
@@ -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
diff --git a/sys/netipsec/key.c b/sys/netipsec/key.c
index 7070c1df4510..4e8c633c7a18 100644
--- a/sys/netipsec/key.c
+++ b/sys/netipsec/key.c
@@ -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;
diff --git a/sys/netipsec/keysock.c b/sys/netipsec/keysock.c
index 73e54bb3de32..c3092e42f685 100644
--- a/sys/netipsec/keysock.c
+++ b/sys/netipsec/keysock.c
@@ -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);
diff --git a/sys/netnatm/natm_proto.c b/sys/netnatm/natm_proto.c
index b064c4340017..aa7fa2cd8511 100644
--- a/sys/netnatm/natm_proto.c
+++ b/sys/netnatm/natm_proto.c
@@ -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 = {
diff --git a/sys/netsmb/smb_smb.c b/sys/netsmb/smb_smb.c
index 6c732f9d4043..6d4f3898e1c3 100644
--- a/sys/netsmb/smb_smb.c
+++ b/sys/netsmb/smb_smb.c
@@ -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)