[PATCH v3 11/27] net/i40e: avoid rte malloc in MAC/VLAN filtering
Bruce Richardson
bruce.richardson at intel.com
Mon Feb 16 18:08:45 CET 2026
On Wed, Feb 11, 2026 at 01:52:53PM +0000, Anatoly Burakov wrote:
> Currently, when adding, removing, or configuring MAC and VLAN filters,
> we are using rte_zmalloc followed by an immediate rte_free. This is not
> needed as this memory is not being stored anywhere, so replace it with
> regular malloc/free.
A minor nit on a number of these patches and the commit logs. I suggest
expanding on the "not being stored anywhere" part to instead say that the
memory is a temporary scratchpad and so does not need to be in DPDK
hugepage memory.
For the code though:
Acked-by: Bruce Richardson <bruce.richardson at intel.com>
>
> Signed-off-by: Anatoly Burakov <anatoly.burakov at intel.com>
> ---
> drivers/net/intel/i40e/i40e_ethdev.c | 38 +++++++++++++--------------
> drivers/net/intel/i40e/rte_pmd_i40e.c | 16 +++++------
> 2 files changed, 26 insertions(+), 28 deletions(-)
>
> diff --git a/drivers/net/intel/i40e/i40e_ethdev.c b/drivers/net/intel/i40e/i40e_ethdev.c
> index 654b0e5d16..806c29368c 100644
> --- a/drivers/net/intel/i40e/i40e_ethdev.c
> +++ b/drivers/net/intel/i40e/i40e_ethdev.c
> @@ -4165,8 +4165,7 @@ i40e_vlan_offload_set(struct rte_eth_dev *dev, int mask)
> if (mask & RTE_ETH_VLAN_EXTEND_MASK) {
> i = 0;
> num = vsi->mac_num;
> - mac_filter = rte_zmalloc("mac_filter_info_data",
> - num * sizeof(*mac_filter), 0);
> + mac_filter = calloc(num, sizeof(*mac_filter));
> if (mac_filter == NULL) {
> PMD_DRV_LOG(ERR, "failed to allocate memory");
> return I40E_ERR_NO_MEMORY;
> @@ -4206,7 +4205,7 @@ i40e_vlan_offload_set(struct rte_eth_dev *dev, int mask)
> if (ret)
> PMD_DRV_LOG(ERR, "i40e vsi add mac fail.");
> }
> - rte_free(mac_filter);
> + free(mac_filter);
> }
>
> if (mask & RTE_ETH_QINQ_STRIP_MASK) {
> @@ -6231,8 +6230,7 @@ i40e_vsi_config_vlan_filter(struct i40e_vsi *vsi, bool on)
>
> num = vsi->mac_num;
>
> - mac_filter = rte_zmalloc("mac_filter_info_data",
> - num * sizeof(*mac_filter), 0);
> + mac_filter = calloc(num, sizeof(*mac_filter));
> if (mac_filter == NULL) {
> PMD_DRV_LOG(ERR, "failed to allocate memory");
> return I40E_ERR_NO_MEMORY;
> @@ -6264,7 +6262,7 @@ i40e_vsi_config_vlan_filter(struct i40e_vsi *vsi, bool on)
> }
>
> DONE:
> - rte_free(mac_filter);
> + free(mac_filter);
> return ret;
> }
>
> @@ -7154,7 +7152,7 @@ i40e_add_macvlan_filters(struct i40e_vsi *vsi,
> ele_num = hw->aq.asq_buf_size / sizeof(*req_list);
> ele_buff_size = hw->aq.asq_buf_size;
>
> - req_list = rte_zmalloc("macvlan_add", ele_buff_size, 0);
> + req_list = calloc(1, ele_buff_size);
> if (req_list == NULL) {
> PMD_DRV_LOG(ERR, "Fail to allocate memory");
> return I40E_ERR_NO_MEMORY;
> @@ -7207,7 +7205,7 @@ i40e_add_macvlan_filters(struct i40e_vsi *vsi,
> } while (num < total);
>
> DONE:
> - rte_free(req_list);
> + free(req_list);
> return ret;
> }
>
> @@ -7230,7 +7228,7 @@ i40e_remove_macvlan_filters(struct i40e_vsi *vsi,
> ele_num = hw->aq.asq_buf_size / sizeof(*req_list);
> ele_buff_size = hw->aq.asq_buf_size;
>
> - req_list = rte_zmalloc("macvlan_remove", ele_buff_size, 0);
> + req_list = calloc(1, ele_buff_size);
> if (req_list == NULL) {
> PMD_DRV_LOG(ERR, "Fail to allocate memory");
> return I40E_ERR_NO_MEMORY;
> @@ -7286,7 +7284,7 @@ i40e_remove_macvlan_filters(struct i40e_vsi *vsi,
> } while (num < total);
>
> DONE:
> - rte_free(req_list);
> + free(req_list);
> return ret;
> }
>
> @@ -7455,7 +7453,7 @@ i40e_vsi_remove_all_macvlan_filter(struct i40e_vsi *vsi)
> else
> num = vsi->mac_num * vsi->vlan_num;
>
> - mv_f = rte_zmalloc("macvlan_data", num * sizeof(*mv_f), 0);
> + mv_f = calloc(num, sizeof(*mv_f));
> if (mv_f == NULL) {
> PMD_DRV_LOG(ERR, "failed to allocate memory");
> return I40E_ERR_NO_MEMORY;
> @@ -7484,7 +7482,7 @@ i40e_vsi_remove_all_macvlan_filter(struct i40e_vsi *vsi)
>
> ret = i40e_remove_macvlan_filters(vsi, mv_f, num);
> DONE:
> - rte_free(mv_f);
> + free(mv_f);
>
> return ret;
> }
> @@ -7510,7 +7508,7 @@ i40e_vsi_add_vlan(struct i40e_vsi *vsi, uint16_t vlan)
> return I40E_ERR_PARAM;
> }
>
> - mv_f = rte_zmalloc("macvlan_data", mac_num * sizeof(*mv_f), 0);
> + mv_f = calloc(mac_num, sizeof(*mv_f));
>
> if (mv_f == NULL) {
> PMD_DRV_LOG(ERR, "failed to allocate memory");
> @@ -7532,7 +7530,7 @@ i40e_vsi_add_vlan(struct i40e_vsi *vsi, uint16_t vlan)
> vsi->vlan_num++;
> ret = I40E_SUCCESS;
> DONE:
> - rte_free(mv_f);
> + free(mv_f);
> return ret;
> }
>
> @@ -7561,7 +7559,7 @@ i40e_vsi_delete_vlan(struct i40e_vsi *vsi, uint16_t vlan)
> return I40E_ERR_PARAM;
> }
>
> - mv_f = rte_zmalloc("macvlan_data", mac_num * sizeof(*mv_f), 0);
> + mv_f = calloc(mac_num, sizeof(*mv_f));
>
> if (mv_f == NULL) {
> PMD_DRV_LOG(ERR, "failed to allocate memory");
> @@ -7594,7 +7592,7 @@ i40e_vsi_delete_vlan(struct i40e_vsi *vsi, uint16_t vlan)
> vsi->vlan_num--;
> ret = I40E_SUCCESS;
> DONE:
> - rte_free(mv_f);
> + free(mv_f);
> return ret;
> }
>
> @@ -7626,7 +7624,7 @@ i40e_vsi_add_mac(struct i40e_vsi *vsi, struct i40e_mac_filter_info *mac_filter)
> mac_filter->filter_type == I40E_MAC_HASH_MATCH)
> vlan_num = 1;
>
> - mv_f = rte_zmalloc("macvlan_data", vlan_num * sizeof(*mv_f), 0);
> + mv_f = calloc(vlan_num, sizeof(*mv_f));
> if (mv_f == NULL) {
> PMD_DRV_LOG(ERR, "failed to allocate memory");
> return I40E_ERR_NO_MEMORY;
> @@ -7665,7 +7663,7 @@ i40e_vsi_add_mac(struct i40e_vsi *vsi, struct i40e_mac_filter_info *mac_filter)
>
> ret = I40E_SUCCESS;
> DONE:
> - rte_free(mv_f);
> + free(mv_f);
>
> return ret;
> }
> @@ -7696,7 +7694,7 @@ i40e_vsi_delete_mac(struct i40e_vsi *vsi, struct rte_ether_addr *addr)
> filter_type == I40E_MAC_HASH_MATCH)
> vlan_num = 1;
>
> - mv_f = rte_zmalloc("macvlan_data", vlan_num * sizeof(*mv_f), 0);
> + mv_f = calloc(vlan_num, sizeof(*mv_f));
> if (mv_f == NULL) {
> PMD_DRV_LOG(ERR, "failed to allocate memory");
> return I40E_ERR_NO_MEMORY;
> @@ -7725,7 +7723,7 @@ i40e_vsi_delete_mac(struct i40e_vsi *vsi, struct rte_ether_addr *addr)
>
> ret = I40E_SUCCESS;
> DONE:
> - rte_free(mv_f);
> + free(mv_f);
> return ret;
> }
>
> diff --git a/drivers/net/intel/i40e/rte_pmd_i40e.c b/drivers/net/intel/i40e/rte_pmd_i40e.c
> index a358f68bc5..fb73fa924f 100644
> --- a/drivers/net/intel/i40e/rte_pmd_i40e.c
> +++ b/drivers/net/intel/i40e/rte_pmd_i40e.c
> @@ -233,7 +233,7 @@ i40e_vsi_rm_mac_filter(struct i40e_vsi *vsi)
> filter_type == I40E_MAC_HASH_MATCH)
> vlan_num = 1;
>
> - mv_f = rte_zmalloc("macvlan_data", vlan_num * sizeof(*mv_f), 0);
> + mv_f = calloc(vlan_num, sizeof(*mv_f));
> if (!mv_f) {
> PMD_DRV_LOG(ERR, "failed to allocate memory");
> return I40E_ERR_NO_MEMORY;
> @@ -250,18 +250,18 @@ i40e_vsi_rm_mac_filter(struct i40e_vsi *vsi)
> ret = i40e_find_all_vlan_for_mac(vsi, mv_f, vlan_num,
> &f->mac_info.mac_addr);
> if (ret != I40E_SUCCESS) {
> - rte_free(mv_f);
> + free(mv_f);
> return ret;
> }
> }
>
> ret = i40e_remove_macvlan_filters(vsi, mv_f, vlan_num);
> if (ret != I40E_SUCCESS) {
> - rte_free(mv_f);
> + free(mv_f);
> return ret;
> }
>
> - rte_free(mv_f);
> + free(mv_f);
> ret = I40E_SUCCESS;
> }
>
> @@ -294,7 +294,7 @@ i40e_vsi_restore_mac_filter(struct i40e_vsi *vsi)
> f->mac_info.filter_type == I40E_MAC_HASH_MATCH)
> vlan_num = 1;
>
> - mv_f = rte_zmalloc("macvlan_data", vlan_num * sizeof(*mv_f), 0);
> + mv_f = calloc(vlan_num, sizeof(*mv_f));
> if (!mv_f) {
> PMD_DRV_LOG(ERR, "failed to allocate memory");
> return I40E_ERR_NO_MEMORY;
> @@ -312,18 +312,18 @@ i40e_vsi_restore_mac_filter(struct i40e_vsi *vsi)
> ret = i40e_find_all_vlan_for_mac(vsi, mv_f, vlan_num,
> &f->mac_info.mac_addr);
> if (ret != I40E_SUCCESS) {
> - rte_free(mv_f);
> + free(mv_f);
> return ret;
> }
> }
>
> ret = i40e_add_macvlan_filters(vsi, mv_f, vlan_num);
> if (ret != I40E_SUCCESS) {
> - rte_free(mv_f);
> + free(mv_f);
> return ret;
> }
>
> - rte_free(mv_f);
> + free(mv_f);
> ret = I40E_SUCCESS;
> }
>
> --
> 2.47.3
>
More information about the dev
mailing list