From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id 7B8CB2B9E for ; Thu, 25 Feb 2016 12:17:51 +0100 (CET) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP; 25 Feb 2016 03:17:50 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,498,1449561600"; d="scan'208";a="911002693" Received: from irsmsx153.ger.corp.intel.com ([163.33.192.75]) by fmsmga001.fm.intel.com with ESMTP; 25 Feb 2016 03:17:49 -0800 Received: from irsmsx105.ger.corp.intel.com ([169.254.7.237]) by IRSMSX153.ger.corp.intel.com ([169.254.9.60]) with mapi id 14.03.0248.002; Thu, 25 Feb 2016 11:17:49 +0000 From: "Ananyev, Konstantin" To: "Tan, Jianfeng" , "dev@dpdk.org" Thread-Topic: [PATCH v2 01/12] ethdev: add API to query packet type filling info Thread-Index: AQHRT5LBzIQ8xSOrQkuYMeiXqH5ZgJ78q0KAgD/oAgCAAEf3sA== Date: Thu, 25 Feb 2016 11:17:48 +0000 Message-ID: <2601191342CEEE43887BDE71AB97725836B0B2D4@irsmsx105.ger.corp.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> In-Reply-To: <56CEA4DE.8040702@intel.com> Accept-Language: en-IE, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiMTFkYmRhMWUtNWE1Ni00MTNiLTk2YTgtNjYyNjY3MjY0NDgwIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE1LjkuNi42IiwiVHJ1c3RlZExhYmVsSGFzaCI6IjdDd0hGZ3FKNWllUFF3QVB0OCtiU2xhUXBNSDU1eFwvelZtWEJob0V1Y0RBPSJ9 x-ctpclassification: CTP_IC x-originating-ip: [163.33.239.180] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 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 11:17:51 -0000 > >> +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 =3D &rte_eth_devices[port_id]; > >> + RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_ptype_info_get, -ENOTSUP)= ; > >> + ret =3D (*dev->dev_ops->dev_ptype_info_get)(dev, all_ptypes); > >> + > >> + for (i =3D 0, j =3D 0; i < ret && j < num; ++i) > >> + if (all_ptypes[i] & ptype_mask) > >> + ptypes[j++] =3D all_ptypes[i]; > >> + > >> + return ret; > > I think it needs to be something like: > > > > j =3D 0; > > for (i =3D 0, j =3D 0; i < ret; ++i) { > > if (all_ptypes[i] & ptype_mask) { > > if (j < num) > > ptypes[j] =3D all_ptypes[i]; > > j++; > > } > > } > > > > return j; > > > > Konstantin > > >=20 > 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. >=20 > So under that condition, how about we just return -ENOMEM? >=20 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= =20 store all adequate ptypes (similar to what snprinf() does). So the user can do something like that (if he needs to):=20 num =3D rte_eth_dev_get_ptype_info(port, ptype_mask, NULL, 0); if (num < 0) {/*error handling*/} ptypes =3D alloca(num * ptypes[0]); n =3D rte_eth_dev_get_ptype_info(port, ptype_mask, ptypes, num); ... Konstantin