]> git.droids-corp.org - dpdk.git/commitdiff
ethdev: clarify null location case in xstats get
authorChengwen Feng <fengchengwen@huawei.com>
Fri, 13 May 2022 02:53:49 +0000 (10:53 +0800)
committerAndrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
Fri, 20 May 2022 14:45:25 +0000 (16:45 +0200)
When xstats location is null in rte_eth_xstats_get() the return value
is not clearly specified.  Some PMDs (eg. hns3/ipn3ke/mvpp2/axgbe) return
zero while others return the required number of elements.

In this patch, special parameter combinations are restricted:
 1. highlight that xstats location may be null if and only if n is 0.
 2. amend n parameter description to specify that if n is lower than
    the required number of elements, the function returns the required
    number of elements.
 3. specify that if n is zero, the xstats must be NULL, the function
    returns the required number of elements (a duplicate which should
    help to not very attentive readers).

Add sanity check for null xstats and non-zero n case on API level to
make it unnecessary to care about it in drivers.

Fixes: ce757f5c9a4d ("ethdev: new method to retrieve extended statistics")
Cc: stable@dpdk.org
Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
Reviewed-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
lib/ethdev/rte_ethdev.c
lib/ethdev/rte_ethdev.h

index 8520aec5619e14fe98192a8a53fcda8cd9da33e3..af55edb6b970595f1bef27a78c5d002a34967110 100644 (file)
@@ -2973,6 +2973,8 @@ rte_eth_xstats_get(uint16_t port_id, struct rte_eth_xstat *xstats,
        int ret;
 
        RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+       if (xstats == NULL && n > 0)
+               return -EINVAL;
        dev = &rte_eth_devices[port_id];
 
        nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
@@ -2989,7 +2991,7 @@ rte_eth_xstats_get(uint16_t port_id, struct rte_eth_xstat *xstats,
                 * xstats struct.
                 */
                xcount = (*dev->dev_ops->xstats_get)(dev,
-                                    xstats ? xstats + count : NULL,
+                                    (n > count) ? xstats + count : NULL,
                                     (n > count) ? n - count : 0);
 
                if (xcount < 0)
index 04cff8ee103bf466af6ad1251ed566a91702df98..04225bba4d5d0f37a77f2828c8465a792f147ccc 100644 (file)
@@ -3174,9 +3174,13 @@ int rte_eth_xstats_get_names(uint16_t port_id,
  * @param xstats
  *   A pointer to a table of structure of type *rte_eth_xstat*
  *   to be filled with device statistics ids and values.
- *   This parameter can be set to NULL if n is 0.
+ *   This parameter can be set to NULL if and only if n is 0.
  * @param n
  *   The size of the xstats array (number of elements).
+ *   If lower than the required number of elements, the function returns
+ *   the required number of elements.
+ *   If equal to zero, the xstats must be NULL, the function returns the
+ *   required number of elements.
  * @return
  *   - A positive value lower or equal to n: success. The return value
  *     is the number of entries filled in the stats table.