Rather than using malloc and free for adminq response buffers, and for the DDP profile list buffer in testpmd commands, define them on the stack, using RTE_DEFINE_FLEX_BYTES for those structures ending in a variable-length array. This removes the allocation failure and cleanup paths.
Signed-off-by: Bruce Richardson <[email protected]> --- drivers/net/intel/i40e/i40e_ethdev.c | 27 +++++---------------------- drivers/net/intel/i40e/i40e_testpmd.c | 10 ++-------- 2 files changed, 7 insertions(+), 30 deletions(-) diff --git a/drivers/net/intel/i40e/i40e_ethdev.c b/drivers/net/intel/i40e/i40e_ethdev.c index 498c5c7ec4..dde1867345 100644 --- a/drivers/net/intel/i40e/i40e_ethdev.c +++ b/drivers/net/intel/i40e/i40e_ethdev.c @@ -4549,18 +4549,13 @@ i40e_free_virt_mem_d(__rte_unused struct i40e_hw *hw, static int i40e_get_cap(struct i40e_hw *hw) { - struct i40e_aqc_list_capabilities_element_resp *buf; + struct i40e_aqc_list_capabilities_element_resp buf[I40E_MAX_CAP_ELE_NUM] = {0}; uint16_t len, size = 0; int ret; /* Calculate a huge enough buff for saving response data temporarily */ len = sizeof(struct i40e_aqc_list_capabilities_element_resp) * I40E_MAX_CAP_ELE_NUM; - buf = rte_zmalloc("i40e", len, 0); - if (!buf) { - PMD_DRV_LOG(ERR, "Failed to allocate memory"); - return I40E_ERR_NO_MEMORY; - } /* Get, parse the capabilities and save it to hw */ ret = i40e_aq_discover_capabilities(hw, buf, len, &size, @@ -4568,9 +4563,6 @@ i40e_get_cap(struct i40e_hw *hw) if (ret != I40E_SUCCESS) PMD_DRV_LOG(ERR, "Failed to discover capabilities"); - /* Free the temporary buffer after being used */ - rte_free(buf); - return ret; } @@ -4775,29 +4767,23 @@ static int i40e_pf_get_switch_config(struct i40e_pf *pf) { struct i40e_hw *hw = I40E_PF_TO_HW(pf); - struct i40e_aqc_get_switch_config_resp *switch_config; + RTE_DEFINE_FLEX_BYTES(struct i40e_aqc_get_switch_config_resp, switch_config, + I40E_AQ_LARGE_BUF); struct i40e_aqc_switch_config_element_resp *element; uint16_t start_seid = 0, num_reported; int ret; - switch_config = (struct i40e_aqc_get_switch_config_resp *)\ - rte_zmalloc("i40e", I40E_AQ_LARGE_BUF, 0); - if (!switch_config) { - PMD_DRV_LOG(ERR, "Failed to allocated memory"); - return -ENOMEM; - } - /* Get the switch configurations */ ret = i40e_aq_get_switch_config(hw, switch_config, I40E_AQ_LARGE_BUF, &start_seid, NULL); if (ret != I40E_SUCCESS) { PMD_DRV_LOG(ERR, "Failed to get switch configurations"); - goto fail; + return ret; } num_reported = rte_le_to_cpu_16(switch_config->header.num_reported); if (num_reported != 1) { /* The number should be 1 */ PMD_DRV_LOG(ERR, "Wrong number of switch config reported"); - goto fail; + return ret; } /* Parse the switch configuration elements */ @@ -4808,9 +4794,6 @@ i40e_pf_get_switch_config(struct i40e_pf *pf) } else PMD_DRV_LOG(INFO, "Unknown element type"); -fail: - rte_free(switch_config); - return ret; } diff --git a/drivers/net/intel/i40e/i40e_testpmd.c b/drivers/net/intel/i40e/i40e_testpmd.c index 21f596297b..30ae57336e 100644 --- a/drivers/net/intel/i40e/i40e_testpmd.c +++ b/drivers/net/intel/i40e/i40e_testpmd.c @@ -1616,7 +1616,8 @@ cmd_ddp_get_list_parsed(__rte_unused void *parsed_result, __rte_unused void *data) { struct cmd_ddp_get_list_result *res = parsed_result; - struct rte_pmd_i40e_profile_list *p_list; + RTE_DEFINE_FLEX_BYTES(struct rte_pmd_i40e_profile_list, p_list, + PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4); struct rte_pmd_i40e_profile_info *p_info; uint32_t p_num; uint32_t size; @@ -1624,11 +1625,6 @@ cmd_ddp_get_list_parsed(__rte_unused void *parsed_result, int ret = -ENOTSUP; size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4; - p_list = (struct rte_pmd_i40e_profile_list *)malloc(size); - if (!p_list) { - fprintf(stderr, "%s: Failed to malloc buffer\n", __func__); - return; - } if (ret == -ENOTSUP) ret = rte_pmd_i40e_get_ddp_list(res->port_id, @@ -1651,8 +1647,6 @@ cmd_ddp_get_list_parsed(__rte_unused void *parsed_result, } } - free(p_list); - if (ret < 0) fprintf(stderr, "Failed to get ddp list\n"); } -- 2.55.0

