metrics: do not fail silently when uninitialised

If rte_metrics_init() had not been called and hence the internal
metric storage is not allocated, rte_metrics_get_values() and
rte_metrics_get_name() would silently fail by returning zero
(i.e. no metrics registered). This patch changes the result of
this scenario to an explicit fail by returning -EIO.

Fixes: 349950ddb9c5 ("metrics: add information metrics library")
Cc: stable@dpdk.org

Signed-off-by: Remy Horton <remy.horton@intel.com>
This commit is contained in:
Remy Horton 2018-07-02 15:55:47 +01:00 committed by Thomas Monjalon
parent 50d2459fdd
commit a84bdf6a10

View File

@ -205,9 +205,8 @@ rte_metrics_get_names(struct rte_metric_name *names,
int return_value;
memzone = rte_memzone_lookup(RTE_METRICS_MEMZONE_NAME);
/* If not allocated, fail silently */
if (memzone == NULL)
return 0;
return -EIO;
stats = memzone->addr;
rte_spinlock_lock(&stats->lock);
@ -243,9 +242,9 @@ rte_metrics_get_values(int port_id,
return -EINVAL;
memzone = rte_memzone_lookup(RTE_METRICS_MEMZONE_NAME);
/* If not allocated, fail silently */
if (memzone == NULL)
return 0;
return -EIO;
stats = memzone->addr;
rte_spinlock_lock(&stats->lock);