From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <jianfeng.tan@intel.com>
Received: from mga02.intel.com (mga02.intel.com [134.134.136.20])
 by dpdk.org (Postfix) with ESMTP id 26AE911DE
 for <dev@dpdk.org>; Mon,  8 Aug 2016 03:07:56 +0200 (CEST)
Received: from fmsmga003.fm.intel.com ([10.253.24.29])
 by orsmga101.jf.intel.com with ESMTP; 07 Aug 2016 18:07:55 -0700
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.28,487,1464678000"; d="scan'208";a="745537602"
Received: from fmsmsx105.amr.corp.intel.com ([10.18.124.203])
 by FMSMGA003.fm.intel.com with ESMTP; 07 Aug 2016 18:07:54 -0700
Received: from fmsmsx116.amr.corp.intel.com (10.18.116.20) by
 FMSMSX105.amr.corp.intel.com (10.18.124.203) with Microsoft SMTP Server (TLS)
 id 14.3.248.2; Sun, 7 Aug 2016 18:07:54 -0700
Received: from shsmsx104.ccr.corp.intel.com (10.239.4.70) by
 fmsmsx116.amr.corp.intel.com (10.18.116.20) with Microsoft SMTP Server (TLS)
 id 14.3.248.2; Sun, 7 Aug 2016 18:07:54 -0700
Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.181]) by
 SHSMSX104.ccr.corp.intel.com ([169.254.5.116]) with mapi id 14.03.0248.002;
 Mon, 8 Aug 2016 09:07:52 +0800
From: "Tan, Jianfeng" <jianfeng.tan@intel.com>
To: Stephen Hemminger <stephen@networkplumber.org>
CC: "dev@dpdk.org" <dev@dpdk.org>, "yuanhan.liu@linux.intel.com"
 <yuanhan.liu@linux.intel.com>, "Wang, Zhihong" <zhihong.wang@intel.com>,
 "lining18@jd.com" <lining18@jd.com>
Thread-Topic: [dpdk-dev] [PATCH 3/3] net/virtio_user: fix dev not freed
 after init error
Thread-Index: AQHR7w22KlIV0gPL4U2bWVmoIgokb6A6Ci6AgAQ4q6A=
Date: Mon, 8 Aug 2016 01:07:52 +0000
Message-ID: <ED26CBA2FAD1BF48A8719AEF02201E3610631666@SHSMSX103.ccr.corp.intel.com>
References: <1470397003-5782-1-git-send-email-jianfeng.tan@intel.com>
 <1470397003-5782-4-git-send-email-jianfeng.tan@intel.com>
 <20160805093413.431ba323@xeon-e3>
In-Reply-To: <20160805093413.431ba323@xeon-e3>
Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
x-originating-ip: [10.239.127.40]
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0
Subject: Re: [dpdk-dev] [PATCH 3/3] net/virtio_user: fix dev not freed after
 init error
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: patches and discussions about DPDK <dev.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Mon, 08 Aug 2016 01:07:56 -0000

Hi Stephen,

> -----Original Message-----
> From: Stephen Hemminger [mailto:stephen@networkplumber.org]
> Sent: Saturday, August 6, 2016 12:34 AM
> To: Tan, Jianfeng
> Cc: dev@dpdk.org; yuanhan.liu@linux.intel.com; Wang, Zhihong;
> lining18@jd.com
> Subject: Re: [dpdk-dev] [PATCH 3/3] net/virtio_user: fix dev not freed af=
ter
> init error
>=20
> On Fri,  5 Aug 2016 11:36:43 +0000
> Jianfeng Tan <jianfeng.tan@intel.com> wrote:
>=20
> > diff --git a/drivers/net/virtio/virtio_user_ethdev.c
> b/drivers/net/virtio/virtio_user_ethdev.c
> > index daef09b..62ccb0b 100644
> > --- a/drivers/net/virtio/virtio_user_ethdev.c
> > +++ b/drivers/net/virtio/virtio_user_ethdev.c
> > @@ -313,6 +313,17 @@ virtio_user_eth_dev_alloc(const char *name)
> >  	return eth_dev;
> >  }
> >
> > +static void
> > +virtio_user_eth_dev_free(struct rte_eth_dev *eth_dev)
> > +{
> > +	struct rte_eth_dev_data *data =3D eth_dev->data;
> > +	struct virtio_hw *hw =3D data->dev_private;
> > +
> > +	rte_free(hw->virtio_user_dev);
> > +	rte_free(hw);
> > +	rte_eth_dev_release_port(eth_dev);
> > +}
> > +
> >  /* Dev initialization routine. Invoked once for each virtio vdev at
> >   * EAL init time, see rte_eal_dev_init().
> >   * Returns 0 on success.
> > @@ -328,7 +339,7 @@ virtio_user_pmd_devinit(const char *name, const
> char *params)
> >  	uint64_t queue_size =3D VIRTIO_USER_DEF_Q_SZ;
> >  	char *path =3D NULL;
> >  	char *mac_addr =3D NULL;
> > -	int ret =3D -1;
> > +	int result =3D -1, ret;
>=20
> It is not clear why two return value variables are needed?

My purpose was to make "ret" to record the return value of intermediate fun=
ctions, and "result" to record that of current method. Any convention to do=
 that?

If it introduces confusions, I'll change to use only one return value varia=
bles.


> >
> >  	if (!params || params[0] =3D=3D '\0') {
> >  		PMD_INIT_LOG(ERR, "arg %s is mandatory for virtio_user",
> > @@ -411,15 +422,19 @@ virtio_user_pmd_devinit(const char *name,
> const char *params)
> >
> >  	hw =3D eth_dev->data->dev_private;
> >  	if (virtio_user_dev_init(hw->virtio_user_dev, path, queues, cq,
> > -				 queue_size, mac_addr) < 0)
> > +				 queue_size, mac_addr) < 0) {
> > +		PMD_INIT_LOG(ERR, "virtio_user_dev_init fails");
> > +		virtio_user_eth_dev_free(eth_dev);
> >  		goto end;
> > +	}
> >
> >  	/* previously called by rte_eal_pci_probe() for physical dev */
> >  	if (eth_virtio_dev_init(eth_dev) < 0) {
> >  		PMD_INIT_LOG(ERR, "eth_virtio_dev_init fails");
> > +		virtio_user_eth_dev_free(eth_dev);
> >  		goto end;
> >  	}
> > -	ret =3D 0;
> > +	result =3D 0;
> >
> >  end:
> >  	if (kvlist)
> > @@ -428,7 +443,7 @@ end:
> >  		free(path);
> >  	if (mac_addr)
> >  		free(mac_addr);
>=20
> Unrelated, but this code could eliminate those if () tests.

Thanks for the hint. Yes, as manual says, "If ptr is NULL, no operation is =
performed". "if"s can be eliminated.

Thanks,
Jianfeng

>=20
> > -	return ret;
> > +	return result;
> >  }