From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 757D891B5 for ; Tue, 24 Nov 2015 18:38:22 +0100 (CET) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga103.jf.intel.com with ESMTP; 24 Nov 2015 09:38:21 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,339,1444719600"; d="scan'208";a="846230726" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga001.fm.intel.com with ESMTP; 24 Nov 2015 09:38:14 -0800 Received: from sivswdev01.ir.intel.com (sivswdev01.ir.intel.com [10.237.217.45]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id tAOHcDQx016993; Tue, 24 Nov 2015 17:38:13 GMT Received: from sivswdev01.ir.intel.com (localhost [127.0.0.1]) by sivswdev01.ir.intel.com with ESMTP id tAOHcDSK001541; Tue, 24 Nov 2015 17:38:13 GMT Received: (from bricha3@localhost) by sivswdev01.ir.intel.com with id tAOHcDRQ001537; Tue, 24 Nov 2015 17:38:13 GMT From: Bruce Richardson To: dev@dpdk.org Date: Tue, 24 Nov 2015 17:37:57 +0000 Message-Id: <1448386677-1441-3-git-send-email-bruce.richardson@intel.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1448386677-1441-1-git-send-email-bruce.richardson@intel.com> References: <1447762867-32124-1-git-send-email-bruce.richardson@intel.com> <1448386677-1441-1-git-send-email-bruce.richardson@intel.com> Subject: [dpdk-dev] [PATCH v5 2/2] ethdev: add sanity checks to functions X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Nov 2015 17:38:22 -0000 The functions rte_eth_rx_queue_count and rte_eth_descriptor_done are supported by very few PMDs. Therefore, it is best to check for support for the functions in the ethdev library, so as to avoid run-time crashes at run-time if the application goes to use those APIs. Similarly, the port parameter should also be checked for validity. Signed-off-by: Bruce Richardson --- doc/guides/rel_notes/release_2_2.rst | 2 ++ lib/librte_ether/rte_ethdev.h | 15 +++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/doc/guides/rel_notes/release_2_2.rst b/doc/guides/rel_notes/release_2_2.rst index d39bf75..5b2ac63 100644 --- a/doc/guides/rel_notes/release_2_2.rst +++ b/doc/guides/rel_notes/release_2_2.rst @@ -259,6 +259,8 @@ API Changes * The devargs union field virtual is renamed to virt for C++ compatibility. +* The rte_eth_rx_queue_count() ethdev API now returns "int" instead of "uint32_t" + to allow the use of negative values as error codes on return ABI Changes ----------- diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h index 9fca6ba..1ff29e2 100644 --- a/lib/librte_ether/rte_ethdev.h +++ b/lib/librte_ether/rte_ethdev.h @@ -2533,16 +2533,16 @@ rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id, * @param queue_id * The queue id on the specific port. * @return - * The number of used descriptors in the specific queue. + * The number of used descriptors in the specific queue, or: + * (-EINVAL) if *port_id* is invalid + * (-ENOTSUP) if the device does not support this function */ -static inline uint32_t +static inline int rte_eth_rx_queue_count(uint8_t port_id, uint16_t queue_id) { struct rte_eth_dev *dev = &rte_eth_devices[port_id]; -#ifdef RTE_LIBRTE_ETHDEV_DEBUG - RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, 0); - RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_count, 0); -#endif + RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL); + RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_count, -ENOTSUP); return (*dev->dev_ops->rx_queue_count)(dev, queue_id); } @@ -2559,15 +2559,14 @@ rte_eth_rx_queue_count(uint8_t port_id, uint16_t queue_id) * - (1) if the specific DD bit is set. * - (0) if the specific DD bit is not set. * - (-ENODEV) if *port_id* invalid. + * - (-ENOTSUP) if the device does not support this function */ static inline int rte_eth_rx_descriptor_done(uint8_t port_id, uint16_t queue_id, uint16_t offset) { struct rte_eth_dev *dev = &rte_eth_devices[port_id]; -#ifdef RTE_LIBRTE_ETHDEV_DEBUG RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_descriptor_done, -ENOTSUP); -#endif return (*dev->dev_ops->rx_descriptor_done)( \ dev->data->rx_queues[queue_id], offset); } -- 2.5.0