[PATCH v9 24/26] net/ice: avoid rte malloc in MAC address operations

Anatoly Burakov
2026-02-24T15:17:38Z

Currently, when adding or deleting MAC addresses, we are using
rte_zmalloc followed by an immediate rte_free. This memory does not need
to be stored in hugepage memory, so replace it with stack allocation.

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
---
drivers/net/intel/ice/ice_dcf_ethdev.c | 22 ++++++++--------------
1 file changed, 8 insertions(+), 14 deletions(-)

diff --git a/drivers/net/intel/ice/ice_dcf_ethdev.c b/drivers/net/intel/ice/ice_dcf_ethdev.c
index 388495d69c..0d3599d7d0 100644
--- a/drivers/net/intel/ice/ice_dcf_ethdev.c
+++ b/drivers/net/intel/ice/ice_dcf_ethdev.c
@@ -926,19 +926,14 @@ dcf_add_del_mc_addr_list(struct ice_dcf_hw *hw,
struct rte_ether_addr *mc_addrs,
uint32_t mc_addrs_num, bool add)
{
- struct virtchnl_ether_addr_list *list;
- struct dcf_virtchnl_cmd args;
+ struct {
+ struct virtchnl_ether_addr_list list;
+ struct virtchnl_ether_addr addr[DCF_NUM_MACADDR_MAX];
+ } list_req = {0};
+ struct virtchnl_ether_addr_list *list = &list_req.list;
+ struct dcf_virtchnl_cmd args = {0};
uint32_t i;
- int len, err = 0;
-
- len = sizeof(struct virtchnl_ether_addr_list);
- len += sizeof(struct virtchnl_ether_addr) * mc_addrs_num;
-
- list = rte_zmalloc(NULL, len, 0);
- if (!list) {
- PMD_DRV_LOG(ERR, "fail to allocate memory");
- return -ENOMEM;
- }
+ int err = 0;

for (i = 0; i < mc_addrs_num; i++) {
memcpy(list->list[i].addr, mc_addrs[i].addr_bytes,
@@ -953,13 +948,12 @@ dcf_add_del_mc_addr_list(struct ice_dcf_hw *hw,
args.v_op = add ? VIRTCHNL_OP_ADD_ETH_ADDR :
VIRTCHNL_OP_DEL_ETH_ADDR;
args.req_msg = (uint8_t *)list;
- args.req_msglen = len;
+ args.req_msglen = sizeof(list_req);
err = ice_dcf_execute_virtchnl_cmd(hw, &args);
if (err)
PMD_DRV_LOG(ERR, "fail to execute command %s",
add ? "OP_ADD_ETHER_ADDRESS" :
"OP_DEL_ETHER_ADDRESS");
- rte_free(list);
return err;
}

--
2.47.3