numam-dpdk/lib/sched/rte_pie.c
Weiguo Li 79aab97c94 sched: remove useless malloc in PIE data init
'rte_pie_rt_data_init(NULL)' is not expected, and it's ought to
fail when this happen. The malloc inside the function didn't work.
So remove the malloc otherwise will lead to a memory leak.

Fixes: 44c730b0e3 ("sched: add PIE based congestion management")
Cc: stable@dpdk.org

Signed-off-by: Weiguo Li <liwg06@foxmail.com>
Acked-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
2022-03-07 19:34:24 +01:00

71 lines
1.4 KiB
C

/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(c) 2020 Intel Corporation
*/
#include <stdlib.h>
#include <string.h>
#include "rte_pie.h"
#include <rte_malloc.h>
#ifdef __INTEL_COMPILER
#pragma warning(disable:2259) /* conversion may lose significant bits */
#endif
int
rte_pie_rt_data_init(struct rte_pie *pie)
{
if (pie == NULL) {
RTE_LOG(ERR, SCHED, "%s: Invalid addr for pie\n", __func__);
return -EINVAL;
}
memset(pie, 0, sizeof(*pie));
return 0;
}
int
rte_pie_config_init(struct rte_pie_config *pie_cfg,
const uint16_t qdelay_ref,
const uint16_t dp_update_interval,
const uint16_t max_burst,
const uint16_t tailq_th)
{
uint64_t tsc_hz = rte_get_tsc_hz();
if (pie_cfg == NULL)
return -1;
if (qdelay_ref <= 0) {
RTE_LOG(ERR, SCHED,
"%s: Incorrect value for qdelay_ref\n", __func__);
return -EINVAL;
}
if (dp_update_interval <= 0) {
RTE_LOG(ERR, SCHED,
"%s: Incorrect value for dp_update_interval\n", __func__);
return -EINVAL;
}
if (max_burst <= 0) {
RTE_LOG(ERR, SCHED,
"%s: Incorrect value for max_burst\n", __func__);
return -EINVAL;
}
if (tailq_th <= 0) {
RTE_LOG(ERR, SCHED,
"%s: Incorrect value for tailq_th\n", __func__);
return -EINVAL;
}
pie_cfg->qdelay_ref = (tsc_hz * qdelay_ref) / 1000;
pie_cfg->dp_update_interval = (tsc_hz * dp_update_interval) / 1000;
pie_cfg->max_burst = (tsc_hz * max_burst) / 1000;
pie_cfg->tailq_th = tailq_th;
return 0;
}