Currently, when enabling, disabling, or switching queues, we are using rte_malloc followed by an immediate rte_free. This is not needed as these structures are not being stored anywhere, so replace them with stack allocation or malloc/free where appropriate.
Signed-off-by: Anatoly Burakov <[email protected]> --- drivers/net/intel/iavf/iavf_vchnl.c | 65 ++++++++++++----------------- 1 file changed, 26 insertions(+), 39 deletions(-) diff --git a/drivers/net/intel/iavf/iavf_vchnl.c b/drivers/net/intel/iavf/iavf_vchnl.c index 19dce17612..af1f5fbfc0 100644 --- a/drivers/net/intel/iavf/iavf_vchnl.c +++ b/drivers/net/intel/iavf/iavf_vchnl.c @@ -1020,19 +1020,15 @@ int iavf_enable_queues_lv(struct iavf_adapter *adapter) { struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter); - struct virtchnl_del_ena_dis_queues *queue_select; - struct virtchnl_queue_chunk *queue_chunk; + struct { + struct virtchnl_del_ena_dis_queues msg; + struct virtchnl_queue_chunk chunks[IAVF_RXTX_QUEUE_CHUNKS_NUM - 1]; + } queue_req = {0}; + struct virtchnl_del_ena_dis_queues *queue_select = &queue_req.msg; + struct virtchnl_queue_chunk *queue_chunk = queue_select->chunks.chunks; struct iavf_cmd_info args; - int err, len; + int err; - len = sizeof(struct virtchnl_del_ena_dis_queues) + - sizeof(struct virtchnl_queue_chunk) * - (IAVF_RXTX_QUEUE_CHUNKS_NUM - 1); - queue_select = rte_zmalloc("queue_select", len, 0); - if (!queue_select) - return -ENOMEM; - - queue_chunk = queue_select->chunks.chunks; queue_select->chunks.num_chunks = IAVF_RXTX_QUEUE_CHUNKS_NUM; queue_select->vport_id = vf->vsi_res->vsi_id; @@ -1048,7 +1044,7 @@ iavf_enable_queues_lv(struct iavf_adapter *adapter) args.ops = VIRTCHNL_OP_ENABLE_QUEUES_V2; args.in_args = (u8 *)queue_select; - args.in_args_size = len; + args.in_args_size = sizeof(queue_req); args.out_buffer = vf->aq_resp; args.out_size = IAVF_AQ_BUF_SZ; err = iavf_execute_vf_cmd_safe(adapter, &args, 0); @@ -1056,7 +1052,6 @@ iavf_enable_queues_lv(struct iavf_adapter *adapter) PMD_DRV_LOG(ERR, "Failed to execute command of OP_ENABLE_QUEUES_V2"); - rte_free(queue_select); return err; } @@ -1064,19 +1059,15 @@ int iavf_disable_queues_lv(struct iavf_adapter *adapter) { struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter); - struct virtchnl_del_ena_dis_queues *queue_select; - struct virtchnl_queue_chunk *queue_chunk; + struct { + struct virtchnl_del_ena_dis_queues msg; + struct virtchnl_queue_chunk chunks[IAVF_RXTX_QUEUE_CHUNKS_NUM - 1]; + } queue_req = {0}; + struct virtchnl_del_ena_dis_queues *queue_select = &queue_req.msg; + struct virtchnl_queue_chunk *queue_chunk = queue_select->chunks.chunks; struct iavf_cmd_info args; - int err, len; + int err; - len = sizeof(struct virtchnl_del_ena_dis_queues) + - sizeof(struct virtchnl_queue_chunk) * - (IAVF_RXTX_QUEUE_CHUNKS_NUM - 1); - queue_select = rte_zmalloc("queue_select", len, 0); - if (!queue_select) - return -ENOMEM; - - queue_chunk = queue_select->chunks.chunks; queue_select->chunks.num_chunks = IAVF_RXTX_QUEUE_CHUNKS_NUM; queue_select->vport_id = vf->vsi_res->vsi_id; @@ -1092,7 +1083,7 @@ iavf_disable_queues_lv(struct iavf_adapter *adapter) args.ops = VIRTCHNL_OP_DISABLE_QUEUES_V2; args.in_args = (u8 *)queue_select; - args.in_args_size = len; + args.in_args_size = sizeof(queue_req); args.out_buffer = vf->aq_resp; args.out_size = IAVF_AQ_BUF_SZ; err = iavf_execute_vf_cmd_safe(adapter, &args, 0); @@ -1100,7 +1091,6 @@ iavf_disable_queues_lv(struct iavf_adapter *adapter) PMD_DRV_LOG(ERR, "Failed to execute command of OP_DISABLE_QUEUES_V2"); - rte_free(queue_select); return err; } @@ -1109,17 +1099,15 @@ iavf_switch_queue_lv(struct iavf_adapter *adapter, uint16_t qid, bool rx, bool on) { struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter); - struct virtchnl_del_ena_dis_queues *queue_select; - struct virtchnl_queue_chunk *queue_chunk; + struct { + struct virtchnl_del_ena_dis_queues msg; + struct virtchnl_queue_chunk chunks[IAVF_RXTX_QUEUE_CHUNKS_NUM - 1]; + } queue_req; + struct virtchnl_del_ena_dis_queues *queue_select = &queue_req.msg; + struct virtchnl_queue_chunk *queue_chunk = queue_select->chunks.chunks; struct iavf_cmd_info args; - int err, len; + int err; - len = sizeof(struct virtchnl_del_ena_dis_queues); - queue_select = rte_zmalloc("queue_select", len, 0); - if (!queue_select) - return -ENOMEM; - - queue_chunk = queue_select->chunks.chunks; queue_select->chunks.num_chunks = 1; queue_select->vport_id = vf->vsi_res->vsi_id; @@ -1138,7 +1126,7 @@ iavf_switch_queue_lv(struct iavf_adapter *adapter, uint16_t qid, else args.ops = VIRTCHNL_OP_DISABLE_QUEUES_V2; args.in_args = (u8 *)queue_select; - args.in_args_size = len; + args.in_args_size = sizeof(queue_req); args.out_buffer = vf->aq_resp; args.out_size = IAVF_AQ_BUF_SZ; err = iavf_execute_vf_cmd_safe(adapter, &args, 0); @@ -1146,7 +1134,6 @@ iavf_switch_queue_lv(struct iavf_adapter *adapter, uint16_t qid, PMD_DRV_LOG(ERR, "Failed to execute command of %s", on ? "OP_ENABLE_QUEUES_V2" : "OP_DISABLE_QUEUES_V2"); - rte_free(queue_select); return err; } @@ -1229,7 +1216,7 @@ iavf_configure_queues(struct iavf_adapter *adapter, size = sizeof(*vc_config) + sizeof(vc_config->qpair[0]) * num_queue_pairs; - vc_config = rte_zmalloc("cfg_queue", size, 0); + vc_config = calloc(1, size); if (!vc_config) return -ENOMEM; @@ -1292,7 +1279,7 @@ iavf_configure_queues(struct iavf_adapter *adapter, PMD_DRV_LOG(ERR, "Failed to execute command of" " VIRTCHNL_OP_CONFIG_VSI_QUEUES"); - rte_free(vc_config); + free(vc_config); return err; } -- 2.47.3

