From: deraadt Date: Sun, 11 Jan 2015 03:06:19 +0000 (+0000) Subject: mallocarray() for the rx_buffer memory X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=ffd39ae77489612981db69f130612484366ddd57;p=openbsd mallocarray() for the rx_buffer memory --- diff --git a/sys/dev/pci/if_ix.c b/sys/dev/pci/if_ix.c index cf1539c1a42..a69d6e4a63c 100644 --- a/sys/dev/pci/if_ix.c +++ b/sys/dev/pci/if_ix.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_ix.c,v 1.113 2014/12/22 02:28:52 tedu Exp $ */ +/* $OpenBSD: if_ix.c,v 1.114 2015/01/11 03:06:19 deraadt Exp $ */ /****************************************************************************** @@ -230,7 +230,7 @@ ixgbe_attach(struct device *parent, struct device *self, void *aux) goto err_out; /* Allocate multicast array memory. */ - sc->mta = malloc(sizeof(uint8_t) * IXGBE_ETH_LENGTH_OF_ADDRESS * + sc->mta = mallocarray(IXGBE_ETH_LENGTH_OF_ADDRESS, MAX_NUM_MULTICAST_ADDRESSES, M_DEVBUF, M_NOWAIT); if (sc->mta == NULL) { printf(": Can not allocate multicast setup array\n"); @@ -2475,13 +2475,14 @@ ixgbe_allocate_receive_buffers(struct rx_ring *rxr) int i, bsize, error; bsize = sizeof(struct ixgbe_rx_buf) * sc->num_rx_desc; - if (!(rxr->rx_buffers = (struct ixgbe_rx_buf *) malloc(bsize, - M_DEVBUF, M_NOWAIT | M_ZERO))) { + if (!(rxr->rx_buffers = mallocarray(sc->num_rx_desc, + sizeof(struct ixgbe_rx_buf), M_DEVBUF, M_NOWAIT | M_ZERO))) { printf("%s: Unable to allocate rx_buffer memory\n", ifp->if_xname); error = ENOMEM; goto fail; } + bsize = sizeof(struct ixgbe_rx_buf) * sc->num_rx_desc; rxbuf = rxr->rx_buffers; for (i = 0; i < sc->num_rx_desc; i++, rxbuf++) {