eliminate unnecessary dynamic allocation
cover eliminate unnecessary dynamic allocation
To reduce the possibility of bugs due to missing memory freeing on error paths (or even the success path) in functions, we can switch memory use from dynamic heap memory to stack memory in functions where both allocation and free occur within the one function, and where the total memory size is not very large (~4K max).
To facilitate this, the first patch of the series defines a new macro to simplify the creation of stack objects which are of the format struct+extra buffer, where the extra buffer space is sized to hold N objects from a flex array member at the end of the primary structure. That macro is then used throughout the drivers to define most of the new stack variables used for e.g. admin queue messages.
Bruce Richardson (6):
eal: add macros for local variable-length structure buffers net/iavf: use stack storage for virtchnl messages net/ice: use stack storage for function-local buffers net/idpf: use stack storage for virtchnl messages net/cpfl: use stack storage for function-local buffers net/i40e: use stack storage for function-local buffers
app/test/test_common.c | 54 ++++ drivers/net/intel/cpfl/cpfl_fxp_rule.c | 20 +- drivers/net/intel/cpfl/cpfl_representor.c | 15 +- drivers/net/intel/cpfl/cpfl_vchnl.c | 41 ++- drivers/net/intel/i40e/i40e_ethdev.c | 27 +- drivers/net/intel/i40e/i40e_testpmd.c | 10 +- drivers/net/intel/iavf/iavf_ipsec_crypto.c | 270 +++++------------- drivers/net/intel/iavf/iavf_tm.c | 26 +- drivers/net/intel/ice/ice_dcf.c | 21 +- drivers/net/intel/ice/ice_dcf_parent.c | 12 +- drivers/net/intel/ice/ice_dcf_sched.c | 25 +- drivers/net/intel/ice/ice_diagnose.c | 12 +- drivers/net/intel/ice/ice_ethdev.c | 104 ++----- drivers/net/intel/ice/ice_rxtx.c | 26 +- drivers/net/intel/ice/ice_tm.c | 7 +- drivers/net/intel/idpf/idpf_common_device.c | 27 +- drivers/net/intel/idpf/idpf_common_virtchnl.c | 77 ++--- lib/eal/include/rte_common.h | 46 +++ 18 files changed, 306 insertions(+), 514 deletions(-)
--
2.55.0
PATCH 1/6 eal: add macros for local variable-length structure buffers
Many drivers allocate small control-path messages, which consist of a header structure followed by a variable-length array, using malloc and free, which adds error handling and the risk of leaks on error paths.
Add RTE_DEFINE_FLEX and RTE_DEFINE_FLEX_BYTES macros to define such buffers on the stack instead, (similar to equivalent macros in Linux kernel). The buffer is a union of a byte array and the structure type, giving correct alignment and type-safe access via a pointer, with the byte array first so that zero-initialization covers the whole buffer.
--- app/test/test_common.c | 54 ++++++++++++++++++++++++++++++++++++ lib/eal/include/rte_common.h | 46 ++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+)
app/test/test_common.c +54 -0
@@ -796,6 +796,59 @@ test_fls(void)return 0 ; } +struct flex_test_elem { +uint64_t a; +uint16_t b; +}; + +struct flex_test_hdr { +uint16_t num; +struct flex_test_elem elems[]; +}; + +struct flex_test_hdr_one { +uint8_t num; +struct { +uint8_t len; +struct flex_test_elem elems[1 ]; + } list; +}; + +static int +test_define_flex (void ) +{ + RTE_DEFINE_FLEX(struct flex_test_hdr, hdr, elems, 4); + RTE_DEFINE_FLEX(struct flex_test_hdr_one, hdr_one, list.elems, 3); + RTE_DEFINE_FLEX_BYTES(struct flex_test_hdr, hdr_bytes, 100); + +RTE_TEST_ASSERT (sizeof (hdr_u) >=sizeof (*hdr) +4 *sizeof (hdr->elems[0 ]), +"RTE_DEFINE_FLEX size, flexible array" ); +RTE_TEST_ASSERT (sizeof (hdr_one_u) >=sizeof (*hdr_one) +3 *sizeof (hdr_one->list.elems[0 ]), +"RTE_DEFINE_FLEX size, nested one-element array" ); +RTE_TEST_ASSERT (sizeof (hdr_bytes_u) >=100 ,"RTE_DEFINE_FLEX_BYTES size" ); + +RTE_TEST_ASSERT ((uintptr_t )hdr % alignof(struct flex_test_hdr ) ==0 , +"RTE_DEFINE_FLEX alignment" ); +RTE_TEST_ASSERT ((uintptr_t )hdr_one % alignof(struct flex_test_hdr_one ) ==0 , +"RTE_DEFINE_FLEX alignment, nested array" ); +RTE_TEST_ASSERT ((uintptr_t )hdr_bytes % alignof(struct flex_test_hdr ) ==0 , +"RTE_DEFINE_FLEX_BYTES alignment" ); + +for (size_t i =0 ; i <sizeof (hdr_u.raw); i++) +RTE_TEST_ASSERT (hdr_u.raw[i] ==0 ,"RTE_DEFINE_FLEX not zeroed" ); +for (size_t i =0 ; i <sizeof (hdr_one_u.raw); i++) +RTE_TEST_ASSERT (hdr_one_u.raw[i] ==0 ,"RTE_DEFINE_FLEX not zeroed, nested array" ); +for (size_t i =0 ; i <sizeof (hdr_bytes_u.raw); i++) +RTE_TEST_ASSERT (hdr_bytes_u.raw[i] ==0 ,"RTE_DEFINE_FLEX_BYTES not zeroed" ); + + hdr->num =4 ; +for (uint16_t i =0 ; i < hdr->num; i++) + hdr->elems[i].b = i; +RTE_TEST_ASSERT_EQUAL (hdr->elems[3 ].b,3 ,"RTE_DEFINE_FLEX element access" ); + +return 0 ; +} +static struct unit_test_suite common_test_suite = { .suite_name ="common autotest" , .setup =NULL ,
@@ -805,6 +858,7 @@ static struct unit_test_suite common_test_suite = {TEST_CASE (test_ptr_align_edge_cases),TEST_CASE (test_align),TEST_CASE (test_macros), +TEST_CASE (test_define_flex),TEST_CASE (test_misc),TEST_CASE (test_bsf), TEST_CASE(test_log2),
lib/eal/include/rte_common.h +46 -0
52 lines not on this page · raw message
Signature · 1 line
2.55.0
PATCH 2/6 net/iavf: use stack storage for virtchnl messages
In reply to Bruce RichardsonRather than using malloc and free for the request and response buffers of IPsec and traffic management virtchnl messages, define them on the stack using RTE_DEFINE_FLEX. This removes the allocation failure and cleanup paths, avoiding potential leaks on error.
For the traffic management messages, add checks that the number of TCs and queue pairs do not exceed the maximum sizes of the buffers.
--- drivers/net/intel/iavf/iavf_ipsec_crypto.c | 270 ++++++--------------- drivers/net/intel/iavf/iavf_tm.c | 26 +- 2 files changed, 79 insertions(+), 217 deletions(-)
drivers/net/intel/iavf/iavf_ipsec_crypto.c +69 -201
@@ -460,28 +460,14 @@ static uint32_t iavf_ipsec_crypto_security_association_add(struct iavf_adapter *adapter, struct rte_security_session_conf *conf) { - struct inline_ipsec_msg *request = NULL, *response = NULL; -struct virtchnl_ipsec_sa_cfg *sa_cfg; -size_t request_len, response_len; - -int rc; - - request_len =sizeof (struct inline_ipsec_msg ) + + RTE_DEFINE_FLEX(struct inline_ipsec_msg, request, ipsec_data.sa_cfg, 1); + RTE_DEFINE_FLEX(struct inline_ipsec_msg, response, ipsec_data.sa_cfg_resp, 1); +const size_t request_len =sizeof (struct inline_ipsec_msg ) +sizeof (struct virtchnl_ipsec_sa_cfg ); - - request =calloc (1 , request_len); -if (request ==NULL ) { - rc = -ENOMEM ; - goto update_cleanup; - } - - response_len =sizeof (struct inline_ipsec_msg ) + +const size_t response_len =sizeof (struct inline_ipsec_msg ) +sizeof (struct virtchnl_ipsec_sa_cfg_resp ); - response =calloc (1 , response_len); -if (response ==NULL ) { - rc = -ENOMEM ; - goto update_cleanup; - } +struct virtchnl_ipsec_sa_cfg *sa_cfg; +int rc;/* set msg header params */ request->ipsec_opcode =INLINE_IPSEC_OP_SA_CREATE ;
@@ -546,19 +532,14 @@ iavf_ipsec_crypto_security_association_add(struct iavf_adapter *adapter, (uint8_t *)request, request_len, (uint8_t *)response, response_len);if (rc) - goto update_cleanup; +return rc;/* verify response id */ if (response->ipsec_opcode != request->ipsec_opcode || response->req_id != request->req_id) - rc = -EFAULT ; -else - rc = response->ipsec_data.sa_cfg_resp->sa_handle; -update_cleanup: -free (response); -free (request); +return -EFAULT ; -return rc; +return response->ipsec_data.sa_cfg_resp->sa_handle; } static void
@@ -722,17 +703,13 @@ iavf_ipsec_crypto_inbound_security_policy_add(struct iavf_adapter *adapter,bool is_udp, uint16_t udp_port) { -struct inline_ipsec_msg *request =NULL , *response =NULL ; -size_t request_len, response_len; -int rc =0 ; - - request_len =sizeof (struct inline_ipsec_msg ) + + RTE_DEFINE_FLEX(struct inline_ipsec_msg, request, ipsec_data.sp_cfg, 1); + RTE_DEFINE_FLEX(struct inline_ipsec_msg, response, ipsec_data.sp_cfg_resp, 1); +const size_t request_len =sizeof (struct inline_ipsec_msg ) +sizeof (struct virtchnl_ipsec_sp_cfg ); - request =calloc (1 , request_len); -if (request ==NULL ) { - rc = -ENOMEM ; - goto update_cleanup; - } +const size_t response_len =sizeof (struct inline_ipsec_msg ) + +sizeof (struct virtchnl_ipsec_sp_cfg_resp ); +int rc =0 ;/* set msg header params */ request->ipsec_opcode =INLINE_IPSEC_OP_SP_CREATE ;
@@ -767,58 +744,32 @@ iavf_ipsec_crypto_inbound_security_policy_add(struct iavf_adapter *adapter, request->ipsec_data.sp_cfg->is_udp = is_udp; request->ipsec_data.sp_cfg->udp_port =htons (udp_port); - response_len =sizeof (struct inline_ipsec_msg ) + -sizeof (struct virtchnl_ipsec_sp_cfg_resp ); - response =calloc (1 , response_len); -if (response ==NULL ) { - rc = -ENOMEM ; - goto update_cleanup; - } -/* send virtual channel request to add SA to hardware database */ rc =iavf_ipsec_crypto_request (adapter, (uint8_t *)request, request_len, (uint8_t *)response, response_len);if (rc) - goto update_cleanup; +return rc;/* verify response */ if (response->ipsec_opcode != request->ipsec_opcode || response->req_id != request->req_id) - rc = -EFAULT ; -else - rc = response->ipsec_data.sp_cfg_resp->rule_id; - -update_cleanup: -free (request); -free (response); +return -EFAULT ; -return rc; +return response->ipsec_data.sp_cfg_resp->rule_id; }static uint32_t iavf_ipsec_crypto_sa_update_esn (struct iavf_adapter *adapter,struct iavf_security_session *sess) { -struct inline_ipsec_msg *request =NULL , *response =NULL ; -size_t request_len, response_len; -int rc =0 ; - - request_len =sizeof (struct inline_ipsec_msg ) + + RTE_DEFINE_FLEX(struct inline_ipsec_msg, request, ipsec_data.sa_update, 1); + RTE_DEFINE_FLEX(struct inline_ipsec_msg, response, ipsec_data.ipsec_resp, 1); +const size_t request_len =sizeof (struct inline_ipsec_msg ) +sizeof (struct virtchnl_ipsec_sa_update ); - request =calloc (1 , request_len); -if (request ==NULL ) { - rc = -ENOMEM ; - goto update_cleanup; - } - - response_len =sizeof (struct inline_ipsec_msg ) + +const size_t response_len =sizeof (struct inline_ipsec_msg ) +sizeof (struct virtchnl_ipsec_resp ); - response =calloc (1 , response_len); -if (response ==NULL ) { - rc = -ENOMEM ; - goto update_cleanup; - } +int rc =0 ;/* set msg header params */ request->ipsec_opcode =INLINE_IPSEC_OP_SA_UPDATE ;
@@ -834,20 +785,14 @@ iavf_ipsec_crypto_sa_update_esn(struct iavf_adapter *adapter, (uint8_t *)request, request_len, (uint8_t *)response, response_len);if (rc) - goto update_cleanup; +return rc;/* verify response */ if (response->ipsec_opcode != request->ipsec_opcode || response->req_id != request->req_id) - rc = -EFAULT ; -else - rc = response->ipsec_data.ipsec_resp->resp; - -update_cleanup: -free (request); -free (response); +return -EFAULT ; -return rc; +return response->ipsec_data.ipsec_resp->resp; } static int
@@ -897,25 +842,13 @@ int iavf_ipsec_crypto_security_policy_delete(struct iavf_adapter *adapter, uint8_t is_v4, uint32_t flow_id) { - struct inline_ipsec_msg *request = NULL, *response = NULL; -size_t request_len, response_len; -int rc =0 ; - - request_len =sizeof (struct inline_ipsec_msg ) + + RTE_DEFINE_FLEX(struct inline_ipsec_msg, request, ipsec_data.sp_destroy, 1); + RTE_DEFINE_FLEX(struct inline_ipsec_msg, response, ipsec_data.ipsec_resp, 1); +const size_t request_len =sizeof (struct inline_ipsec_msg ) +sizeof (struct virtchnl_ipsec_sp_destroy ); - request =calloc (1 , request_len); -if (request ==NULL ) { - rc = -ENOMEM ; - goto update_cleanup; - } - - response_len =sizeof (struct inline_ipsec_msg ) + +const size_t response_len =sizeof (struct inline_ipsec_msg ) +sizeof (struct virtchnl_ipsec_resp ); - response =calloc (1 , response_len); -if (response ==NULL ) { - rc = -ENOMEM ; - goto update_cleanup; - } +int rc =0 ;/* set msg header params */ request->ipsec_opcode =INLINE_IPSEC_OP_SP_DESTROY ;
@@ -932,48 +865,27 @@ iavf_ipsec_crypto_security_policy_delete(struct iavf_adapter *adapter, (uint8_t *)request, request_len, (uint8_t *)response, response_len);if (rc) - goto update_cleanup; +return rc;/* verify response */ if (response->ipsec_opcode != request->ipsec_opcode || response->req_id != request->req_id) - rc = -EFAULT ; -else - rc = response->ipsec_data.ipsec_status->status; - -update_cleanup: -free (request); -free (response); +return -EFAULT ; -return rc; +return response->ipsec_data.ipsec_status->status; }static uint32_t iavf_ipsec_crypto_sa_del (struct iavf_adapter *adapter,struct iavf_security_session *sess) { -struct inline_ipsec_msg *request =NULL , *response =NULL ; -size_t request_len, response_len; - -int rc =0 ; - - request_len =sizeof (struct inline_ipsec_msg ) + + RTE_DEFINE_FLEX(struct inline_ipsec_msg, request, ipsec_data.sa_destroy, 1); + RTE_DEFINE_FLEX(struct inline_ipsec_msg, response, ipsec_data.ipsec_resp, 1); +const size_t request_len =sizeof (struct inline_ipsec_msg ) +sizeof (struct virtchnl_ipsec_sa_destroy ); - - request =calloc (1 , request_len); -if (request ==NULL ) { - rc = -ENOMEM ; - goto update_cleanup; - } - - response_len =sizeof (struct inline_ipsec_msg ) + +const size_t response_len =sizeof (struct inline_ipsec_msg ) +sizeof (struct virtchnl_ipsec_resp ); - - response =calloc (1 , response_len); -if (response ==NULL ) { - rc = -ENOMEM ; - goto update_cleanup; - } +int rc =0 ;/* set msg header params */ request->ipsec_opcode =INLINE_IPSEC_OP_SA_DESTROY ;
@@ -995,12 +907,12 @@ iavf_ipsec_crypto_sa_del(struct iavf_adapter *adapter, (uint8_t *)request, request_len, (uint8_t *)response, response_len);if (rc) - goto update_cleanup; +return rc;/* verify response */ if (response->ipsec_opcode != request->ipsec_opcode || response->req_id != request->req_id) - rc = -EFAULT ; +return -EFAULT ;/** * Delete status will be the same bitmask as sa_destroy request flag if
@@ -1008,13 +920,9 @@ iavf_ipsec_crypto_sa_del(struct iavf_adapter *adapter,*/ if (request->ipsec_data.sa_destroy->flag != response->ipsec_data.ipsec_status->status) - rc = -EFAULT ; - -update_cleanup: -free (response); -free (request); +return -EFAULT ; -return rc; +return 0 ; } static int
@@ -1160,50 +1068,30 @@ iavf_ipsec_crypto_device_capabilities_get(struct iavf_adapter *adapter, struct virtchnl_ipsec_cap *capability) {/* Perform pf-vf comms */ -struct inline_ipsec_msg *request =NULL , *response =NULL ; -size_t request_len, response_len; -int rc; - - request_len =sizeof (struct inline_ipsec_msg ); - - request =calloc (1 , request_len); -if (request ==NULL ) { - rc = -ENOMEM ; - goto update_cleanup; - } - - response_len =sizeof (struct inline_ipsec_msg ) + +struct inline_ipsec_msg request = {0 }; + RTE_DEFINE_FLEX(struct inline_ipsec_msg, response, ipsec_data.ipsec_cap, 1); +const size_t response_len =sizeof (struct inline_ipsec_msg ) +sizeof (struct virtchnl_ipsec_cap ); - response =calloc (1 , response_len); -if (response ==NULL ) { - rc = -ENOMEM ; - goto update_cleanup; - } +int rc;/* set msg header params */ - request->ipsec_opcode =INLINE_IPSEC_OP_GET_CAP ; - request->req_id = (uint16_t )0xDEADBEEF ; + request.ipsec_opcode =INLINE_IPSEC_OP_GET_CAP ; + request.req_id = (uint16_t )0xDEADBEEF ;/* send virtual channel request to add SA to hardware database */ rc =iavf_ipsec_crypto_request (adapter, - (uint8_t *)request, request_len, + (uint8_t *)&request,sizeof (request), (uint8_t *)response, response_len);if (rc) - goto update_cleanup; +return rc;/* verify response id */ -if (response->ipsec_opcode != request->ipsec_opcode || - response->req_id != request->req_id){ - rc = -EFAULT ; - goto update_cleanup; - } -memcpy (capability, response->ipsec_data.ipsec_cap,sizeof (*capability)); - -update_cleanup: -free (response); -free (request); +if (response->ipsec_opcode != request.ipsec_opcode || + response->req_id != request.req_id) +return -EFAULT ; -return rc; +memcpy (capability, response->ipsec_data.ipsec_cap,sizeof (*capability)); +return 0 ; }enum rte_crypto_auth_algorithm auth_maptbl[] = {
@@ -1588,50 +1476,30 @@ iavf_ipsec_crypto_status_get(struct iavf_adapter *adapter, struct virtchnl_ipsec_status *status) {/* Perform pf-vf comms */ -struct inline_ipsec_msg *request =NULL , *response =NULL ; -size_t request_len, response_len; -int rc; - - request_len =sizeof (struct inline_ipsec_msg ); - - request =calloc (1 , request_len); -if (request ==NULL ) { - rc = -ENOMEM ; - goto update_cleanup; - } - - response_len =sizeof (struct inline_ipsec_msg ) + +struct inline_ipsec_msg request = {0 }; + RTE_DEFINE_FLEX(struct inline_ipsec_msg, response, ipsec_data.ipsec_status, 1); +const size_t response_len =sizeof (struct inline_ipsec_msg ) +sizeof (struct virtchnl_ipsec_status ); - response =calloc (1 , response_len); -if (response ==NULL ) { - rc = -ENOMEM ; - goto update_cleanup; - } +int rc;/* set msg header params */ - request->ipsec_opcode =INLINE_IPSEC_OP_GET_STATUS ; - request->req_id = (uint16_t )0xDEADBEEF ; + request.ipsec_opcode =INLINE_IPSEC_OP_GET_STATUS ; + request.req_id = (uint16_t )0xDEADBEEF ;/* send virtual channel request to add SA to hardware database */ rc =iavf_ipsec_crypto_request (adapter, - (uint8_t *)request, request_len, + (uint8_t *)&request,sizeof (request), (uint8_t *)response, response_len);if (rc) - goto update_cleanup; +return rc;/* verify response id */ -if (response->ipsec_opcode != request->ipsec_opcode || - response->req_id != request->req_id){ - rc = -EFAULT ; - goto update_cleanup; - } -memcpy (status, response->ipsec_data.ipsec_status,sizeof (*status)); - -update_cleanup: -free (response); -free (request); +if (response->ipsec_opcode != request.ipsec_opcode || + response->req_id != request.req_id) +return -EFAULT ; -return rc; +memcpy (status, response->ipsec_data.ipsec_status,sizeof (*status)); +return 0 ; }
drivers/net/intel/iavf/iavf_tm.c +10 -16
@@ -833,8 +833,9 @@ static int iavf_hierarchy_commit(struct rte_eth_dev *dev,struct iavf_info *vf =IAVF_DEV_PRIVATE_TO_VF (dev->data->dev_private);struct iavf_adapter *adapter =IAVF_DEV_PRIVATE_TO_ADAPTER (dev->data->dev_private); -struct virtchnl_queue_tc_mapping *q_tc_mapping =NULL ; -struct virtchnl_queues_bw_cfg *q_bw =NULL ; + RTE_DEFINE_FLEX(struct virtchnl_queue_tc_mapping, q_tc_mapping, tc, + IAVF_MAX_TRAFFIC_CLASS - 1); + RTE_DEFINE_FLEX(struct virtchnl_queues_bw_cfg, q_bw, cfg, IAVF_MAX_NUM_QUEUES_LV - 1);struct iavf_tm_node_list *queue_list = &vf->tm_conf.queue_list;struct iavf_tm_node *tm_node;struct iavf_qtc_map *qtc_map =NULL ;
@@ -869,21 +870,18 @@ static int iavf_hierarchy_commit(struct rte_eth_dev *dev, goto fail_clear; } - size =sizeof (*q_tc_mapping) +sizeof (q_tc_mapping->tc[0 ]) * - (vf->qos_cap->num_elem -1 ); - q_tc_mapping =calloc (1 , size); -if (!q_tc_mapping) { - ret_val =IAVF_ERR_NO_MEMORY ; +if (vf->qos_cap->num_elem >IAVF_MAX_TRAFFIC_CLASS || + vf->num_queue_pairs >IAVF_MAX_NUM_QUEUES_LV ) { +PMD_DRV_LOG (ERR ,"Too many TCs (%u) or queues (%u) for TM configuration" , + vf->qos_cap->num_elem, vf->num_queue_pairs); + ret_val =IAVF_ERR_PARAM ; goto fail_clear; } + size =sizeof (*q_tc_mapping) +sizeof (q_tc_mapping->tc[0 ]) * + (vf->qos_cap->num_elem -1 ); size_q =sizeof (*q_bw) +sizeof (q_bw->cfg[0 ]) * (vf->num_queue_pairs -1 ); - q_bw =calloc (1 , size_q); -if (!q_bw) { - ret_val =IAVF_ERR_NO_MEMORY ; - goto fail_clear; - } q_tc_mapping->vsi_id = vf->vsi.vsi_id; q_tc_mapping->num_tc = vf->qos_cap->num_elem;
@@ -950,8 +948,6 @@ static int iavf_hierarchy_commit(struct rte_eth_dev *dev,free (old_qtc_map);if (adapter->stopped ==1 ) vf->tm_conf.committed = true; -free (q_bw); -free (q_tc_mapping);return ret_val; fail_clear:
@@ -961,8 +957,6 @@ static int iavf_hierarchy_commit(struct rte_eth_dev *dev,iavf_tm_conf_init (dev); } err: -free (q_bw); -free (q_tc_mapping);free (qtc_map);return ret_val; }
Signature · 1 line
2.55.0
PATCH 3/6 net/ice: use stack storage for function-local buffers
In reply to Bruce RichardsonRather than using malloc and free for small or medium-sized buffers used only within a single function, such as adminq and virtchnl messages, define them on the stack, using RTE_DEFINE_FLEX for those structures ending in a variable-length array. This removes the allocation failure and cleanup paths, avoiding potential leaks on error.
Where the number of elements used depends on runtime values, add checks that those values do not exceed the buffer sizes.
--- drivers/net/intel/ice/ice_dcf.c | 21 ++--- drivers/net/intel/ice/ice_dcf_parent.c | 12 +-- drivers/net/intel/ice/ice_dcf_sched.c | 25 ++---- drivers/net/intel/ice/ice_diagnose.c | 12 +-- drivers/net/intel/ice/ice_ethdev.c | 104 +++++++------------------ drivers/net/intel/ice/ice_rxtx.c | 26 +------ drivers/net/intel/ice/ice_tm.c | 7 +- 7 files changed, 52 insertions(+), 155 deletions(-)
drivers/net/intel/ice/ice_dcf.c +7 -14
@@ -1275,18 +1275,19 @@ ice_dcf_configure_queues(struct ice_dcf_hw *hw)int ice_dcf_config_irq_map (struct ice_dcf_hw *hw) { -struct virtchnl_irq_map_info *map_info; + RTE_DEFINE_FLEX(struct virtchnl_irq_map_info, map_info, vecmap, RTE_DIM(hw->rxq_map));struct virtchnl_vector_map *vecmap;struct dcf_virtchnl_cmd args;int len, i, err; +if (hw->nb_msix >RTE_DIM (hw->rxq_map)) { +PMD_DRV_LOG (ERR ,"Too many interrupt vectors: %u" , hw->nb_msix); +return -EINVAL ; + } + len =sizeof (struct virtchnl_irq_map_info ) +sizeof (struct virtchnl_vector_map ) * hw->nb_msix; - map_info =rte_zmalloc ("map_info" , len,0 ); -if (!map_info) -return -ENOMEM ; - map_info->num_vectors = hw->nb_msix;for (i =0 ; i < hw->nb_msix; i++) { vecmap = &map_info->vecmap[i];
@@ -1306,7 +1307,6 @@ ice_dcf_config_irq_map(struct ice_dcf_hw *hw)if (err)PMD_DRV_LOG (ERR ,"fail to execute command OP_CONFIG_IRQ_MAP" ); -rte_free (map_info);return err; }
@@ -1402,7 +1402,7 @@ ice_dcf_add_del_all_mac_addr(struct ice_dcf_hw *hw,struct rte_ether_addr *addr, bool add, uint8_t type) { - struct virtchnl_ether_addr_list *list; + RTE_DEFINE_FLEX(struct virtchnl_ether_addr_list, list, list, 1);struct dcf_virtchnl_cmd args;int len, err =0 ;
@@ -1417,12 +1417,6 @@ ice_dcf_add_del_all_mac_addr(struct ice_dcf_hw *hw, len =sizeof (struct virtchnl_ether_addr_list ); len +=sizeof (struct virtchnl_ether_addr ); - list =rte_zmalloc (NULL , len,0 ); -if (!list) { -PMD_DRV_LOG (ERR ,"fail to allocate memory" ); -return -ENOMEM ; - } -memcpy (list->list[0 ].addr, addr->addr_bytes,sizeof (addr->addr_bytes));
@@ -1442,6 +1436,5 @@ ice_dcf_add_del_all_mac_addr(struct ice_dcf_hw *hw,PMD_DRV_LOG (ERR ,"fail to execute command %s" , add ?"OP_ADD_ETHER_ADDRESS" :"OP_DEL_ETHER_ADDRESS" ); -rte_free (list);return err; }
drivers/net/intel/ice/ice_dcf_parent.c +2 -10
@@ -321,7 +321,7 @@ ice_dcf_query_port_ets(struct ice_hw *parent_hw, struct ice_dcf_hw *real_hw)static int ice_dcf_init_parent_hw (struct ice_hw *hw) { -struct ice_aqc_get_phy_caps_data *pcaps; +struct ice_aqc_get_phy_caps_data pcaps = {0 };int status; status =ice_aq_get_fw_ver (hw,NULL );
@@ -345,17 +345,9 @@ ice_dcf_init_parent_hw(struct ice_hw *hw)if (status) goto err_unroll_alloc; - pcaps = (struct ice_aqc_get_phy_caps_data *) -ice_malloc (hw,sizeof (*pcaps)); -if (!pcaps) { - status =ICE_ERR_NO_MEMORY ; - goto err_unroll_alloc; - } -/* Initialize port_info struct with PHY capabilities */ status =ice_aq_get_phy_caps (hw->port_info, false, -ICE_AQC_REPORT_TOPO_CAP_MEDIA , pcaps,NULL ); -ice_free (hw, pcaps); +ICE_AQC_REPORT_TOPO_CAP_MEDIA , &pcaps,NULL );if (status) goto err_unroll_alloc;
drivers/net/intel/ice/ice_dcf_sched.c +8 -17
@@ -723,8 +723,8 @@ static int ice_dcf_hierarchy_commit(struct rte_eth_dev *dev, {struct ice_dcf_adapter *adapter = dev->data->dev_private;struct ice_dcf_hw *hw = &adapter->real_hw; -struct virtchnl_dcf_bw_cfg_list *vf_bw =NULL ; -struct virtchnl_dcf_bw_cfg_list *tc_bw =NULL ; + RTE_DEFINE_FLEX(struct virtchnl_dcf_bw_cfg_list, vf_bw, cfg, ICE_MAX_TRAFFIC_CLASS - 1); + RTE_DEFINE_FLEX(struct virtchnl_dcf_bw_cfg_list, tc_bw, cfg, ICE_MAX_TRAFFIC_CLASS - 1);struct virtchnl_dcf_bw_cfg_list *bw_cfg;struct ice_dcf_tm_node_list *vsi_list = &hw->tm_conf.vsi_list;struct rte_tm_shaper_params *profile;
@@ -745,19 +745,15 @@ static int ice_dcf_hierarchy_commit(struct rte_eth_dev *dev,if (ret_val) goto fail_clear; +if (hw->tm_conf.nb_tc_node >ICE_MAX_TRAFFIC_CLASS ) { +PMD_DRV_LOG (ERR ,"Too many TC nodes: %u" , hw->tm_conf.nb_tc_node); + ret_val =ICE_ERR_PARAM ; + goto fail_clear; + } + size =sizeof (struct virtchnl_dcf_bw_cfg_list ) +sizeof (struct virtchnl_dcf_bw_cfg ) * (hw->tm_conf.nb_tc_node -1 ); - vf_bw =calloc (1 , size); -if (!vf_bw) { - ret_val =ICE_ERR_NO_MEMORY ; - goto fail_clear; - } - tc_bw =calloc (1 , size); -if (!tc_bw) { - ret_val =ICE_ERR_NO_MEMORY ; - goto fail_clear; - }/* port bandwidth (Kbps) */ port_bw = hw->link_speed *1000 ;
@@ -850,14 +846,9 @@ static int ice_dcf_hierarchy_commit(struct rte_eth_dev *dev,ice_dcf_replace_qos_bw_cfg (hw,ICE_DCF_VFID , bw_cfg); hw->tm_conf.committed = true; -free (vf_bw); -free (tc_bw);return ret_val; fail_clear: -free (vf_bw); -free (tc_bw); -/* clear all the traffic manager configuration */ if (clear_on_fail) {ice_dcf_tm_conf_uninit (dev);
drivers/net/intel/ice/ice_diagnose.c +2 -10
@@ -453,13 +453,9 @@ ice_dump_switch(struct rte_eth_dev *dev, uint8_t **buff2, uint32_t *size)for (i =0 ; i <ICE_BLK_MAX_COUNT ; i++) {int res;uint16_t buff_size; -uint8_t *buff; +uint8_t buff[ICE_PKG_BUF_SIZE ];uint32_t offset =0 ; - buff =malloc (ICE_PKG_BUF_SIZE ); -if (!buff) -return ICE_ERR_NO_MEMORY ; -if (tbl_idx ==0 ) {char tbl_idx_str[TBL_IDX_STR_SIZE ];memset (tbl_idx_str,0 ,sizeof (tbl_idx_str));
@@ -475,16 +471,12 @@ ice_dump_switch(struct rte_eth_dev *dev, uint8_t **buff2, uint32_t *size)ICE_PKG_BUF_SIZE , &buff_size, &tbl_id, &tbl_idx, NULL, cd); -if (res) { -free (buff); +if (res)return res; - } offset =covert_byte_to_hex (&buffer, buff, buff_size); buffer += offset; -free (buff); -if (tbl_idx ==0xffff ) { tbl_idx =0 ;memset (buffer,'\n' ,sizeof (char ));
drivers/net/intel/ice/ice_ethdev.c +29 -75
255 lines not on this page · raw message
drivers/net/intel/ice/ice_rxtx.c +3 -23
@@ -790,7 +790,7 @@ ice_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)struct ice_vsi *vsi;struct ice_hw *hw;struct ice_pf *pf; -struct ice_aqc_add_tx_qgrp *txq_elem; + RTE_DEFINE_FLEX(struct ice_aqc_add_tx_qgrp, txq_elem, txqs, 1);struct ice_tlan_ctx tx_ctx;int buf_len;struct ice_adapter *ad =ICE_DEV_PRIVATE_TO_ADAPTER (dev->data->dev_private);
@@ -816,9 +816,6 @@ ice_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)return 0 ; buf_len =ice_struct_size (txq_elem, txqs,1 ); - txq_elem =ice_malloc (hw, buf_len); -if (!txq_elem) -return -ENOMEM ; vsi = txq->ice_vsi; hw =ICE_VSI_TO_HW (vsi);
@@ -854,13 +851,11 @@ ice_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id) }if (cgd_idx >=ICE_MAX_TRAFFIC_CLASS ) {PMD_DRV_LOG (ERR ,"Bad queue mapping configuration" ); -ice_free (hw, txq_elem);return -EINVAL ; } }else if (pf->dcb_num_tcs >1 ) {/* TM only manages the TC0 scheduler subtree. */ PMD_DRV_LOG (ERR ,"TM hierarchy is not supported together with multi-TC DCB" ); -ice_free (hw, txq_elem);return -EINVAL ; }
@@ -874,7 +869,6 @@ ice_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id) txq_elem, buf_len, NULL);if (err) {PMD_DRV_LOG (ERR ,"Failed to add lan txq" ); -ice_free (hw, txq_elem);return -EIO ; }/* store the schedule node id */
@@ -884,7 +878,6 @@ ice_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)if (pf->tm_conf.committed)if (ice_tm_setup_txq_node (pf, hw, tx_queue_id, txq->q_teid) !=0 ) {PMD_DRV_LOG (ERR ,"Failed to set up txq traffic management node" ); -ice_free (hw, txq_elem);return -EIO ; }
@@ -893,15 +886,10 @@ ice_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id) txq->use_ctx = ad->use_ctx;if (txq->tsq !=NULL && txq->tsq->ts_flag >0 ) { -struct ice_aqc_set_txtime_qgrp *ts_elem; + RTE_DEFINE_FLEX(struct ice_aqc_set_txtime_qgrp, ts_elem, txtimeqs, 1);struct ice_txtime_ctx txtime_ctx = {0 };u8 ts_buf_len =ice_struct_size (ts_elem, txtimeqs,1 ); - ts_elem =ice_malloc (hw, ts_buf_len); -if (!ts_elem) { -ice_free (hw, txq_elem); -return -ENOMEM ; - }ice_setup_txtime_ctx (txq, &txtime_ctx, true); ice_set_ctx(hw, (u8 *)&txtime_ctx, ts_elem->txtimeqs[0].txtime_ctx,
@@ -913,10 +901,8 @@ ice_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)ICE_PCI_REG_WRITE (txq->qtx_tail,0 ); err =ice_aq_set_txtimeq (hw, txq->reg_idx,1 , ts_elem, ts_buf_len,NULL ); -ice_free (hw, ts_elem);if (err) {PMD_DRV_LOG (ERR ,"Failed to set Tx Time queue context, error: %d" , err); -ice_free (hw, txq_elem);return err; } }else {
@@ -928,7 +914,6 @@ ice_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id) dev->data->tx_queue_state[tx_queue_id] =RTE_ETH_QUEUE_STATE_STARTED ; -ice_free (hw, txq_elem);return 0 ; }
@@ -1052,7 +1037,7 @@ ice_fdir_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)int err;struct ice_vsi *vsi;struct ice_hw *hw; -struct ice_aqc_add_tx_qgrp *txq_elem; + RTE_DEFINE_FLEX(struct ice_aqc_add_tx_qgrp, txq_elem, txqs, 1);struct ice_tlan_ctx tx_ctx;int buf_len;
@@ -1066,9 +1051,6 @@ ice_fdir_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id) } buf_len =ice_struct_size (txq_elem, txqs,1 ); - txq_elem =ice_malloc (hw, buf_len); -if (!txq_elem) -return -ENOMEM ; vsi = txq->ice_vsi; hw =ICE_VSI_TO_HW (vsi);
@@ -1100,13 +1082,11 @@ ice_fdir_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id) txq_elem, buf_len, NULL);if (err) {PMD_DRV_LOG (ERR ,"Failed to add FDIR txq" ); -ice_free (hw, txq_elem);return -EIO ; }/* store the schedule node id */ txq->q_teid = txq_elem->txqs[0 ].q_teid; -ice_free (hw, txq_elem);return 0 ; }
drivers/net/intel/ice/ice_tm.c +1 -6
@@ -712,14 +712,10 @@ ice_tm_setup_txq_node(struct ice_pf *pf, struct ice_hw *hw, uint16_t qid, uint32/* if the queue node has been put in the wrong place in hierarchy */ if (hw_node->parent != sw_node->parent->sched_node) { -struct ice_aqc_move_txqs_data *buf; + RTE_DEFINE_FLEX(struct ice_aqc_move_txqs_data, buf, txqs, 1);uint8_t txqs_moved =0 ;uint16_t buf_size =ice_struct_size (buf, txqs,1 ); - buf =calloc (1 , buf_size); -if (buf ==NULL ) -return -ENOMEM ; -struct ice_sched_node *parent = hw_node->parent;struct ice_sched_node *new_parent = sw_node->parent->sched_node; buf->src_teid = parent->info.node_teid;
@@ -729,7 +725,6 @@ ice_tm_setup_txq_node(struct ice_pf *pf, struct ice_hw *hw, uint16_t qid, uint32int ret =ice_aq_move_recfg_lan_txq (hw,1 , true, false, false, false,50 ,NULL , buf, buf_size, &txqs_moved,NULL ); -free (buf);if (ret || txqs_moved ==0 ) {PMD_DRV_LOG (ERR ,"move lan queue %u failed" , qid);return ICE_ERR_PARAM ;
Signature · 1 line
2.55.0
PATCH 4/6 net/idpf: use stack storage for virtchnl messages
In reply to Bruce RichardsonRather than using malloc and free for virtchnl message buffers whose maximum size is known at compile time, define them on the stack using RTE_DEFINE_FLEX. This removes the allocation failure and cleanup paths.
As part of this, the queue chunks in idpf_vc_queues_ena_dis() are now filled sequentially rather than indexed by queue type.
--- drivers/net/intel/idpf/idpf_common_device.c | 27 ++----- drivers/net/intel/idpf/idpf_common_virtchnl.c | 77 +++++++------------ 2 files changed, 36 insertions(+), 68 deletions(-)
drivers/net/intel/idpf/idpf_common_device.c +8 -19
@@ -157,23 +157,15 @@ idpf_init_mbx(struct idpf_hw *hw)static int idpf_get_pkt_type (struct idpf_adapter *adapter) { -struct virtchnl2_get_ptype_info *req_ptype_info; -struct virtchnl2_get_ptype_info *recv_ptype_info; +struct virtchnl2_get_ptype_info req_ptype_msg = {0 }; +struct virtchnl2_get_ptype_info *req_ptype_info = &req_ptype_msg; + RTE_DEFINE_FLEX_BYTES(struct virtchnl2_get_ptype_info, recv_ptype_info, + IDPF_DFLT_MBX_BUF_SIZE);uint16_t recv_num_ptypes =0 ;uint16_t ptype_offset, i, j;uint16_t start_ptype_id =0 ;int ret; - req_ptype_info =rte_zmalloc ("req_ptype_info" ,IDPF_DFLT_MBX_BUF_SIZE ,0 ); -if (req_ptype_info ==NULL ) -return -ENOMEM ; - - recv_ptype_info =rte_zmalloc ("recv_ptype_info" ,IDPF_DFLT_MBX_BUF_SIZE ,0 ); -if (recv_ptype_info ==NULL ) { - ret = -ENOMEM ; - goto free_req_ptype_info; - } -while (start_ptype_id <IDPF_MAX_PKT_TYPE ) {memset (req_ptype_info,0 ,sizeof (*req_ptype_info));memset (recv_ptype_info,0 ,sizeof (*recv_ptype_info));
@@ -188,13 +180,13 @@ idpf_get_pkt_type(struct idpf_adapter *adapter) ret =idpf_vc_ptype_info_query (adapter, req_ptype_info, recv_ptype_info);if (ret !=0 ) {DRV_LOG (ERR ,"Fail to query packet type information" ); - goto free_recv_ptype_info; + goto out; } recv_num_ptypes +=rte_le_to_cpu_16 (recv_ptype_info->num_ptypes);if (recv_num_ptypes >IDPF_MAX_PKT_TYPE ) { ret = -EINVAL ; - goto free_recv_ptype_info; + goto out; } start_ptype_id = rte_le_to_cpu_16(req_ptype_info->start_ptype_id) +
@@ -213,7 +205,7 @@ idpf_get_pkt_type(struct idpf_adapter *adapter) ptype_offset +=IDPF_GET_PTYPE_SIZE (ptype);if (ptype_offset >IDPF_DFLT_MBX_BUF_SIZE ) { ret = -EINVAL ; - goto free_recv_ptype_info; + goto out; }for (j =0 ; j < ptype->proto_id_count; j++) {
@@ -374,10 +366,7 @@ idpf_get_pkt_type(struct idpf_adapter *adapter) } } -free_recv_ptype_info: -rte_free (recv_ptype_info); -free_req_ptype_info: -rte_free (req_ptype_info); +out:clear_cmd (adapter);return ret; }
drivers/net/intel/idpf/idpf_common_virtchnl.c +28 -49
207 lines not on this page · raw message
Signature · 1 line
2.55.0
PATCH 5/6 net/cpfl: use stack storage for function-local buffers
In reply to Bruce RichardsonRather than using malloc and free for virtchnl and control queue buffers used only within a single function, define them on the stack, using RTE_DEFINE_FLEX for those structures ending in a variable-length array. This removes the allocation failure and cleanup paths.
Where the number of elements used depends on runtime values, add checks that those values do not exceed the buffer sizes.
--- drivers/net/intel/cpfl/cpfl_fxp_rule.c | 20 ++++------- drivers/net/intel/cpfl/cpfl_representor.c | 15 +++++---- drivers/net/intel/cpfl/cpfl_vchnl.c | 41 +++++++++-------------- 3 files changed, 32 insertions(+), 44 deletions(-)
drivers/net/intel/cpfl/cpfl_fxp_rule.c +7 -13
@@ -13,23 +13,21 @@ int cpfl_send_ctlq_msg(struct idpf_hw *hw, struct idpf_ctlq_info *cq, u16 num_q_msg, struct idpf_ctlq_msg q_msg[]) { - struct idpf_ctlq_msg **msg_ptr_list; + struct idpf_ctlq_msg *msg_ptr_list[CPFL_FLOW_BATCH_SIZE] = {0};u16 clean_count =0 ;int num_cleaned =0 ;int retries =0 ;int ret =0 ; - msg_ptr_list =calloc (num_q_msg,sizeof (struct idpf_ctlq_msg *)); -if (!msg_ptr_list) { -PMD_INIT_LOG (ERR ,"no memory for cleaning ctlq" ); - ret = -ENOMEM ; - goto err; +if (num_q_msg >RTE_DIM (msg_ptr_list)) { +PMD_INIT_LOG (ERR ,"too many messages for ctlq: %u" , num_q_msg); +return -EINVAL ; } ret =cpfl_vport_ctlq_send (hw, cq, num_q_msg, q_msg);if (ret) {PMD_INIT_LOG (ERR ,"cpfl_vport_ctlq_send() failed with error: 0x%4x" , ret); - goto send_err; +return ret; }while (retries <=CTLQ_SEND_RETRIES ) {
@@ -38,7 +36,7 @@ cpfl_send_ctlq_msg(struct idpf_hw *hw, struct idpf_ctlq_info *cq, u16 num_q_msg, &msg_ptr_list[num_cleaned]);if (ret) {PMD_INIT_LOG (ERR ,"clean ctlq failed: 0x%4x" , ret); - goto send_err; +return ret; } num_cleaned += clean_count;
@@ -50,13 +48,9 @@ cpfl_send_ctlq_msg(struct idpf_hw *hw, struct idpf_ctlq_info *cq, u16 num_q_msg,if (retries >CTLQ_SEND_RETRIES ) {PMD_INIT_LOG (ERR ,"timed out while polling for completions" ); - ret =-1 ; - goto send_err; +return -1 ; } -send_err: -free (msg_ptr_list); -err:return ret; }
drivers/net/intel/cpfl/cpfl_representor.c +9 -6
@@ -558,14 +558,11 @@ cpfl_repr_create(struct rte_pci_device *pci_dev, struct cpfl_adapter_ext *adapteuint32_t iter =0 ;const struct cpfl_repr_id *repr_id;const struct cpfl_vport_id *vp_id; -struct cpchnl2_get_vport_list_response *vlist_resp; + RTE_DEFINE_FLEX_BYTES(struct cpchnl2_get_vport_list_response, vlist_resp, + IDPF_DFLT_MBX_BUF_SIZE);struct cpchnl2_get_vport_info_response vinfo_resp;int ret; - vlist_resp =rte_zmalloc (NULL ,IDPF_DFLT_MBX_BUF_SIZE ,0 ); -if (vlist_resp ==NULL ) -return -ENOMEM ; -rte_spinlock_lock (&adapter->repr_lock); while (rte_hash_iterate(adapter->repr_allowlist_hash,
@@ -603,6 +600,13 @@ cpfl_repr_create(struct rte_pci_device *pci_dev, struct cpfl_adapter_ext *adaptePMD_INIT_LOG (WARNING ,"No matched vport for representor %s" , name);continue ; } +if (vlist_resp->nof_vports > (IDPF_DFLT_MBX_BUF_SIZE -sizeof (*vlist_resp)) / +sizeof (vlist_resp->vports[0 ])) { +PMD_INIT_LOG (ERR ,"Invalid vport count %u for representor %s" , + vlist_resp->nof_vports, name); + ret = -EINVAL ; + goto err; + }/* get all vport info for the port representor */ for (i =0 ; i < vlist_resp->nof_vports; i++) {
@@ -657,6 +661,5 @@ cpfl_repr_create(struct rte_pci_device *pci_dev, struct cpfl_adapter_ext *adapte err:rte_spinlock_unlock (&adapter->repr_lock); -rte_free (vlist_resp);return ret; }
drivers/net/intel/cpfl/cpfl_vchnl.c +16 -25
99 lines not on this page · raw message
Signature · 1 line
2.55.0
PATCH 6/6 net/i40e: use stack storage for function-local buffers
In reply to Bruce RichardsonRather 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.
--- drivers/net/intel/i40e/i40e_ethdev.c | 27 +++++---------------------- drivers/net/intel/i40e/i40e_testpmd.c | 10 ++-------- 2 files changed, 7 insertions(+), 30 deletions(-)
drivers/net/intel/i40e/i40e_ethdev.c +5 -22
@@ -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; }
drivers/net/intel/i40e/i40e_testpmd.c +2 -8
@@ -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" ); }
Signature · 1 line
2.55.0