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
This commit is contained in:
Pedro F. Giffuni 2018-01-15 21:08:22 +00:00
parent a2674e031c
commit 74641f0bc6
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=328016
4 changed files with 4 additions and 4 deletions

View file

@ -186,7 +186,7 @@ bpf_jit_compile(struct bpf_insn *prog, u_int nins, size_t *size)
/* 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));

View file

@ -185,7 +185,7 @@ bpf_jit_compile(struct bpf_insn *prog, u_int nins, size_t *size)
/* 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));

View file

@ -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");

View file

@ -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;