]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
vduse: refactor vdpa_dev_add for goto err handling
authorEugenio Pérez <eperezma@redhat.com>
Mon, 19 Jan 2026 14:33:00 +0000 (15:33 +0100)
committerMichael S. Tsirkin <mst@redhat.com>
Wed, 28 Jan 2026 20:32:17 +0000 (15:32 -0500)
Next patches introduce more error paths in this function.  Refactor it
so they can be accommodated through gotos.

Acked-by: Jason Wang <jasowang@redhat.com>
Reviewed-by: Xie Yongji <xieyongji@bytedance.com>
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Message-Id: <20260119143306.1818855-8-eperezma@redhat.com>

drivers/vdpa/vdpa_user/vduse_dev.c

index 68290c3d9d8fe914ef54aa8c9ef62b552b551cc1..43851b0711ac2c73463f880061869efe220d8d60 100644 (file)
@@ -2171,21 +2171,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)