From: Tony Nguyen <anthony.l.nguyen@intel.com>
To: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com,
edumazet@google.com, andrew+netdev@lunn.ch,
netdev@vger.kernel.org
Cc: Przemek Kitszel <przemyslaw.kitszel@intel.com>,
anthony.l.nguyen@intel.com, mschmidt@redhat.com,
poros@redhat.com, aleksandr.loktionov@intel.com,
horms@kernel.org
Subject: [PATCH net v4 2/5] ice: extract ice_vsi_new_stat_arrays()
Date: Mon, 21 Sep 2026 11:21:01 -0700 [thread overview]
Message-ID: <20260921182106.1015019-3-anthony.l.nguyen@intel.com> (raw)
In-Reply-To: <20260921182106.1015019-1-anthony.l.nguyen@intel.com>
From: Przemek Kitszel <przemyslaw.kitszel@intel.com>
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 <przemyslaw.kitszel@intel.com>
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
---
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 cc66ae6f2edb..456b524c0c5f 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.47.1
next prev parent reply other threads:[~2026-09-21 18:21 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-21 18:20 [PATCH net v4 0/5][pull request] ice: fix stats array overflow via proper realloc Tony Nguyen
2026-09-21 18:21 ` [PATCH net v4 1/5] ice: extract __ice_vsi_free_stats() Tony Nguyen
2026-09-24 12:23 ` netdev-bot+sashiko
2026-09-21 18:21 ` Tony Nguyen [this message]
2026-09-21 18:21 ` [PATCH net v4 3/5] ice: extract ice_vsi_get_num_qs() Tony Nguyen
2026-09-21 18:21 ` [PATCH net v4 4/5] ice: rebuild ring stats arrays instead of reallocating them in place Tony Nguyen
2026-09-24 12:23 ` netdev-bot+sashiko
2026-09-21 18:21 ` [PATCH net v4 5/5] ice: fix stats array overflow when VF requests more queues Tony Nguyen
2026-09-24 12:23 ` netdev-bot+sashiko
2026-09-25 7:12 ` Przemek Kitszel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260921182106.1015019-3-anthony.l.nguyen@intel.com \
--to=anthony.l.nguyen@intel.com \
--cc=aleksandr.loktionov@intel.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=mschmidt@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=poros@redhat.com \
--cc=przemyslaw.kitszel@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox