mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-05-05 19:24:01 -04:00
Merge branch 'net-use-vmalloc_array-to-simplify-code'
Qianfeng Rong says: ==================== net: use vmalloc_array() to simplify code Remove array_size() calls and replace vmalloc() with vmalloc_array() to simplify the code and maintain consistency with existing kmalloc_array() usage. vmalloc_array() is also optimized better, resulting in less instructions being used [1]. [1]: https://lore.kernel.org/lkml/abc66ec5-85a4-47e1-9759-2f60ab111971@vivo.com/ ==================== Link: https://patch.msgid.link/20250816090659.117699-1-rongqianfeng@vivo.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
@@ -560,7 +560,7 @@ static int fm10k_set_ringparam(struct net_device *netdev,
|
||||
|
||||
/* allocate temporary buffer to store rings in */
|
||||
i = max_t(int, interface->num_tx_queues, interface->num_rx_queues);
|
||||
temp_ring = vmalloc(array_size(i, sizeof(struct fm10k_ring)));
|
||||
temp_ring = vmalloc_array(i, sizeof(struct fm10k_ring));
|
||||
|
||||
if (!temp_ring) {
|
||||
err = -ENOMEM;
|
||||
|
||||
@@ -920,11 +920,11 @@ static int igb_set_ringparam(struct net_device *netdev,
|
||||
}
|
||||
|
||||
if (adapter->num_tx_queues > adapter->num_rx_queues)
|
||||
temp_ring = vmalloc(array_size(sizeof(struct igb_ring),
|
||||
adapter->num_tx_queues));
|
||||
temp_ring = vmalloc_array(adapter->num_tx_queues,
|
||||
sizeof(struct igb_ring));
|
||||
else
|
||||
temp_ring = vmalloc(array_size(sizeof(struct igb_ring),
|
||||
adapter->num_rx_queues));
|
||||
temp_ring = vmalloc_array(adapter->num_rx_queues,
|
||||
sizeof(struct igb_ring));
|
||||
|
||||
if (!temp_ring) {
|
||||
err = -ENOMEM;
|
||||
|
||||
@@ -627,11 +627,11 @@ igc_ethtool_set_ringparam(struct net_device *netdev,
|
||||
}
|
||||
|
||||
if (adapter->num_tx_queues > adapter->num_rx_queues)
|
||||
temp_ring = vmalloc(array_size(sizeof(struct igc_ring),
|
||||
adapter->num_tx_queues));
|
||||
temp_ring = vmalloc_array(adapter->num_tx_queues,
|
||||
sizeof(struct igc_ring));
|
||||
else
|
||||
temp_ring = vmalloc(array_size(sizeof(struct igc_ring),
|
||||
adapter->num_rx_queues));
|
||||
temp_ring = vmalloc_array(adapter->num_rx_queues,
|
||||
sizeof(struct igc_ring));
|
||||
|
||||
if (!temp_ring) {
|
||||
err = -ENOMEM;
|
||||
|
||||
@@ -1278,7 +1278,7 @@ static int ixgbe_set_ringparam(struct net_device *netdev,
|
||||
/* allocate temporary buffer to store rings in */
|
||||
i = max_t(int, adapter->num_tx_queues + adapter->num_xdp_queues,
|
||||
adapter->num_rx_queues);
|
||||
temp_ring = vmalloc(array_size(i, sizeof(struct ixgbe_ring)));
|
||||
temp_ring = vmalloc_array(i, sizeof(struct ixgbe_ring));
|
||||
|
||||
if (!temp_ring) {
|
||||
err = -ENOMEM;
|
||||
|
||||
@@ -276,9 +276,9 @@ static int ixgbevf_set_ringparam(struct net_device *netdev,
|
||||
}
|
||||
|
||||
if (new_tx_count != adapter->tx_ring_count) {
|
||||
tx_ring = vmalloc(array_size(sizeof(*tx_ring),
|
||||
adapter->num_tx_queues +
|
||||
adapter->num_xdp_queues));
|
||||
tx_ring = vmalloc_array(adapter->num_tx_queues +
|
||||
adapter->num_xdp_queues,
|
||||
sizeof(*tx_ring));
|
||||
if (!tx_ring) {
|
||||
err = -ENOMEM;
|
||||
goto clear_reset;
|
||||
|
||||
@@ -564,8 +564,8 @@ int nfp_flower_metadata_init(struct nfp_app *app, u64 host_ctx_count,
|
||||
|
||||
/* Init ring buffer and unallocated stats_ids. */
|
||||
priv->stats_ids.free_list.buf =
|
||||
vmalloc(array_size(NFP_FL_STATS_ELEM_RS,
|
||||
priv->stats_ring_size));
|
||||
vmalloc_array(priv->stats_ring_size,
|
||||
NFP_FL_STATS_ELEM_RS);
|
||||
if (!priv->stats_ids.free_list.buf)
|
||||
goto err_free_last_used;
|
||||
|
||||
|
||||
@@ -406,7 +406,7 @@ static void *bsd_alloc (unsigned char *options, int opt_len, int decomp)
|
||||
* Allocate space for the dictionary. This may be more than one page in
|
||||
* length.
|
||||
*/
|
||||
db->dict = vmalloc(array_size(hsize, sizeof(struct bsd_dict)));
|
||||
db->dict = vmalloc_array(hsize, sizeof(struct bsd_dict));
|
||||
if (!db->dict)
|
||||
{
|
||||
bsd_free (db);
|
||||
@@ -425,7 +425,7 @@ static void *bsd_alloc (unsigned char *options, int opt_len, int decomp)
|
||||
*/
|
||||
else
|
||||
{
|
||||
db->lens = vmalloc(array_size(sizeof(db->lens[0]), (maxmaxcode + 1)));
|
||||
db->lens = vmalloc_array(maxmaxcode + 1, sizeof(db->lens[0]));
|
||||
if (!db->lens)
|
||||
{
|
||||
bsd_free (db);
|
||||
|
||||
Reference in New Issue
Block a user