[dpdk-dev] [PATCH v4 2/4] net/virtio: improve queue init error path
Xia, Chenbo
chenbo.xia at intel.com
Wed Mar 17 10:01:33 CET 2021
> -----Original Message-----
> From: Maxime Coquelin <maxime.coquelin at redhat.com>
> Sent: Tuesday, March 16, 2021 5:38 PM
> To: dev at dpdk.org; Xia, Chenbo <chenbo.xia at intel.com>; amorenoz at redhat.com;
> david.marchand at redhat.com; olivier.matz at 6wind.com; bnemeth at redhat.com
> Cc: Maxime Coquelin <maxime.coquelin at redhat.com>
> Subject: [PATCH v4 2/4] net/virtio: improve queue init error path
>
> This patch improves the error path of virtio_init_queue(),
> by cleaning in reversing order all resources that have
> been allocated.
>
> Suggested-by: Chenbo Xia <chenbo.xia at intel.com>
> Signed-off-by: Maxime Coquelin <maxime.coquelin at redhat.com>
> Reviewed-by: David Marchand <david.marchand at redhat.com>
> ---
> drivers/net/virtio/virtio_ethdev.c | 15 ++++++++++-----
> 1 file changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/net/virtio/virtio_ethdev.c
> b/drivers/net/virtio/virtio_ethdev.c
> index af090fdf9c..d5643733f7 100644
> --- a/drivers/net/virtio/virtio_ethdev.c
> +++ b/drivers/net/virtio/virtio_ethdev.c
> @@ -507,7 +507,7 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t
> queue_idx)
> mz = rte_memzone_lookup(vq_name);
> if (mz == NULL) {
> ret = -ENOMEM;
> - goto fail_q_alloc;
> + goto free_vq;
> }
> }
>
> @@ -533,7 +533,7 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t
> queue_idx)
> hdr_mz = rte_memzone_lookup(vq_hdr_name);
> if (hdr_mz == NULL) {
> ret = -ENOMEM;
> - goto fail_q_alloc;
> + goto free_mz;
> }
> }
> }
> @@ -547,7 +547,7 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t
> queue_idx)
> if (!sw_ring) {
> PMD_INIT_LOG(ERR, "can not allocate RX soft ring");
> ret = -ENOMEM;
> - goto fail_q_alloc;
> + goto free_hdr_mz;
> }
>
> vq->sw_ring = sw_ring;
> @@ -604,15 +604,20 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t
> queue_idx)
>
> if (VIRTIO_OPS(hw)->setup_queue(hw, vq) < 0) {
> PMD_INIT_LOG(ERR, "setup_queue failed");
> - return -EINVAL;
> + ret = -EINVAL;
> + goto clean_vq;
> }
>
> return 0;
>
> -fail_q_alloc:
> +clean_vq:
> + hw->cvq = NULL;
> rte_free(sw_ring);
> +free_hdr_mz:
> rte_memzone_free(hdr_mz);
> +free_mz:
> rte_memzone_free(mz);
> +free_vq:
> rte_free(vq);
>
> return ret;
> --
> 2.29.2
Reviewed-by: Chenbo Xia <chenbo.xia at intel.com>
More information about the dev
mailing list