On Wed, 2 Jul 2025 15:34:45 +0800 Bingbin Chen <chen.bing...@zte.com.cn> wrote:
> if (hw->is_pf) { > + dtb_qid = hw->dev_sd->dtb_sd.queueid; > + fd_entry = rte_malloc(NULL, > + sizeof(ZXDH_DTB_ACL_ENTRY_INFO_T) * > ZXDH_MAX_FLOW_NUM, 1); > + key = rte_malloc(NULL, sizeof(struct fd_flow_key) * > ZXDH_MAX_FLOW_NUM, 1); > + key_mask = rte_malloc(NULL, > + sizeof(struct fd_flow_key) * ZXDH_MAX_FLOW_NUM, > 1); > + result = rte_malloc(NULL, > + sizeof(struct fd_flow_result) * > ZXDH_MAX_FLOW_NUM, 1); > + if (!fd_entry || !key || !key_mask || !result) { > + PMD_DRV_LOG(ERR, "fd_entry malloc failed!"); > + goto end; > + } > + > + for (int i = 0; i < ZXDH_MAX_FLOW_NUM; i++) { > + fd_entry[i].key_data = key + i * sizeof(struct > fd_flow_key); > + fd_entry[i].key_mask = key_mask + i * > sizeof(struct fd_flow_key); > + fd_entry[i].p_as_rslt = result + i * > sizeof(struct fd_flow_result); > + } > + ret = zxdh_np_dtb_acl_table_dump_by_vport(hw->dev_id, > dtb_qid, > + ZXDH_SDT_FD_TABLE, > hw->vport.vport, &entry_num, > + (uint8_t *)fd_entry); > + if (ret) { > + PMD_DRV_LOG(ERR, > "dpp_dtb_acl_table_dump_by_vport failed!"); > + goto end; > + } > + for (uint32_t i = 0; i < entry_num; i++) { > + offlow_key_dump((struct fd_flow_key > *)fd_entry[i].key_data, > + (struct fd_flow_key > *)fd_entry[i].key_mask, file); > + offlow_result_dump((struct fd_flow_result > *)fd_entry[i].p_as_rslt, > + file); > + } > + rte_free(result); > + rte_free(key_mask); > + rte_free(key); > + rte_free(fd_entry); > + } else { This code uses rte_malloc for temporary buffers. It would be faster, safer, and better to use malloc, calloc or alloca for these arrays. The rte_malloc library allocates from shared huge pages and the algorithm is slower than malloc, so should only be used when needed. Also, static analyzer and compiler tools know what malloc is and do a better job checking that.