Split the allocation of a struct ice_vsi_stats and its two ring stats arrays out of ice_vsi_alloc_stat_arrays(), which is left with just the lookup and the store into pf->vsi_stats[]. The sole caller keeps passing the very same queue counts as before, vsi->alloc_txq and vsi->alloc_rxq. A later commit adds a second caller in the rebuild path, which cannot use vsi->alloc_* because it has to size the arrays before the VSI is reconfigured. Note that the error path no longer clears pf->vsi_stats[vsi->idx]; the early return above guarantees it is already NULL. No functional change intended. Signed-off-by: Przemek Kitszel --- drivers/net/ethernet/intel/ice/ice_lib.c | 47 +++++++++++++----------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/drivers/net/ethernet/intel/ice/ice_lib.c b/drivers/net/ethernet/intel/ice/ice_lib.c index cd78c5c69a30..9c2863fc696c 100644 --- a/drivers/net/ethernet/intel/ice/ice_lib.c +++ b/drivers/net/ethernet/intel/ice/ice_lib.c @@ -519,6 +519,30 @@ static irqreturn_t ice_msix_clean_rings(int __always_unused irq, void *data) return IRQ_HANDLED; } +static struct ice_vsi_stats *ice_vsi_new_stat_arrays(int txq, int rxq) +{ + struct ice_ring_stats **tx_ring_stats; + struct ice_ring_stats **rx_ring_stats; + struct ice_vsi_stats *vsi_stat; + + vsi_stat = kzalloc_obj(*vsi_stat); + tx_ring_stats = kzalloc_objs(*tx_ring_stats, txq); + rx_ring_stats = kzalloc_objs(*rx_ring_stats, rxq); + if (!vsi_stat || !tx_ring_stats || !rx_ring_stats) { + kfree(vsi_stat); + kfree(tx_ring_stats); + kfree(rx_ring_stats); + return NULL; + } + + vsi_stat->tx_ring_stats = tx_ring_stats; + vsi_stat->rx_ring_stats = rx_ring_stats; + vsi_stat->tx_ring_stats_len = txq; + vsi_stat->rx_ring_stats_len = rxq; + + return vsi_stat; +} + /** * ice_vsi_alloc_stat_arrays - Allocate statistics arrays * @vsi: VSI pointer @@ -537,33 +561,12 @@ static int ice_vsi_alloc_stat_arrays(struct ice_vsi *vsi) /* realloc will happen in rebuild path */ return 0; - vsi_stat = kzalloc_obj(*vsi_stat); + vsi_stat = ice_vsi_new_stat_arrays(vsi->alloc_txq, vsi->alloc_rxq); if (!vsi_stat) return -ENOMEM; - vsi_stat->tx_ring_stats = - kzalloc_objs(*vsi_stat->tx_ring_stats, vsi->alloc_txq); - if (!vsi_stat->tx_ring_stats) - goto err_alloc_tx; - vsi_stat->tx_ring_stats_len = vsi->alloc_txq; - - vsi_stat->rx_ring_stats = - kzalloc_objs(*vsi_stat->rx_ring_stats, vsi->alloc_rxq); - if (!vsi_stat->rx_ring_stats) - goto err_alloc_rx; - vsi_stat->rx_ring_stats_len = vsi->alloc_rxq; - pf->vsi_stats[vsi->idx] = vsi_stat; - return 0; - -err_alloc_rx: - kfree(vsi_stat->rx_ring_stats); -err_alloc_tx: - kfree(vsi_stat->tx_ring_stats); - kfree(vsi_stat); - pf->vsi_stats[vsi->idx] = NULL; - return -ENOMEM; } /** -- 2.51.1