dev/(e1000,ixl): Make some use of mallocarray(9).

Reviewed by:	erj
Differential Revision: https://reviews.freebsd.org/D13833
This commit is contained in:
Pedro F. Giffuni 2018-01-11 15:25:26 +00:00
parent e426794f61
commit efaa3e0789
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=327828
4 changed files with 16 additions and 14 deletions

View File

@ -2835,9 +2835,9 @@ em_if_tx_queues_alloc(if_ctx_t ctx, caddr_t *vaddrs, uint64_t *paddrs, int ntxqs
/* First allocate the top level queue structs */
if (!(adapter->tx_queues =
(struct em_tx_queue *) malloc(sizeof(struct em_tx_queue) *
adapter->tx_num_queues, M_DEVBUF, M_NOWAIT | M_ZERO))) {
device_printf(iflib_get_dev(ctx), "Unable to allocate queue memory\n");
(struct em_tx_queue *) mallocarray(adapter->tx_num_queues,
sizeof(struct em_tx_queue), M_DEVBUF, M_NOWAIT | M_ZERO))) {
device_printf(iflib_get_dev(ctx), "Unable to allocate queue memory\n");
return(ENOMEM);
}
@ -2849,7 +2849,8 @@ em_if_tx_queues_alloc(if_ctx_t ctx, caddr_t *vaddrs, uint64_t *paddrs, int ntxqs
que->me = txr->me = i;
/* Allocate report status array */
if (!(txr->tx_rsq = (qidx_t *) malloc(sizeof(qidx_t) * scctx->isc_ntxd[0], M_DEVBUF, M_NOWAIT | M_ZERO))) {
if (!(txr->tx_rsq = (qidx_t *) mallocarray(scctx->isc_ntxd[0],
sizeof(qidx_t), M_DEVBUF, M_NOWAIT | M_ZERO))) {
device_printf(iflib_get_dev(ctx), "failed to allocate rs_idxs memory\n");
error = ENOMEM;
goto fail;
@ -2881,8 +2882,8 @@ em_if_rx_queues_alloc(if_ctx_t ctx, caddr_t *vaddrs, uint64_t *paddrs, int nrxqs
/* First allocate the top level queue structs */
if (!(adapter->rx_queues =
(struct em_rx_queue *) malloc(sizeof(struct em_rx_queue) *
adapter->rx_num_queues, M_DEVBUF, M_NOWAIT | M_ZERO))) {
(struct em_rx_queue *) mallocarray(adapter->rx_num_queues,
sizeof(struct em_rx_queue), M_DEVBUF, M_NOWAIT | M_ZERO))) {
device_printf(iflib_get_dev(ctx), "Unable to allocate queue memory\n");
error = ENOMEM;
goto fail;

View File

@ -1637,8 +1637,8 @@ ixlv_setup_queues(struct ixlv_sc *sc)
/* Get memory for the station queues */
if (!(vsi->queues =
(struct ixl_queue *) malloc(sizeof(struct ixl_queue) *
vsi->num_queues, M_DEVBUF, M_NOWAIT | M_ZERO))) {
(struct ixl_queue *) mallocarray(vsi->num_queues,
sizeof(struct ixl_queue), M_DEVBUF, M_NOWAIT | M_ZERO))) {
device_printf(dev, "Unable to allocate queue memory\n");
error = ENOMEM;
goto early;

View File

@ -1695,8 +1695,8 @@ ixl_iov_init(device_t dev, uint16_t num_vfs, const nvlist_t *params)
pf_vsi = &pf->vsi;
IXL_PF_LOCK(pf);
pf->vfs = malloc(sizeof(struct ixl_vf) * num_vfs, M_IXL, M_NOWAIT |
M_ZERO);
pf->vfs = mallocarray(num_vfs, sizeof(struct ixl_vf), M_IXL,
M_NOWAIT | M_ZERO);
if (pf->vfs == NULL) {
error = ENOMEM;

View File

@ -2431,8 +2431,8 @@ ixl_setup_stations(struct ixl_pf *pf)
/* Get memory for the station queues */
if (!(vsi->queues =
(struct ixl_queue *) malloc(sizeof(struct ixl_queue) *
vsi->num_queues, M_DEVBUF, M_NOWAIT | M_ZERO))) {
(struct ixl_queue *) mallocarray(vsi->num_queues,
sizeof(struct ixl_queue), M_DEVBUF, M_NOWAIT | M_ZERO))) {
device_printf(dev, "Unable to allocate queue memory\n");
error = ENOMEM;
return (error);
@ -3317,7 +3317,7 @@ ixl_add_hw_filters(struct ixl_vsi *vsi, int flags, int cnt)
hw = &pf->hw;
IXL_PF_LOCK_ASSERT(pf);
a = malloc(sizeof(struct i40e_aqc_add_macvlan_element_data) * cnt,
a = mallocarray(cnt, sizeof(struct i40e_aqc_add_macvlan_element_data),
M_DEVBUF, M_NOWAIT | M_ZERO);
if (a == NULL) {
device_printf(dev, "add_hw_filters failed to get memory\n");
@ -3380,7 +3380,8 @@ ixl_del_hw_filters(struct ixl_vsi *vsi, int cnt)
hw = &pf->hw;
dev = pf->dev;
d = malloc(sizeof(struct i40e_aqc_remove_macvlan_element_data) * cnt,
d = mallocarray(cnt,
sizeof(struct i40e_aqc_remove_macvlan_element_data),
M_DEVBUF, M_NOWAIT | M_ZERO);
if (d == NULL) {
printf("del hw filter failed to get memory\n");