From af8b614ef3330a479f6d31592c9a41da4ca7fe10 Mon Sep 17 00:00:00 2001 From: pfg Date: Mon, 15 Jan 2018 21:09:58 +0000 Subject: [PATCH] arm: 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 --- sys/arm/xscale/ixp425/if_npe.c | 3 ++- sys/arm64/arm64/busdma_bounce.c | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/sys/arm/xscale/ixp425/if_npe.c b/sys/arm/xscale/ixp425/if_npe.c index d797154ee1d4..c5c6033f01b7 100644 --- a/sys/arm/xscale/ixp425/if_npe.c +++ b/sys/arm/xscale/ixp425/if_npe.c @@ -515,7 +515,8 @@ npe_dma_setup(struct npe_softc *sc, struct npedma *dma, return error; } /* XXX M_TEMP */ - dma->buf = malloc(nbuf * sizeof(struct npebuf), M_TEMP, M_NOWAIT | M_ZERO); + dma->buf = mallocarray(nbuf, sizeof(struct npebuf), M_TEMP, + M_NOWAIT | M_ZERO); if (dma->buf == NULL) { device_printf(sc->sc_dev, "unable to allocate memory for %s s/w buffers\n", diff --git a/sys/arm64/arm64/busdma_bounce.c b/sys/arm64/arm64/busdma_bounce.c index 31eaf05370b6..9b6d944bd33d 100644 --- a/sys/arm64/arm64/busdma_bounce.c +++ b/sys/arm64/arm64/busdma_bounce.c @@ -302,8 +302,8 @@ bounce_bus_dmamap_create(bus_dma_tag_t dmat, int flags, bus_dmamap_t *mapp) error = 0; if (dmat->segments == NULL) { - dmat->segments = (bus_dma_segment_t *)malloc( - sizeof(bus_dma_segment_t) * dmat->common.nsegments, + dmat->segments = (bus_dma_segment_t *)mallocarray( + dmat->common.nsegments, sizeof(bus_dma_segment_t), M_DEVBUF, M_NOWAIT); if (dmat->segments == NULL) { CTR3(KTR_BUSDMA, "%s: tag %p error %d",