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 050509A8D for ; Thu, 19 May 2016 12:57:31 +0200 (CEST) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga101.jf.intel.com with ESMTP; 19 May 2016 03:57:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.26,334,1459839600"; d="scan'208";a="810385466" Received: from irsmsx101.ger.corp.intel.com ([163.33.3.153]) by orsmga003.jf.intel.com with ESMTP; 19 May 2016 03:57:30 -0700 Received: from irsmsx103.ger.corp.intel.com ([169.254.3.198]) by IRSMSX101.ger.corp.intel.com ([169.254.1.42]) with mapi id 14.03.0248.002; Thu, 19 May 2016 11:57:29 +0100 From: "Mrozowicz, SlawomirX" To: Olivier Matz CC: "dev@dpdk.org" Thread-Topic: [PATCH] rte mempool: division or modulo by zero Thread-Index: AQHRrEurHqx8Y7KweESdQmuhnYqHOp+7P5gAgATgD/A= Date: Thu, 19 May 2016 10:57:28 +0000 Message-ID: <158888A50F43E34AAE179517F56C97455ACDD1@IRSMSX103.ger.corp.intel.com> References: <1463057213-4123-1-git-send-email-slawomirx.mrozowicz@intel.com> <57399158.7020509@6wind.com> In-Reply-To: <57399158.7020509@6wind.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [163.33.239.181] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH] rte mempool: division or modulo by zero 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, 19 May 2016 10:57:32 -0000 Hi Olivier, I try to marge my change CID 13234 with your patch 12057. Can you tell me which is the base commit to apply the patch. I think that I should apply your patches starting from 12834. Regards, Slawomir >-----Original Message----- >From: Olivier Matz [mailto:olivier.matz@6wind.com] >Sent: Monday, May 16, 2016 11:23 AM >To: Mrozowicz, SlawomirX >Cc: dev@dpdk.org >Subject: Re: [PATCH] rte mempool: division or modulo by zero > >Hi Slawomir, > >On 05/12/2016 02:46 PM, Slawomir Mrozowicz wrote: >> Fix issue reported by Coverity. >> >> Coverity ID 13243: Division or modulo by zero In function call >> rte_mempool_xmem_size, division by expression total_size which may be >> zero has undefined behavior. >> >> Fixes: 148f963fb532 ("xen: core library changes") >> >> Signed-off-by: Slawomir Mrozowicz >> --- >> lib/librte_mempool/rte_mempool.c | 18 +++++++++++------- >> 1 file changed, 11 insertions(+), 7 deletions(-) >> >> diff --git a/lib/librte_mempool/rte_mempool.c >> b/lib/librte_mempool/rte_mempool.c >> index f8781e1..01668c1 100644 >> --- a/lib/librte_mempool/rte_mempool.c >> +++ b/lib/librte_mempool/rte_mempool.c >> @@ -327,15 +327,19 @@ rte_mempool_calc_obj_size(uint32_t elt_size, >> uint32_t flags, size_t rte_mempool_xmem_size(uint32_t elt_num, >> size_t elt_sz, uint32_t pg_shift) { >> - size_t n, pg_num, pg_sz, sz; >> + size_t n, pg_num, pg_sz; >> + size_t sz =3D 0; >> >> - pg_sz =3D (size_t)1 << pg_shift; >> + if (elt_sz > 0) { >> + pg_sz =3D (size_t)1 << pg_shift; >> + n =3D pg_sz / elt_sz; >> >> - if ((n =3D pg_sz / elt_sz) > 0) { >> - pg_num =3D (elt_num + n - 1) / n; >> - sz =3D pg_num << pg_shift; >> - } else { >> - sz =3D RTE_ALIGN_CEIL(elt_sz, pg_sz) * elt_num; >> + if (n > 0) { >> + pg_num =3D (elt_num + n - 1) / n; >> + sz =3D pg_num << pg_shift; >> + } else { >> + sz =3D RTE_ALIGN_CEIL(elt_sz, pg_sz) * elt_num; >> + } >> } >> >> return sz; >> > >I think it would be clearer (either for the patch and the code) to avoid a= n >additional indent, and do something like that: > > size_t > rte_mempool_xmem_size(uint32_t elt_num, size_t elt_sz, > uint32_t pg_shift) > { > if (elt_sz =3D=3D 0) > return 0; > > /* same code as before */ > >It will also facilitate the merge with >http://patchwork.dpdk.org/dev/patchwork/patch/12057/ > >Could you please submit a v2 with this logic? > >Thanks, >Olivier