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 A7B033230 for ; Mon, 13 Jun 2016 11:29:07 +0200 (CEST) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga103.jf.intel.com with ESMTP; 13 Jun 2016 02:29:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.26,466,1459839600"; d="scan'208";a="826889579" Received: from yliu-dev.sh.intel.com (HELO yliu-dev) ([10.239.67.162]) by orsmga003.jf.intel.com with ESMTP; 13 Jun 2016 02:29:05 -0700 Date: Mon, 13 Jun 2016 17:31:04 +0800 From: Yuanhan Liu To: "Tan, Jianfeng" Cc: "dev@dpdk.org" , "Xie, Huawei" Message-ID: <20160613093104.GO10038@yliu-dev.sh.intel.com> References: <1465725945-95964-1-git-send-email-jianfeng.tan@intel.com> <20160613085749.GM10038@yliu-dev.sh.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Subject: Re: [dpdk-dev] [PATCH] virito: fix reuse index in nested loop 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: Mon, 13 Jun 2016 09:29:08 -0000 On Mon, Jun 13, 2016 at 09:11:57AM +0000, Tan, Jianfeng wrote: > > > > -----Original Message----- > > From: Yuanhan Liu [mailto:yuanhan.liu@linux.intel.com] > > Sent: Monday, June 13, 2016 4:58 PM > > To: Tan, Jianfeng > > Cc: dev@dpdk.org; Xie, Huawei > > Subject: Re: [PATCH] virito: fix reuse index in nested loop > > > > On Sun, Jun 12, 2016 at 10:05:45AM +0000, Jianfeng Tan wrote: > > > This patches fixes problem of reusing index of outmost loop in nested > > > loops. This bug will lead to failure when starting a multi queue > > > virtio device: rx queues (except from the first one) cannot be started, > > > expecially their vq_ring cannot be initialized, so that when invoking > > > rx func on these queues, segment fault happens. > > > > > > Fixes: a900472aedef ("virtio: split virtio Rx/Tx queue") > > > > Good catch! > > > > > Signed-off-by: Jianfeng Tan > > > --- > > > drivers/net/virtio/virtio_rxtx.c | 36 ++++++++++++++++++++---------------- > > > 1 file changed, 20 insertions(+), 16 deletions(-) > > > > > > diff --git a/drivers/net/virtio/virtio_rxtx.c b/drivers/net/virtio/virtio_rxtx.c > > > index 2e7205b..b96d0cb 100644 > > > --- a/drivers/net/virtio/virtio_rxtx.c > > > +++ b/drivers/net/virtio/virtio_rxtx.c > > > @@ -331,7 +331,7 @@ virtio_dev_rxtx_start(struct rte_eth_dev *dev) > > > * - Allocate blank mbufs for the each rx descriptor > > > * > > > */ > > > - int i; > > > + int i, j; > > > > However, I don't quite like using "i, j, k" stuff. So, how about > > renaming "j" to "ring_idx"? > > > > > PMD_INIT_FUNC_TRACE(); > > > > > > @@ -352,15 +352,18 @@ virtio_dev_rxtx_start(struct rte_eth_dev *dev) > > > error = ENOSPC; > > > > > > #ifdef RTE_MACHINE_CPUFLAG_SSSE3 > > > - if (use_simple_rxtx) > > > - for (i = 0; i < vq->vq_nentries; i++) { > > > - vq->vq_ring.avail->ring[i] = i; > > > - vq->vq_ring.desc[i].flags = > > VRING_DESC_F_WRITE; > > > + if (use_simple_rxtx) { > > > + uint16_t k; > > > > We could reuse "ring_idx" here; no need to define yet another iterate var > > for that. > > Make sense. Besides, since comparison between unsigned and signed is a violation to static code analyzer, I'll redefine these variables as unsigned. > Such as, > int i -> uint16_t q_idx > int j -> uint16_t r_idx > k -> r_idx It's nothing big deal, but if I were you, I would keep the var name "i" unchanged (yes, we need define it to uint16_t), and introduce "ring_idx" but not "r_idx": I will not sacrifice the readability by saving few typings. --yliu