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 830132BCD for ; Thu, 25 Feb 2016 07:53:21 +0100 (CET) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga103.jf.intel.com with ESMTP; 24 Feb 2016 22:53:20 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,497,1449561600"; d="scan'208";a="658985284" Received: from shwdeisgchi083.ccr.corp.intel.com (HELO [10.239.67.193]) ([10.239.67.193]) by FMSMGA003.fm.intel.com with ESMTP; 24 Feb 2016 22:53:19 -0800 To: "Ananyev, Konstantin" , "dev@dpdk.org" References: <1451544799-70776-1-git-send-email-jianfeng.tan@intel.com> <1452836759-63540-1-git-send-email-jianfeng.tan@intel.com> <1452836759-63540-2-git-send-email-jianfeng.tan@intel.com> <2601191342CEEE43887BDE71AB97725836AE6184@irsmsx105.ger.corp.intel.com> From: "Tan, Jianfeng" Message-ID: <56CEA4DE.8040702@intel.com> Date: Thu, 25 Feb 2016 14:53:18 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: <2601191342CEEE43887BDE71AB97725836AE6184@irsmsx105.ger.corp.intel.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH v2 01/12] ethdev: add API to query packet type filling info 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, 25 Feb 2016 06:53:21 -0000 Hi Konstantin, On 1/15/2016 11:03 PM, Ananyev, Konstantin wrote: > >> -----Original Message----- >> From: Tan, Jianfeng >> Sent: Friday, January 15, 2016 5:46 AM >> To: dev@dpdk.org >> Cc: Zhang, Helin; Ananyev, Konstantin; Tan, Jianfeng >> Subject: [PATCH v2 01/12] ethdev: add API to query packet type filling info >> >> Add a new API rte_eth_dev_get_ptype_info to query wether/what packet type will >> be filled by given pmd rx burst function. >> >> Signed-off-by: Jianfeng Tan >> --- >> lib/librte_ether/rte_ethdev.c | 20 ++++++++++++++++++++ >> lib/librte_ether/rte_ethdev.h | 27 +++++++++++++++++++++++++++ >> lib/librte_mbuf/rte_mbuf.h | 6 ++++++ >> 3 files changed, 53 insertions(+) >> >> diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c >> index ed971b4..cd34f46 100644 >> --- a/lib/librte_ether/rte_ethdev.c >> +++ b/lib/librte_ether/rte_ethdev.c >> @@ -1614,6 +1614,26 @@ rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info) >> dev_info->driver_name = dev->data->drv_name; >> } >> >> +int >> +rte_eth_dev_get_ptype_info(uint8_t port_id, uint32_t ptype_mask, >> + uint32_t ptypes[], int num) >> +{ >> + int ret, i, j; >> + struct rte_eth_dev *dev; >> + uint32_t all_ptypes[RTE_PTYPE_MAX_NUM]; >> + >> + RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); >> + dev = &rte_eth_devices[port_id]; >> + RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_ptype_info_get, -ENOTSUP); >> + ret = (*dev->dev_ops->dev_ptype_info_get)(dev, all_ptypes); >> + >> + for (i = 0, j = 0; i < ret && j < num; ++i) >> + if (all_ptypes[i] & ptype_mask) >> + ptypes[j++] = all_ptypes[i]; >> + >> + return ret; > I think it needs to be something like: > > j = 0; > for (i = 0, j = 0; i < ret; ++i) { > if (all_ptypes[i] & ptype_mask) { > if (j < num) > ptypes[j] = all_ptypes[i]; > j++; > } > } > > return j; > > Konstantin > You are right, my previous code is wrong. But I have a concern about your code above: under the condition that the caller does not provide big enough array to store adequate ptypes, it has no way to return the not-enough-memory message back to caller. So under that condition, how about we just return -ENOMEM? Thanks, Jianfeng