Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

eth: intel: 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.

Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
Link: https://patch.msgid.link/20250816090659.117699-2-rongqianfeng@vivo.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Qianfeng Rong and committed by
Jakub Kicinski
4490d075 ab4ee77e

+13 -13
+1 -1
drivers/net/ethernet/intel/fm10k/fm10k_ethtool.c
··· 560 560 561 561 /* allocate temporary buffer to store rings in */ 562 562 i = max_t(int, interface->num_tx_queues, interface->num_rx_queues); 563 - temp_ring = vmalloc(array_size(i, sizeof(struct fm10k_ring))); 563 + temp_ring = vmalloc_array(i, sizeof(struct fm10k_ring)); 564 564 565 565 if (!temp_ring) { 566 566 err = -ENOMEM;
+4 -4
drivers/net/ethernet/intel/igb/igb_ethtool.c
··· 920 920 } 921 921 922 922 if (adapter->num_tx_queues > adapter->num_rx_queues) 923 - temp_ring = vmalloc(array_size(sizeof(struct igb_ring), 924 - adapter->num_tx_queues)); 923 + temp_ring = vmalloc_array(adapter->num_tx_queues, 924 + sizeof(struct igb_ring)); 925 925 else 926 - temp_ring = vmalloc(array_size(sizeof(struct igb_ring), 927 - adapter->num_rx_queues)); 926 + temp_ring = vmalloc_array(adapter->num_rx_queues, 927 + sizeof(struct igb_ring)); 928 928 929 929 if (!temp_ring) { 930 930 err = -ENOMEM;
+4 -4
drivers/net/ethernet/intel/igc/igc_ethtool.c
··· 627 627 } 628 628 629 629 if (adapter->num_tx_queues > adapter->num_rx_queues) 630 - temp_ring = vmalloc(array_size(sizeof(struct igc_ring), 631 - adapter->num_tx_queues)); 630 + temp_ring = vmalloc_array(adapter->num_tx_queues, 631 + sizeof(struct igc_ring)); 632 632 else 633 - temp_ring = vmalloc(array_size(sizeof(struct igc_ring), 634 - adapter->num_rx_queues)); 633 + temp_ring = vmalloc_array(adapter->num_rx_queues, 634 + sizeof(struct igc_ring)); 635 635 636 636 if (!temp_ring) { 637 637 err = -ENOMEM;
+1 -1
drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
··· 1278 1278 /* allocate temporary buffer to store rings in */ 1279 1279 i = max_t(int, adapter->num_tx_queues + adapter->num_xdp_queues, 1280 1280 adapter->num_rx_queues); 1281 - temp_ring = vmalloc(array_size(i, sizeof(struct ixgbe_ring))); 1281 + temp_ring = vmalloc_array(i, sizeof(struct ixgbe_ring)); 1282 1282 1283 1283 if (!temp_ring) { 1284 1284 err = -ENOMEM;
+3 -3
drivers/net/ethernet/intel/ixgbevf/ethtool.c
··· 276 276 } 277 277 278 278 if (new_tx_count != adapter->tx_ring_count) { 279 - tx_ring = vmalloc(array_size(sizeof(*tx_ring), 280 - adapter->num_tx_queues + 281 - adapter->num_xdp_queues)); 279 + tx_ring = vmalloc_array(adapter->num_tx_queues + 280 + adapter->num_xdp_queues, 281 + sizeof(*tx_ring)); 282 282 if (!tx_ring) { 283 283 err = -ENOMEM; 284 284 goto clear_reset;