Next patches introduce more error paths in this function.  Refactor it
so they can be accomodated through gotos.

Acked-by: Jason Wang <[email protected]>
Reviewed-by: Xie Yongji <[email protected]>
Signed-off-by: Eugenio Pérez <[email protected]>
---
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


Reply via email to