aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/ral
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/ral
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/ral')
-rw-r--r--sys/dev/ral/rt2560.c6
-rw-r--r--sys/dev/ral/rt2661.c4
2 files changed, 5 insertions, 5 deletions
diff --git a/sys/dev/ral/rt2560.c b/sys/dev/ral/rt2560.c
index 9da26a8f581a..ce396dc81094 100644
--- a/sys/dev/ral/rt2560.c
+++ b/sys/dev/ral/rt2560.c
@@ -488,7 +488,7 @@ rt2560_alloc_tx_ring(struct rt2560_softc *sc, struct rt2560_tx_ring *ring,
goto fail;
}
- ring->data = malloc(count * sizeof (struct rt2560_tx_data), M_DEVBUF,
+ ring->data = mallocarray(count, sizeof(struct rt2560_tx_data), M_DEVBUF,
M_NOWAIT | M_ZERO);
if (ring->data == NULL) {
device_printf(sc->sc_dev, "could not allocate soft data\n");
@@ -632,8 +632,8 @@ rt2560_alloc_rx_ring(struct rt2560_softc *sc, struct rt2560_rx_ring *ring,
goto fail;
}
- ring->data = malloc(count * sizeof (struct rt2560_rx_data), M_DEVBUF,
- M_NOWAIT | M_ZERO);
+ ring->data = mallocarray(count, sizeof (struct rt2560_rx_data),
+ M_DEVBUF, M_NOWAIT | M_ZERO);
if (ring->data == NULL) {
device_printf(sc->sc_dev, "could not allocate soft data\n");
error = ENOMEM;
diff --git a/sys/dev/ral/rt2661.c b/sys/dev/ral/rt2661.c
index aab385a5855f..55dedd4eaba6 100644
--- a/sys/dev/ral/rt2661.c
+++ b/sys/dev/ral/rt2661.c
@@ -497,7 +497,7 @@ rt2661_alloc_tx_ring(struct rt2661_softc *sc, struct rt2661_tx_ring *ring,
goto fail;
}
- ring->data = malloc(count * sizeof (struct rt2661_tx_data), M_DEVBUF,
+ ring->data = mallocarray(count, sizeof(struct rt2661_tx_data), M_DEVBUF,
M_NOWAIT | M_ZERO);
if (ring->data == NULL) {
device_printf(sc->sc_dev, "could not allocate soft data\n");
@@ -638,7 +638,7 @@ rt2661_alloc_rx_ring(struct rt2661_softc *sc, struct rt2661_rx_ring *ring,
goto fail;
}
- ring->data = malloc(count * sizeof (struct rt2661_rx_data), M_DEVBUF,
+ ring->data = mallocarray(count, sizeof(struct rt2661_rx_data), M_DEVBUF,
M_NOWAIT | M_ZERO);
if (ring->data == NULL) {
device_printf(sc->sc_dev, "could not allocate soft data\n");