[PATCH] vp_vdpa: Fix an error handling path in vp_vdpa_probe()

From: Christophe JAILLET
Date: Sun Apr 03 2022 - 03:24:05 EST


If an error occurs after a successful vp_modern_probe() call, it should be
undone by a corresponding vp_modern_remove() call, as already do in the
remove function.

Fixes: 64b9f64f80a6 ("vdpa: introduce virtio pci driver")
Signed-off-by: Christophe JAILLET <christophe.jaillet@xxxxxxxxxx>
---
This patch is completely speculative.
Review with care.
---
drivers/vdpa/virtio_pci/vp_vdpa.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/vdpa/virtio_pci/vp_vdpa.c b/drivers/vdpa/virtio_pci/vp_vdpa.c
index cce101e6a940..9b713fe0f2c7 100644
--- a/drivers/vdpa/virtio_pci/vp_vdpa.c
+++ b/drivers/vdpa/virtio_pci/vp_vdpa.c
@@ -491,7 +491,7 @@ static int vp_vdpa_probe(struct pci_dev *pdev, const struct pci_device_id *id)
if (ret) {
dev_err(&pdev->dev,
"Failed for adding devres for freeing irq vectors\n");
- goto err;
+ goto err_remove;
}

vp_vdpa->vring = devm_kcalloc(&pdev->dev, vp_vdpa->queues,
@@ -500,7 +500,7 @@ static int vp_vdpa_probe(struct pci_dev *pdev, const struct pci_device_id *id)
if (!vp_vdpa->vring) {
ret = -ENOMEM;
dev_err(&pdev->dev, "Fail to allocate virtqueues\n");
- goto err;
+ goto err_remove;
}

for (i = 0; i < vp_vdpa->queues; i++) {
@@ -511,7 +511,7 @@ static int vp_vdpa_probe(struct pci_dev *pdev, const struct pci_device_id *id)
if (!vp_vdpa->vring[i].notify) {
ret = -EINVAL;
dev_warn(&pdev->dev, "Fail to map vq notify %d\n", i);
- goto err;
+ goto err_remove;
}
}
vp_vdpa->config_irq = VIRTIO_MSI_NO_VECTOR;
@@ -519,11 +519,13 @@ static int vp_vdpa_probe(struct pci_dev *pdev, const struct pci_device_id *id)
ret = vdpa_register_device(&vp_vdpa->vdpa, vp_vdpa->queues);
if (ret) {
dev_err(&pdev->dev, "Failed to register to vdpa bus\n");
- goto err;
+ goto err_remove;
}

return 0;

+err_remove:
+ vp_modern_remove(&vp_vdpa->mdev);
err:
put_device(&vp_vdpa->vdpa.dev);
return ret;
--
2.32.0