From: Chengwen Feng <fengchengwen@huawei.com> To: <thomas@monjalon.net>, <ferruh.yigit@xilinx.com>, <andrew.rybchenko@oktetlabs.ru>, <ndabilpuram@marvell.com>, <kirankumark@marvell.com>, <skori@marvell.com>, <skoteshwar@marvell.com> Cc: <mb@smartsharesystems.com>, <stephen@networkplumber.org>, <dev@dpdk.org> Subject: [PATCH v4 1/9] ethdev: specify return value of xstats-get API Date: Fri, 13 May 2022 10:53:49 +0800 Message-ID: <20220513025357.52275-2-fengchengwen@huawei.com> (raw) In-Reply-To: <20220513025357.52275-1-fengchengwen@huawei.com> Currently the value returned when xstats is NULL of rte_eth_xstats_get() is not 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. specify that xstats is NULL if and only if n is 0. 2. 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. This patch also makes sure that xstats is NULL if n is lower or equal to the number of basic stats when invoke driver's ops. Fixes: ce757f5c9a4d ("ethdev: new method to retrieve extended statistics") Cc: stable@dpdk.org Signed-off-by: Chengwen Feng <fengchengwen@huawei.com> --- lib/ethdev/rte_ethdev.c | 4 +++- lib/ethdev/rte_ethdev.h | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c index 29a3d80466..d9661bd64f 100644 --- a/lib/ethdev/rte_ethdev.c +++ b/lib/ethdev/rte_ethdev.c @@ -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) diff --git a/lib/ethdev/rte_ethdev.h b/lib/ethdev/rte_ethdev.h index 04cff8ee10..04225bba4d 100644 --- a/lib/ethdev/rte_ethdev.h +++ b/lib/ethdev/rte_ethdev.h @@ -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. -- 2.33.0
next prev parent reply other threads:[~2022-05-13 3:00 UTC|newest] Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-04-16 1:07 [PATCH 0/3] bugfix for ethdev telemetry Chengwen Feng 2022-04-16 1:07 ` [PATCH 1/3] ethdev: fix telemetry xstats return null with some PMDs Chengwen Feng 2022-04-16 1:38 ` Stephen Hemminger 2022-04-21 6:49 ` Andrew Rybchenko 2022-04-24 3:44 ` fengchengwen 2022-04-25 10:16 ` Morten Brørup 2022-04-28 13:38 ` fengchengwen 2022-04-28 13:53 ` Morten Brørup 2022-04-16 1:07 ` [PATCH 2/3] ethdev: fix memory leak when telemetry xstats Chengwen Feng 2022-04-21 6:51 ` Andrew Rybchenko 2022-04-21 8:09 ` David Marchand 2022-04-21 9:03 ` Bruce Richardson 2022-04-22 8:14 ` David Marchand 2022-04-16 1:07 ` [PATCH 3/3] net/cnxk: fix telemetry possible null pointer access Chengwen Feng 2022-04-28 13:15 ` [PATCH v2 0/9] bugfix for ethdev telemetry Chengwen Feng 2022-04-28 13:15 ` [PATCH v2 1/9] ethdev: define retval when xstats is null of get xstats Chengwen Feng 2022-05-04 10:32 ` Andrew Rybchenko 2022-04-28 13:15 ` [PATCH v2 2/9] net/hns3: adjust " Chengwen Feng 2022-05-06 7:56 ` Min Hu (Connor) 2022-04-28 13:15 ` [PATCH v2 3/9] net/ipn3ke: " Chengwen Feng 2022-04-28 13:15 ` [PATCH v2 4/9] net/mvpp2: " Chengwen Feng 2022-04-28 13:15 ` [PATCH v2 5/9] net/axgbe: " Chengwen Feng 2022-04-28 13:15 ` [PATCH v2 6/9] ethdev: fix memory leak when telemetry xstats Chengwen Feng 2022-04-28 13:15 ` [PATCH v2 7/9] ethdev: support auto-filled flag when telemetry stats Chengwen Feng 2022-04-28 13:15 ` [PATCH v2 8/9] ethdev: fix possible null pointer access Chengwen Feng 2022-04-28 13:16 ` [PATCH v2 9/9] net/cnxk: fix telemetry " Chengwen Feng 2022-05-05 8:02 ` [PATCH v3 00/10] bugfix for ethdev telemetry Chengwen Feng 2022-05-05 8:02 ` [PATCH v3 01/10] ethdev: define retval when xstats is null of get xstats Chengwen Feng 2022-05-05 8:02 ` [PATCH v3 02/10] ethdev: optimize xstats-get API's implementation Chengwen Feng 2022-05-12 10:31 ` Andrew Rybchenko 2022-05-05 8:02 ` [PATCH v3 03/10] net/hns3: adjust retval when xstats is null of get xstats Chengwen Feng 2022-05-12 9:51 ` Andrew Rybchenko 2022-05-05 8:02 ` [PATCH v3 04/10] net/ipn3ke: " Chengwen Feng 2022-05-05 8:02 ` [PATCH v3 05/10] net/mvpp2: " Chengwen Feng 2022-05-05 8:02 ` [PATCH v3 06/10] net/axgbe: " Chengwen Feng 2022-05-12 10:00 ` Andrew Rybchenko 2022-05-05 8:02 ` [PATCH v3 07/10] ethdev: fix memory leak when telemetry xstats Chengwen Feng 2022-05-05 8:02 ` [PATCH v3 08/10] ethdev: support auto-filled flag when telemetry stats Chengwen Feng 2022-05-12 10:26 ` Andrew Rybchenko 2022-05-05 8:02 ` [PATCH v3 09/10] ethdev: fix possible null pointer access Chengwen Feng 2022-05-12 10:29 ` Andrew Rybchenko 2022-05-05 8:02 ` [PATCH v3 10/10] net/cnxk: fix telemetry " Chengwen Feng 2022-05-12 10:30 ` Andrew Rybchenko 2022-05-13 2:53 ` [PATCH v4 0/9] bugfix for ethdev telemetry Chengwen Feng 2022-05-13 2:53 ` Chengwen Feng [this message] 2022-05-13 2:53 ` [PATCH v4 2/9] ethdev: optimize xstats-get API's implementation Chengwen Feng 2022-05-13 2:53 ` [PATCH v4 3/9] net/hns3: adjust return value of xstats-get ops Chengwen Feng 2022-05-13 2:53 ` [PATCH v4 4/9] net/ipn3ke: " Chengwen Feng 2022-05-13 2:53 ` [PATCH v4 5/9] net/mvpp2: " Chengwen Feng 2022-05-13 2:53 ` [PATCH v4 6/9] net/axgbe: " Chengwen Feng 2022-05-13 2:53 ` [PATCH v4 7/9] ethdev: fix memory leak when telemetry xstats Chengwen Feng 2022-05-13 2:53 ` [PATCH v4 8/9] ethdev: fix possible null pointer access Chengwen Feng 2022-05-13 2:53 ` [PATCH v4 9/9] net/cnxk: fix telemetry " Chengwen Feng 2022-05-16 8:43 ` [PATCH v4 0/9] bugfix for ethdev telemetry Morten Brørup 2022-05-20 14:50 ` Andrew Rybchenko
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220513025357.52275-2-fengchengwen@huawei.com \ --to=fengchengwen@huawei.com \ --cc=andrew.rybchenko@oktetlabs.ru \ --cc=dev@dpdk.org \ --cc=ferruh.yigit@xilinx.com \ --cc=kirankumark@marvell.com \ --cc=mb@smartsharesystems.com \ --cc=ndabilpuram@marvell.com \ --cc=skori@marvell.com \ --cc=skoteshwar@marvell.com \ --cc=stephen@networkplumber.org \ --cc=thomas@monjalon.net \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
DPDK patches and discussions This inbox may be cloned and mirrored by anyone: git clone --mirror http://inbox.dpdk.org/dev/0 dev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 dev dev/ http://inbox.dpdk.org/dev \ dev@dpdk.org public-inbox-index dev Example config snippet for mirrors. Newsgroup available over NNTP: nntp://inbox.dpdk.org/inbox.dpdk.dev AGPL code for this site: git clone https://public-inbox.org/public-inbox.git