VLAs with known upper limits are replaced with fixed-length arrays.
In case an upper limit of an array cannot be known in advance,
the memory for such an array is allocated dynamically using alloca.
In comparison to malloc family of functions, the alloca executes faster
due to working directly with a stack instead of a heap,
for the same reason it does not require manual memory management.

Signed-off-by: Oleksandr Kolomeiets <okl-...@napatech.com>
---
 drivers/net/ntnic/meson.build                       |  2 --
 .../flow_api/profile_inline/flow_api_hw_db_inline.c | 13 ++++++++++---
 .../profile_inline/flow_api_profile_inline.c        |  8 ++++----
 3 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/drivers/net/ntnic/meson.build b/drivers/net/ntnic/meson.build
index 30a92130b5..b4c6cfe7de 100644
--- a/drivers/net/ntnic/meson.build
+++ b/drivers/net/ntnic/meson.build
@@ -124,5 +124,3 @@ sources = files(
         'ntnic_vfio.c',
         'ntnic_ethdev.c',
 )
-
-cflags += no_wvla_cflag
diff --git 
a/drivers/net/ntnic/nthw/flow_api/profile_inline/flow_api_hw_db_inline.c 
b/drivers/net/ntnic/nthw/flow_api/profile_inline/flow_api_hw_db_inline.c
index a016c82458..ae72b8775e 100644
--- a/drivers/net/ntnic/nthw/flow_api/profile_inline/flow_api_hw_db_inline.c
+++ b/drivers/net/ntnic/nthw/flow_api/profile_inline/flow_api_hw_db_inline.c
@@ -1343,9 +1343,11 @@ static int hw_db_inline_alloc_prioritized_cfn(struct 
flow_nic_dev *ndev,
        struct {
                uint64_t priority;
                uint32_t idx;
-       } sorted_priority[db->nb_cat];
+       } *sorted_priority;
 
-       memset(sorted_priority, 0x0, sizeof(sorted_priority));
+       sorted_priority = calloc(db->nb_cat, sizeof(*sorted_priority));
+       if (!sorted_priority)
+               return -1;
 
        uint32_t in_use_count = 0;
 
@@ -1360,13 +1362,16 @@ static int hw_db_inline_alloc_prioritized_cfn(struct 
flow_nic_dev *ndev,
                }
        }
 
-       if (in_use_count >= db->nb_cat - 1)
+       if (in_use_count >= db->nb_cat - 1) {
+               free(sorted_priority);
                return -1;
+       }
 
        if (in_use_count == 0) {
                db->cfn[db_cfn_idx].ref = 1;
                db->cfn[db_cfn_idx].cfn_hw = 1;
                db->cfn[db_cfn_idx].priority = priority;
+               free(sorted_priority);
                return db_cfn_idx;
        }
 
@@ -1400,6 +1405,7 @@ static int hw_db_inline_alloc_prioritized_cfn(struct 
flow_nic_dev *ndev,
                db->cfn[db_cfn_idx].ref = 1;
                db->cfn[db_cfn_idx].cfn_hw = goal;
                db->cfn[db_cfn_idx].priority = priority;
+               free(sorted_priority);
                return db_cfn_idx;
        }
 
@@ -1425,6 +1431,7 @@ static int hw_db_inline_alloc_prioritized_cfn(struct 
flow_nic_dev *ndev,
        db->cfn[db_cfn_idx].ref = 1;
        db->cfn[db_cfn_idx].cfn_hw = goal;
        db->cfn[db_cfn_idx].priority = priority;
+       free(sorted_priority);
 
        return db_cfn_idx;
 }
diff --git 
a/drivers/net/ntnic/nthw/flow_api/profile_inline/flow_api_profile_inline.c 
b/drivers/net/ntnic/nthw/flow_api/profile_inline/flow_api_profile_inline.c
index 6824b35463..c0407574f0 100644
--- a/drivers/net/ntnic/nthw/flow_api/profile_inline/flow_api_profile_inline.c
+++ b/drivers/net/ntnic/nthw/flow_api/profile_inline/flow_api_profile_inline.c
@@ -3198,15 +3198,15 @@ static void setup_db_qsl_data(struct nic_flow_def *fd, 
struct hw_db_inline_qsl_d
        } else {
                RTE_ASSERT(fd->dst_num_avail < HW_DB_INLINE_MAX_QST_PER_QSL);
 
-               uint32_t ports[fd->dst_num_avail];
-               uint32_t queues[fd->dst_num_avail];
+               uint32_t ports[HW_DB_INLINE_MAX_QST_PER_QSL];
+               uint32_t queues[HW_DB_INLINE_MAX_QST_PER_QSL];
 
                uint32_t port_index = 0;
                uint32_t queue_index = 0;
                uint32_t max = num_dest_port > num_queues ? num_dest_port : 
num_queues;
 
-               memset(ports, 0, fd->dst_num_avail);
-               memset(queues, 0, fd->dst_num_avail);
+               memset(ports, 0, sizeof(ports));
+               memset(queues, 0, sizeof(queues));
 
                qsl_data->table_size = max;
                qsl_data->retransmit = num_dest_port > 0 ? 1 : 0;
-- 
2.47.1

Reply via email to