aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/mxge
diff options
context:
space:
mode:
authorPedro F. Giffuni <pfg@FreeBSD.org>2018-01-13 22:30:30 +0000
committerPedro F. Giffuni <pfg@FreeBSD.org>2018-01-13 22:30:30 +0000
commit26c1d774b55c4db79bca772941883244986e6f44 (patch)
tree0d4a99e9eba470c0808a66d7d3f857c9f36446fa /sys/dev/mxge
parenta019e26c0f76f5fd5c401cd87554ef2d5efc36ca (diff)
downloadsrc-26c1d774b55c4db79bca772941883244986e6f44.tar.gz
src-26c1d774b55c4db79bca772941883244986e6f44.zip
dev: make some use of mallocarray(9).
Focus on code where we are doing multiplications within malloc(9). None of these is 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.
Notes
Notes: svn path=/head/; revision=327949
Diffstat (limited to 'sys/dev/mxge')
-rw-r--r--sys/dev/mxge/if_mxge.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/sys/dev/mxge/if_mxge.c b/sys/dev/mxge/if_mxge.c
index edd5ff3a972f..44ddb7f1a6c2 100644
--- a/sys/dev/mxge/if_mxge.c
+++ b/sys/dev/mxge/if_mxge.c
@@ -688,7 +688,7 @@ z_alloc(void *nil, u_int items, u_int size)
{
void *ptr;
- ptr = malloc(items * size, M_TEMP, M_NOWAIT);
+ ptr = mallocarray(items, size, M_TEMP, M_NOWAIT);
return ptr;
}
@@ -4390,8 +4390,8 @@ mxge_alloc_slices(mxge_softc_t *sc)
sc->rx_ring_size = cmd.data0;
max_intr_slots = 2 * (sc->rx_ring_size / sizeof (mcp_dma_addr_t));
- bytes = sizeof (*sc->ss) * sc->num_slices;
- sc->ss = malloc(bytes, M_DEVBUF, M_NOWAIT | M_ZERO);
+ sc->ss = mallocarray(sc->num_slices, sizeof(*sc->ss), M_DEVBUF,
+ M_NOWAIT | M_ZERO);
if (sc->ss == NULL)
return (ENOMEM);
for (i = 0; i < sc->num_slices; i++) {
@@ -4563,8 +4563,8 @@ mxge_add_msix_irqs(mxge_softc_t *sc)
err = ENOSPC;
goto abort_with_msix;
}
- bytes = sizeof (*sc->msix_irq_res) * sc->num_slices;
- sc->msix_irq_res = malloc(bytes, M_DEVBUF, M_NOWAIT|M_ZERO);
+ sc->msix_irq_res = mallocarray(sc->num_slices,
+ sizeof(*sc->msix_irq_res), M_DEVBUF, M_NOWAIT|M_ZERO);
if (sc->msix_irq_res == NULL) {
err = ENOMEM;
goto abort_with_msix;
@@ -4583,8 +4583,8 @@ mxge_add_msix_irqs(mxge_softc_t *sc)
}
}
- bytes = sizeof (*sc->msix_ih) * sc->num_slices;
- sc->msix_ih = malloc(bytes, M_DEVBUF, M_NOWAIT|M_ZERO);
+ sc->msix_ih = mallocarray(sc->num_slices, sizeof(*sc->msix_ih),
+ M_DEVBUF, M_NOWAIT|M_ZERO);
for (i = 0; i < sc->num_slices; i++) {
err = bus_setup_intr(sc->dev, sc->msix_irq_res[i],