net*: 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
3b0a4e40a0
commit
443133416b
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=328025
@ -479,7 +479,7 @@ vlan_growhash(struct ifvlantrunk *trunk, int howmuch)
|
||||
return;
|
||||
|
||||
/* M_NOWAIT because we're called with trunk mutex held */
|
||||
hash2 = malloc(sizeof(struct ifvlanhead) * n2, M_VLAN, M_NOWAIT);
|
||||
hash2 = mallocarray(n2, sizeof(struct ifvlanhead), M_VLAN, M_NOWAIT);
|
||||
if (hash2 == NULL) {
|
||||
printf("%s: out of memory -- hash size not changed\n",
|
||||
__func__);
|
||||
|
@ -1550,15 +1550,15 @@ iflib_txsd_alloc(iflib_txq_t txq)
|
||||
goto fail;
|
||||
}
|
||||
if (!(txq->ift_sds.ifsd_flags =
|
||||
(uint8_t *) malloc(sizeof(uint8_t) *
|
||||
scctx->isc_ntxd[txq->ift_br_offset], M_IFLIB, M_NOWAIT | M_ZERO))) {
|
||||
(uint8_t *) mallocarray(scctx->isc_ntxd[txq->ift_br_offset],
|
||||
sizeof(uint8_t), M_IFLIB, M_NOWAIT | M_ZERO))) {
|
||||
device_printf(dev, "Unable to allocate tx_buffer memory\n");
|
||||
err = ENOMEM;
|
||||
goto fail;
|
||||
}
|
||||
if (!(txq->ift_sds.ifsd_m =
|
||||
(struct mbuf **) malloc(sizeof(struct mbuf *) *
|
||||
scctx->isc_ntxd[txq->ift_br_offset], M_IFLIB, M_NOWAIT | M_ZERO))) {
|
||||
(struct mbuf **) mallocarray(scctx->isc_ntxd[txq->ift_br_offset],
|
||||
sizeof(struct mbuf *), M_IFLIB, M_NOWAIT | M_ZERO))) {
|
||||
device_printf(dev, "Unable to allocate tx_buffer memory\n");
|
||||
err = ENOMEM;
|
||||
goto fail;
|
||||
@ -1570,7 +1570,8 @@ iflib_txsd_alloc(iflib_txq_t txq)
|
||||
return (0);
|
||||
|
||||
if (!(txq->ift_sds.ifsd_map =
|
||||
(bus_dmamap_t *) malloc(sizeof(bus_dmamap_t) * scctx->isc_ntxd[txq->ift_br_offset], M_IFLIB, M_NOWAIT | M_ZERO))) {
|
||||
(bus_dmamap_t *) mallocarray(scctx->isc_ntxd[txq->ift_br_offset],
|
||||
sizeof(bus_dmamap_t), M_IFLIB, M_NOWAIT | M_ZERO))) {
|
||||
device_printf(dev, "Unable to allocate tx_buffer map memory\n");
|
||||
err = ENOMEM;
|
||||
goto fail;
|
||||
@ -1726,22 +1727,22 @@ iflib_rxsd_alloc(iflib_rxq_t rxq)
|
||||
goto fail;
|
||||
}
|
||||
if (!(fl->ifl_sds.ifsd_flags =
|
||||
(uint8_t *) malloc(sizeof(uint8_t) *
|
||||
scctx->isc_nrxd[rxq->ifr_fl_offset], M_IFLIB, M_NOWAIT | M_ZERO))) {
|
||||
(uint8_t *) mallocarray(scctx->isc_nrxd[rxq->ifr_fl_offset],
|
||||
sizeof(uint8_t), M_IFLIB, M_NOWAIT | M_ZERO))) {
|
||||
device_printf(dev, "Unable to allocate tx_buffer memory\n");
|
||||
err = ENOMEM;
|
||||
goto fail;
|
||||
}
|
||||
if (!(fl->ifl_sds.ifsd_m =
|
||||
(struct mbuf **) malloc(sizeof(struct mbuf *) *
|
||||
scctx->isc_nrxd[rxq->ifr_fl_offset], M_IFLIB, M_NOWAIT | M_ZERO))) {
|
||||
(struct mbuf **) mallocarray(scctx->isc_nrxd[rxq->ifr_fl_offset],
|
||||
sizeof(struct mbuf *), M_IFLIB, M_NOWAIT | M_ZERO))) {
|
||||
device_printf(dev, "Unable to allocate tx_buffer memory\n");
|
||||
err = ENOMEM;
|
||||
goto fail;
|
||||
}
|
||||
if (!(fl->ifl_sds.ifsd_cl =
|
||||
(caddr_t *) malloc(sizeof(caddr_t) *
|
||||
scctx->isc_nrxd[rxq->ifr_fl_offset], M_IFLIB, M_NOWAIT | M_ZERO))) {
|
||||
(caddr_t *) mallocarray(scctx->isc_nrxd[rxq->ifr_fl_offset],
|
||||
sizeof(caddr_t), M_IFLIB, M_NOWAIT | M_ZERO))) {
|
||||
device_printf(dev, "Unable to allocate tx_buffer memory\n");
|
||||
err = ENOMEM;
|
||||
goto fail;
|
||||
@ -1753,7 +1754,8 @@ iflib_rxsd_alloc(iflib_rxq_t rxq)
|
||||
continue;
|
||||
|
||||
if (!(fl->ifl_sds.ifsd_map =
|
||||
(bus_dmamap_t *) malloc(sizeof(bus_dmamap_t) * scctx->isc_nrxd[rxq->ifr_fl_offset], M_IFLIB, M_NOWAIT | M_ZERO))) {
|
||||
(bus_dmamap_t *) mallocarray(scctx->isc_nrxd[rxq->ifr_fl_offset],
|
||||
sizeof(bus_dmamap_t), M_IFLIB, M_NOWAIT | M_ZERO))) {
|
||||
device_printf(dev, "Unable to allocate tx_buffer map memory\n");
|
||||
err = ENOMEM;
|
||||
goto fail;
|
||||
@ -4745,8 +4747,8 @@ iflib_queues_alloc(if_ctx_t ctx)
|
||||
|
||||
/* Allocate the TX ring struct memory */
|
||||
if (!(txq =
|
||||
(iflib_txq_t) malloc(sizeof(struct iflib_txq) *
|
||||
ntxqsets, M_IFLIB, M_NOWAIT | M_ZERO))) {
|
||||
(iflib_txq_t) mallocarray(ntxqsets, sizeof(struct iflib_txq),
|
||||
M_IFLIB, M_NOWAIT | M_ZERO))) {
|
||||
device_printf(dev, "Unable to allocate TX ring memory\n");
|
||||
err = ENOMEM;
|
||||
goto fail;
|
||||
@ -4754,8 +4756,8 @@ iflib_queues_alloc(if_ctx_t ctx)
|
||||
|
||||
/* Now allocate the RX */
|
||||
if (!(rxq =
|
||||
(iflib_rxq_t) malloc(sizeof(struct iflib_rxq) *
|
||||
nrxqsets, M_IFLIB, M_NOWAIT | M_ZERO))) {
|
||||
(iflib_rxq_t) mallocarray(nrxqsets, sizeof(struct iflib_rxq),
|
||||
M_IFLIB, M_NOWAIT | M_ZERO))) {
|
||||
device_printf(dev, "Unable to allocate RX ring memory\n");
|
||||
err = ENOMEM;
|
||||
goto rx_fail;
|
||||
@ -4849,7 +4851,8 @@ iflib_queues_alloc(if_ctx_t ctx)
|
||||
}
|
||||
rxq->ifr_nfl = nfree_lists;
|
||||
if (!(fl =
|
||||
(iflib_fl_t) malloc(sizeof(struct iflib_fl) * nfree_lists, M_IFLIB, M_NOWAIT | M_ZERO))) {
|
||||
(iflib_fl_t) mallocarray(nfree_lists, sizeof(struct iflib_fl),
|
||||
M_IFLIB, M_NOWAIT | M_ZERO))) {
|
||||
device_printf(dev, "Unable to allocate free list memory\n");
|
||||
err = ENOMEM;
|
||||
goto err_tx_desc;
|
||||
|
@ -103,8 +103,8 @@ prison_restrict_ip6(struct prison *pr, struct in6_addr *newip6)
|
||||
*/
|
||||
used = 1;
|
||||
if (newip6 == NULL) {
|
||||
newip6 = malloc(ppr->pr_ip6s * sizeof(*newip6),
|
||||
M_PRISON, M_NOWAIT);
|
||||
newip6 = mallocarray(ppr->pr_ip6s,
|
||||
sizeof(*newip6), M_PRISON, M_NOWAIT);
|
||||
if (newip6 != NULL)
|
||||
used = 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user