From: Bruce Richardson Date: Tue, 24 Nov 2015 17:37:57 +0000 (+0000) Subject: ethdev: add sanity checks to functions X-Git-Tag: spdx-start~7957 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=33cf6be04d603e99056cbc88ddf46dc58d836e02;p=dpdk.git ethdev: add sanity checks to functions 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 --- diff --git a/doc/guides/rel_notes/release_2_2.rst b/doc/guides/rel_notes/release_2_2.rst index b523b26f56..2ab954c477 100644 --- a/doc/guides/rel_notes/release_2_2.rst +++ b/doc/guides/rel_notes/release_2_2.rst @@ -243,6 +243,9 @@ API Changes structures: rte_eth_dcb_rx_conf, rte_eth_dcb_tx_conf, rte_eth_vmdq_dcb_conf, rte_eth_vmdq_dcb_tx_conf. +* The rte_eth_rx_queue_count() function now returns "int" instead of "uint32_t" + to allow the use of negative values as error codes on return. + * The function rte_eal_pci_close_one() is removed. It was replaced by rte_eal_pci_detach(). @@ -259,7 +262,6 @@ API Changes * The devargs union field virtual is renamed to virt for C++ compatibility. - ABI Changes ----------- diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h index 9fca6ba68a..1ff29e2263 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); }