Author: pfg Date: Mon Jan 15 21:08:22 2018 New Revision: 328016 URL: https://svnweb.freebsd.org/changeset/base/328016
Log: x86: make some use of mallocarray(9). Focus on code where we are doing multiplications within malloc(9). None of these ire likely to overflow, however the change is still useful as some static checkers can benefit from the allocation attributes we use for mallocarray. This initial sweep only covers malloc(9) calls with M_NOWAIT. No good reason but I started doing the changes before r327796 and at that time it was convenient to make sure the sorrounding code could handle NULL values. X-Differential revision: https://reviews.freebsd.org/D13837 Modified: head/sys/amd64/amd64/bpf_jit_machdep.c head/sys/i386/i386/bpf_jit_machdep.c head/sys/i386/i386/k6_mem.c head/sys/x86/cpufreq/est.c Modified: head/sys/amd64/amd64/bpf_jit_machdep.c ============================================================================== --- head/sys/amd64/amd64/bpf_jit_machdep.c Mon Jan 15 20:39:42 2018 (r328015) +++ head/sys/amd64/amd64/bpf_jit_machdep.c Mon Jan 15 21:08:22 2018 (r328016) @@ -186,7 +186,7 @@ bpf_jit_compile(struct bpf_insn *prog, u_int nins, siz /* Allocate the reference table for the jumps. */ if (fjmp) { #ifdef _KERNEL - stream.refs = malloc((nins + 1) * sizeof(u_int), M_BPFJIT, + stream.refs = mallocarray(nins + 1, sizeof(u_int), M_BPFJIT, M_NOWAIT | M_ZERO); #else stream.refs = calloc(nins + 1, sizeof(u_int)); Modified: head/sys/i386/i386/bpf_jit_machdep.c ============================================================================== --- head/sys/i386/i386/bpf_jit_machdep.c Mon Jan 15 20:39:42 2018 (r328015) +++ head/sys/i386/i386/bpf_jit_machdep.c Mon Jan 15 21:08:22 2018 (r328016) @@ -185,7 +185,7 @@ bpf_jit_compile(struct bpf_insn *prog, u_int nins, siz /* Allocate the reference table for the jumps. */ if (fjmp) { #ifdef _KERNEL - stream.refs = malloc((nins + 1) * sizeof(u_int), M_BPFJIT, + stream.refs = mallocarray(nins + 1, sizeof(u_int), M_BPFJIT, M_NOWAIT | M_ZERO); #else stream.refs = calloc(nins + 1, sizeof(u_int)); Modified: head/sys/i386/i386/k6_mem.c ============================================================================== --- head/sys/i386/i386/k6_mem.c Mon Jan 15 20:39:42 2018 (r328015) +++ head/sys/i386/i386/k6_mem.c Mon Jan 15 21:08:22 2018 (r328016) @@ -107,7 +107,7 @@ k6_mrinit(struct mem_range_softc *sc) sc->mr_cap = 0; sc->mr_ndesc = 2; /* XXX (BFF) For now, we only have one msr for this */ - sc->mr_desc = malloc(sc->mr_ndesc * sizeof(struct mem_range_desc), + sc->mr_desc = mallocarray(sc->mr_ndesc, sizeof(struct mem_range_desc), M_MEMDESC, M_NOWAIT | M_ZERO); if (sc->mr_desc == NULL) panic("k6_mrinit: malloc returns NULL"); Modified: head/sys/x86/cpufreq/est.c ============================================================================== --- head/sys/x86/cpufreq/est.c Mon Jan 15 20:39:42 2018 (r328015) +++ head/sys/x86/cpufreq/est.c Mon Jan 15 21:08:22 2018 (r328016) @@ -1119,7 +1119,7 @@ est_acpi_info(device_t dev, freq_info **freqs) goto out; /* Parse settings into our local table format. */ - table = malloc((count + 1) * sizeof(freq_info), M_DEVBUF, M_NOWAIT); + table = mallocarray(count + 1, sizeof(freq_info), M_DEVBUF, M_NOWAIT); if (table == NULL) { error = ENOMEM; goto out; _______________________________________________ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"