[dpdk-dev,3/4] virtio: return 1 to tell the upper layer we don't take over this device
Commit Message
if virtio_resource_init fails, cleanup the resource and return 1 to
tell the upper layer we don't take over this device.
return -1 means error and DPDK will exit.
Signed-off-by: Huawei Xie <huawei.xie@intel.com>
---
drivers/net/virtio/virtio_ethdev.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
Comments
On Fri, Dec 25, 2015 at 02:38:11AM +0800, Huawei Xie wrote:
> if virtio_resource_init fails, cleanup the resource and return 1 to
> tell the upper layer we don't take over this device.
> return -1 means error and DPDK will exit.
>
> Signed-off-by: Huawei Xie <huawei.xie@intel.com>
> ---
> drivers/net/virtio/virtio_ethdev.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
> index d928339..00015ef 100644
> --- a/drivers/net/virtio/virtio_ethdev.c
> +++ b/drivers/net/virtio/virtio_ethdev.c
> @@ -1287,8 +1287,12 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
>
> pci_dev = eth_dev->pci_dev;
>
> - if (virtio_resource_init(pci_dev) < 0)
> - return -1;
> + /* Return 1 to tell the upper layer we don't take over this device. */
> + if (virtio_resource_init(pci_dev) < 0) {
> + rte_free(eth_dev->data->mac_addrs);
> + eth_dev->data->mac_addrs = NULL;
This assignment looks unnecessary to me.
And, I think above comment is better to put here, right above the return
statement.
> + return 1;
> + }
--yliu
> -----Original Message-----
> From: Yuanhan Liu [mailto:yuanhan.liu@linux.intel.com]
> Sent: Monday, December 28, 2015 1:25 PM
> To: Xie, Huawei
> Cc: dev@dpdk.org; Jayakumar, Muthurajan; Troitsky, Nikita;
> peterx@redhat.com; stephen@networkplumber.org;
> Changchun.ouyang@hotmail.com; thomas.monjalon@6wind.com
> Subject: Re: [PATCH 3/4] virtio: return 1 to tell the upper layer we
> don't take over this device
>
> On Fri, Dec 25, 2015 at 02:38:11AM +0800, Huawei Xie wrote:
> > if virtio_resource_init fails, cleanup the resource and return 1 to
> > tell the upper layer we don't take over this device.
> > return -1 means error and DPDK will exit.
> >
> > Signed-off-by: Huawei Xie <huawei.xie@intel.com>
> > ---
> > drivers/net/virtio/virtio_ethdev.c | 8 ++++++--
> > 1 file changed, 6 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/net/virtio/virtio_ethdev.c
> b/drivers/net/virtio/virtio_ethdev.c
> > index d928339..00015ef 100644
> > --- a/drivers/net/virtio/virtio_ethdev.c
> > +++ b/drivers/net/virtio/virtio_ethdev.c
> > @@ -1287,8 +1287,12 @@ eth_virtio_dev_init(struct rte_eth_dev
> *eth_dev)
> >
> > pci_dev = eth_dev->pci_dev;
> >
> > - if (virtio_resource_init(pci_dev) < 0)
> > - return -1;
> > + /* Return 1 to tell the upper layer we don't take over this
> device. */
> > + if (virtio_resource_init(pci_dev) < 0) {
> > + rte_free(eth_dev->data->mac_addrs);
> > + eth_dev->data->mac_addrs = NULL;
>
> This assignment looks unnecessary to me.
>
Noted this when write this code. It is ok not to reset as this layer is responsible for all the allocation/free.
>
> And, I think above comment is better to put here, right above the
> return
> statement.
>
> > + return 1;
> > + }
>
> --yliu
@@ -1287,8 +1287,12 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
pci_dev = eth_dev->pci_dev;
- if (virtio_resource_init(pci_dev) < 0)
- return -1;
+ /* Return 1 to tell the upper layer we don't take over this device. */
+ if (virtio_resource_init(pci_dev) < 0) {
+ rte_free(eth_dev->data->mac_addrs);
+ eth_dev->data->mac_addrs = NULL;
+ return 1;
+ }
hw->use_msix = virtio_has_msix(&pci_dev->addr);
hw->io_base = (uint32_t)(uintptr_t)pci_dev->mem_resource[0].addr;