diff options
author | Jasper Lievisse Adriaanse <jasper@cvs.openbsd.org> | 2014-07-13 12:11:02 +0000 |
---|---|---|
committer | Jasper Lievisse Adriaanse <jasper@cvs.openbsd.org> | 2014-07-13 12:11:02 +0000 |
commit | 80e50dabeaa559b5257135a152de27644db4432f (patch) | |
tree | 709cd9b655dfef589834933b2becb4db65e32a28 /sys/arch/amd64 | |
parent | f1b98cae21f0f62799fbbc23fee97381c77bda62 (diff) |
use nitems() instead of handrolling something identical
ok mpi@ sthen@
Diffstat (limited to 'sys/arch/amd64')
-rw-r--r-- | sys/arch/amd64/amd64/amd64_mem.c | 8 | ||||
-rw-r--r-- | sys/arch/amd64/amd64/amd64errata.c | 4 | ||||
-rw-r--r-- | sys/arch/amd64/amd64/bios.c | 4 | ||||
-rw-r--r-- | sys/arch/amd64/amd64/db_trace.c | 5 | ||||
-rw-r--r-- | sys/arch/amd64/amd64/identcpu.c | 26 | ||||
-rw-r--r-- | sys/arch/amd64/amd64/machdep.c | 4 | ||||
-rw-r--r-- | sys/arch/amd64/amd64/trap.c | 4 |
7 files changed, 22 insertions, 33 deletions
diff --git a/sys/arch/amd64/amd64/amd64_mem.c b/sys/arch/amd64/amd64/amd64_mem.c index d709b9cbafe..ce0fd6d7727 100644 --- a/sys/arch/amd64/amd64/amd64_mem.c +++ b/sys/arch/amd64/amd64/amd64_mem.c @@ -1,4 +1,4 @@ -/* $OpenBSD: amd64_mem.c,v 1.7 2013/08/24 04:26:15 mlarkin Exp $ */ +/* $OpenBSD: amd64_mem.c,v 1.8 2014/07/13 12:11:01 jasper Exp $ */ /* * Copyright (c) 1999 Michael Smith <msmith@freebsd.org> * All rights reserved. @@ -106,12 +106,10 @@ int mtrrtomrt[] = { MDF_WRITEBACK }; -#define MTRRTOMRTLEN (sizeof(mtrrtomrt) / sizeof(mtrrtomrt[0])) - int mtrr2mrt(int val) { - if (val < 0 || val >= MTRRTOMRTLEN) + if (val < 0 || val >= nitems(mtrrtomrt)) return MDF_UNKNOWN; return mtrrtomrt[val]; } @@ -249,7 +247,7 @@ mtrrtype(u_int64_t flags) flags &= MDF_ATTRMASK; - for (i = 0; i < MTRRTOMRTLEN; i++) { + for (i = 0; i < nitems(mtrrtomrt); i++) { if (mtrrtomrt[i] == MDF_UNKNOWN) continue; if (flags == mtrrtomrt[i]) diff --git a/sys/arch/amd64/amd64/amd64errata.c b/sys/arch/amd64/amd64/amd64errata.c index cfc5654a458..b1123e1c12b 100644 --- a/sys/arch/amd64/amd64/amd64errata.c +++ b/sys/arch/amd64/amd64/amd64errata.c @@ -1,4 +1,4 @@ -/* $OpenBSD: amd64errata.c,v 1.6 2013/12/07 01:43:50 brad Exp $ */ +/* $OpenBSD: amd64errata.c,v 1.7 2014/07/13 12:11:01 jasper Exp $ */ /* $NetBSD: errata.c,v 1.6 2007/02/05 21:05:45 ad Exp $ */ /*- @@ -312,7 +312,7 @@ amd64_errata(struct cpu_info *ci) } } - ex = errata + sizeof(errata) / sizeof(errata[0]); + ex = errata + nitems(errata); /* Reset e_reporteds (for multiple CPUs) */ for (e = errata; e < ex; e++) diff --git a/sys/arch/amd64/amd64/bios.c b/sys/arch/amd64/amd64/bios.c index cbeedf44020..54d41042bb9 100644 --- a/sys/arch/amd64/amd64/bios.c +++ b/sys/arch/amd64/amd64/bios.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bios.c,v 1.26 2013/11/19 04:12:17 guenther Exp $ */ +/* $OpenBSD: bios.c,v 1.27 2014/07/13 12:11:01 jasper Exp $ */ /* * Copyright (c) 2006 Gordon Willem Klok <gklok@cogeco.ca> * @@ -314,7 +314,7 @@ fixstring(char *s) char *p, *e; int i; - for (i = 0; i < sizeof(smbios_uninfo)/sizeof(smbios_uninfo[0]); i++) + for (i = 0; i < nitems(smbios_uninfo); i++) if ((strncasecmp(s, smbios_uninfo[i], strlen(smbios_uninfo[i])))==0) return NULL; diff --git a/sys/arch/amd64/amd64/db_trace.c b/sys/arch/amd64/amd64/db_trace.c index b784e72172f..1b45a85ac9d 100644 --- a/sys/arch/amd64/amd64/db_trace.c +++ b/sys/arch/amd64/amd64/db_trace.c @@ -1,4 +1,4 @@ -/* $OpenBSD: db_trace.c,v 1.7 2010/09/27 10:08:28 mikeb Exp $ */ +/* $OpenBSD: db_trace.c,v 1.8 2014/07/13 12:11:01 jasper Exp $ */ /* $NetBSD: db_trace.c,v 1.1 2003/04/26 18:39:27 fvdl Exp $ */ /* @@ -79,8 +79,7 @@ struct db_variable db_regs[] = { { "rsp", dbreg(rsp), db_x86_64_regop }, { "ss", dbreg(ss), db_x86_64_regop }, }; -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_x86_64_regop(struct db_variable *vp, db_expr_t *val, int opcode) diff --git a/sys/arch/amd64/amd64/identcpu.c b/sys/arch/amd64/amd64/identcpu.c index 3bde63ec12f..3f8d5146b7f 100644 --- a/sys/arch/amd64/amd64/identcpu.c +++ b/sys/arch/amd64/amd64/identcpu.c @@ -1,4 +1,4 @@ -/* $OpenBSD: identcpu.c,v 1.53 2014/07/03 21:15:28 matthew Exp $ */ +/* $OpenBSD: identcpu.c,v 1.54 2014/07/13 12:11:01 jasper Exp $ */ /* $NetBSD: identcpu.c,v 1.1 2003/04/26 18:39:28 fvdl Exp $ */ /* @@ -385,7 +385,7 @@ identifycpu(struct cpu_info *ci) u_int32_t dummy, val, pnfeatset; u_int32_t brand[12]; char mycpu_model[48]; - int i, max; + int i; char *brandstr_from, *brandstr_to; int skipspace; @@ -477,37 +477,29 @@ identifycpu(struct cpu_info *ci) printf("\n%s: ", ci->ci_dev->dv_xname); - max = sizeof(cpu_cpuid_features) / sizeof(cpu_cpuid_features[0]); - for (i = 0; i < max; i++) + for (i = 0; i < nitems(cpu_cpuid_features); i++) if (ci->ci_feature_flags & cpu_cpuid_features[i].bit) printf("%s%s", i? "," : "", cpu_cpuid_features[i].str); - max = sizeof(cpu_cpuid_ecxfeatures) / sizeof(cpu_cpuid_ecxfeatures[0]); - for (i = 0; i < max; i++) + for (i = 0; i < nitems(cpu_cpuid_ecxfeatures); i++) if (cpu_ecxfeature & cpu_cpuid_ecxfeatures[i].bit) printf(",%s", cpu_cpuid_ecxfeatures[i].str); - max = sizeof(cpu_ecpuid_features) / sizeof(cpu_ecpuid_features[0]); - for (i = 0; i < max; i++) + for (i = 0; i < nitems(cpu_ecpuid_features); i++) if (ci->ci_feature_eflags & cpu_ecpuid_features[i].bit) printf(",%s", cpu_ecpuid_features[i].str); - max = sizeof(cpu_ecpuid_ecxfeatures) / sizeof(cpu_ecpuid_ecxfeatures[0]); - for (i = 0; i < max; i++) + for (i = 0; i < nitems(cpu_ecpuid_ecxfeatures); i++) if (ecpu_ecxfeature & cpu_ecpuid_ecxfeatures[i].bit) printf(",%s", cpu_ecpuid_ecxfeatures[i].str); - max = sizeof(cpu_cpuid_perf_eax) / sizeof(cpu_cpuid_perf_eax[0]); - for (i = 0; i < max; i++) + for (i = 0; i < nitems(cpu_cpuid_perf_eax); i++) if (cpu_perf_eax & cpu_cpuid_perf_eax[i].bit) printf(",%s", cpu_cpuid_perf_eax[i].str); - max = sizeof(cpu_cpuid_apmi_edx) / sizeof(cpu_cpuid_apmi_edx[0]); - for (i = 0; i < max; i++) + for (i = 0; i < nitems(cpu_cpuid_apmi_edx); i++) if (cpu_apmi_edx & cpu_cpuid_apmi_edx[i].bit) printf(",%s", cpu_cpuid_apmi_edx[i].str); if (cpuid_level >= 0x07) { /* "Structured Extended Feature Flags" */ CPUID_LEAF(0x7, 0, dummy, ci->ci_feature_sefflags, dummy, dummy); - max = sizeof(cpu_seff0_ebxfeatures) / - sizeof(cpu_seff0_ebxfeatures[0]); - for (i = 0; i < max; i++) + for (i = 0; i < nitems(cpu_seff0_ebxfeatures); i++) if (ci->ci_feature_sefflags & cpu_seff0_ebxfeatures[i].bit) printf(",%s", cpu_seff0_ebxfeatures[i].str); diff --git a/sys/arch/amd64/amd64/machdep.c b/sys/arch/amd64/amd64/machdep.c index d42dd320596..af754189a7b 100644 --- a/sys/arch/amd64/amd64/machdep.c +++ b/sys/arch/amd64/amd64/machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machdep.c,v 1.185 2014/07/11 22:28:05 uebayasi Exp $ */ +/* $OpenBSD: machdep.c,v 1.186 2014/07/13 12:11:01 jasper Exp $ */ /* $NetBSD: machdep.c,v 1.3 2003/05/07 22:58:18 fvdl Exp $ */ /*- @@ -1862,7 +1862,7 @@ getbootinfo(char *bootinfo, int bootinfo_size) int unit = minor(cdp->consdev); int consaddr = cdp->consaddr; if (consaddr == -1 && unit >= 0 && - unit < (sizeof(ports)/sizeof(ports[0]))) + unit < nitems(ports)) consaddr = ports[unit]; if (major(cdp->consdev) == 8 && consaddr != -1) { diff --git a/sys/arch/amd64/amd64/trap.c b/sys/arch/amd64/amd64/trap.c index 67e2ec884a3..8ec6571fd0e 100644 --- a/sys/arch/amd64/amd64/trap.c +++ b/sys/arch/amd64/amd64/trap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trap.c,v 1.41 2014/07/09 07:29:00 guenther Exp $ */ +/* $OpenBSD: trap.c,v 1.42 2014/07/13 12:11:01 jasper Exp $ */ /* $NetBSD: trap.c,v 1.2 2003/05/04 23:51:56 fvdl Exp $ */ /*- @@ -124,7 +124,7 @@ const char *trap_type[] = { "SSE FP exception", /* 19 T_XMM */ "reserved trap", /* 20 T_RESERVED */ }; -int trap_types = sizeof trap_type / sizeof trap_type[0]; +int trap_types = nitems(trap_type); #ifdef DEBUG int trapdebug = 0; |