From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id 0B5C82934 for ; Thu, 24 Nov 2016 11:59:53 +0100 (CET) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP; 24 Nov 2016 02:59:52 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,543,1473145200"; d="scan'208";a="905068285" Received: from fyigit-mobl1.ger.corp.intel.com (HELO [10.237.220.57]) ([10.237.220.57]) by orsmga003.jf.intel.com with ESMTP; 24 Nov 2016 02:59:51 -0800 To: Olivier Matz , dev@dpdk.org References: <1479981261-19512-1-git-send-email-olivier.matz@6wind.com> <1479981261-19512-3-git-send-email-olivier.matz@6wind.com> Cc: thomas.monjalon@6wind.com, konstantin.ananyev@intel.com, wenzhuo.lu@intel.com, helin.zhang@intel.com From: Ferruh Yigit Message-ID: <174b8455-3806-26a1-38bd-edb756c101d0@intel.com> Date: Thu, 24 Nov 2016 10:59:50 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.5.0 MIME-Version: 1.0 In-Reply-To: <1479981261-19512-3-git-send-email-olivier.matz@6wind.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit Subject: Re: [dpdk-dev] [RFC 2/9] ethdev: move queue id check in generic layer 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: Thu, 24 Nov 2016 10:59:54 -0000 On 11/24/2016 9:54 AM, Olivier Matz wrote: > The check of queue_id is done in all drivers implementing > rte_eth_rx_queue_count(). Factorize this check in the generic function. > > Note that the nfp driver was doing the check differently, which could > induce crashes if the queue index was too big. > > By the way, also move the is_supported test before the port valid and > queue valid test. > > PR=52423 > Signed-off-by: Olivier Matz > Acked-by: Ivan Boule > --- <...> > diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h > index c3edc23..9551cfd 100644 > --- a/lib/librte_ether/rte_ethdev.h > +++ b/lib/librte_ether/rte_ethdev.h > @@ -2693,7 +2693,7 @@ rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id, > * The queue id on the specific port. > * @return > * The number of used descriptors in the specific queue, or: > - * (-EINVAL) if *port_id* is invalid > + * (-EINVAL) if *port_id* or *queue_id* is invalid > * (-ENOTSUP) if the device does not support this function > */ > static inline int > @@ -2701,8 +2701,10 @@ rte_eth_rx_queue_count(uint8_t port_id, uint16_t queue_id) > { > struct rte_eth_dev *dev = &rte_eth_devices[port_id]; > > - RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL); > RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_count, -ENOTSUP); > + RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL); Doing port validity check before accessing dev->dev_ops->rx_queue_count can be good idea. What about validating port_id even before accessing rte_eth_devices[port_id]? > + if (queue_id >= dev->data->nb_rx_queues) > + return -EINVAL; > > return (*dev->dev_ops->rx_queue_count)(dev, queue_id); > } >