Skip to content

Commit

Permalink
app/procinfo: remove unnecessary rte_malloc
Browse files Browse the repository at this point in the history
[ upstream commit cfe29906c69bedb5f87dadcc02703ce46e80f37e ]

Better to use malloc() which is faster than rte_malloc()
and has more error checking, as is done already for statistics.

Fixes: 077c546 ("app/proc_info: add metrics displaying")

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
  • Loading branch information
shemminger authored and kevintraynor committed Oct 31, 2023
1 parent 6b396dc commit 997c669
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions app/proc-info/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <rte_common.h>
#include <rte_debug.h>
#include <rte_ethdev.h>
#include <rte_malloc.h>
#include <rte_memory.h>
#include <rte_memzone.h>
#include <rte_launch.h>
Expand Down Expand Up @@ -621,24 +620,23 @@ metrics_display(int port_id)
return;
}

metrics = rte_malloc("proc_info_metrics",
sizeof(struct rte_metric_value) * len, 0);
metrics = malloc(sizeof(struct rte_metric_value) * len);
if (metrics == NULL) {
printf("Cannot allocate memory for metrics\n");
return;
}

names = rte_malloc(NULL, sizeof(struct rte_metric_name) * len, 0);
names = malloc(sizeof(struct rte_metric_name) * len);
if (names == NULL) {
printf("Cannot allocate memory for metrics names\n");
rte_free(metrics);
free(metrics);
return;
}

if (len != rte_metrics_get_names(names, len)) {
printf("Cannot get metrics names\n");
rte_free(metrics);
rte_free(names);
free(metrics);
free(names);
return;
}

Expand All @@ -650,8 +648,8 @@ metrics_display(int port_id)
ret = rte_metrics_get_values(port_id, metrics, len);
if (ret < 0 || ret > len) {
printf("Cannot get metrics values\n");
rte_free(metrics);
rte_free(names);
free(metrics);
free(names);
return;
}

Expand All @@ -660,8 +658,8 @@ metrics_display(int port_id)
printf("%s: %"PRIu64"\n", names[i].name, metrics[i].value);

printf("%s############################\n", nic_stats_border);
rte_free(metrics);
rte_free(names);
free(metrics);
free(names);
}
#endif

Expand Down

0 comments on commit 997c669

Please sign in to comment.