From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Tan, Jianfeng" Subject: Re: [PATCH v2 01/12] ethdev: add API to query packet type filling info Date: Thu, 25 Feb 2016 22:57:04 +0800 Message-ID: <56CF1640.1060005@intel.com> 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> <56CEA4DE.8040702@intel.com> <2601191342CEEE43887BDE71AB97725836B0B2D4@irsmsx105.ger.corp.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit To: "Ananyev, Konstantin" , "dev@dpdk.org" Return-path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 2A82A2BD7 for ; Thu, 25 Feb 2016 15:57:07 +0100 (CET) In-Reply-To: <2601191342CEEE43887BDE71AB97725836B0B2D4@irsmsx105.ger.corp.intel.com> List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On 2/25/2016 7:17 PM, Ananyev, Konstantin wrote: >>>> +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? >> > As I remember, the agreement was - we don't return an -ENOMEM in that case. > What we do return - number of entries in ptypes[] that would be required to > store all adequate ptypes (similar to what snprinf() does). > So the user can do something like that (if he needs to): > > num = rte_eth_dev_get_ptype_info(port, ptype_mask, NULL, 0); > if (num < 0) {/*error handling*/} > ptypes = alloca(num * ptypes[0]); > n = rte_eth_dev_get_ptype_info(port, ptype_mask, ptypes, num); > ... > > Konstantin > Oh, yes. Sorry, I previously misunderstood your code. But I still have a concern of above way that this APIs should be called two times. I suggest to use a way, like strdup, callee to malloc, caller to free. I send out v3 right now, please have a look at if it's OK. Thanks, Jianfeng