[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251113115558.1277981-5-eperezma@redhat.com>
Date: Thu, 13 Nov 2025 12:55:56 +0100
From: Eugenio Pérez <eperezma@...hat.com>
To: "Michael S . Tsirkin " <mst@...hat.com>
Cc: Laurent Vivier <lvivier@...hat.com>,
virtualization@...ts.linux.dev,
Maxime Coquelin <mcoqueli@...hat.com>,
Cindy Lu <lulu@...hat.com>,
jasowang@...hat.com,
linux-kernel@...r.kernel.org,
Eugenio Pérez <eperezma@...hat.com>,
Yongji Xie <xieyongji@...edance.com>,
Xuan Zhuo <xuanzhuo@...ux.alibaba.com>,
Stefano Garzarella <sgarzare@...hat.com>
Subject: [PATCH v9 4/6] vduse: refactor vdpa_dev_add for goto err handling
Next patches introduce more error paths in this function. Refactor it
so they can be accomodated through gotos.
Acked-by: Jason Wang <jasowang@...hat.com>
Reviewed-by: Xie Yongji <xieyongji@...edance.com>
Signed-off-by: Eugenio Pérez <eperezma@...hat.com>
---
v6: New in v6.
---
drivers/vdpa/vdpa_user/vduse_dev.c | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c
index b01f55a1c22d..97be04f73fbf 100644
--- a/drivers/vdpa/vdpa_user/vduse_dev.c
+++ b/drivers/vdpa/vdpa_user/vduse_dev.c
@@ -2172,21 +2172,27 @@ static int vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
dev->bounce_size);
mutex_unlock(&dev->domain_lock);
if (!dev->domain) {
- put_device(&dev->vdev->vdpa.dev);
- return -ENOMEM;
+ ret = -ENOMEM;
+ goto domain_err;
}
ret = _vdpa_register_device(&dev->vdev->vdpa, dev->vq_num);
if (ret) {
- put_device(&dev->vdev->vdpa.dev);
- mutex_lock(&dev->domain_lock);
- vduse_domain_destroy(dev->domain);
- dev->domain = NULL;
- mutex_unlock(&dev->domain_lock);
- return ret;
+ goto register_err;
}
return 0;
+
+register_err:
+ mutex_lock(&dev->domain_lock);
+ vduse_domain_destroy(dev->domain);
+ dev->domain = NULL;
+ mutex_unlock(&dev->domain_lock);
+
+domain_err:
+ put_device(&dev->vdev->vdpa.dev);
+
+ return ret;
}
static void vdpa_dev_del(struct vdpa_mgmt_dev *mdev, struct vdpa_device *dev)
--
2.51.1
Powered by blists - more mailing lists