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:
parent
3c9ef68521
commit
a7c6776f59
@ -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));
|
||||
|
@ -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));
|
||||
|
@ -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");
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user