Skip to content

Commit 3e2ddda

Browse files
eugpermarmstsirkin
authored andcommitted
vduse: refactor vdpa_dev_add for goto err handling
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>
1 parent 3543b04 commit 3e2ddda

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

drivers/vdpa/vdpa_user/vduse_dev.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2171,21 +2171,27 @@ static int vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
21712171
dev->bounce_size);
21722172
mutex_unlock(&dev->domain_lock);
21732173
if (!dev->domain) {
2174-
put_device(&dev->vdev->vdpa.dev);
2175-
return -ENOMEM;
2174+
ret = -ENOMEM;
2175+
goto domain_err;
21762176
}
21772177

21782178
ret = _vdpa_register_device(&dev->vdev->vdpa, dev->vq_num);
21792179
if (ret) {
2180-
put_device(&dev->vdev->vdpa.dev);
2181-
mutex_lock(&dev->domain_lock);
2182-
vduse_domain_destroy(dev->domain);
2183-
dev->domain = NULL;
2184-
mutex_unlock(&dev->domain_lock);
2185-
return ret;
2180+
goto register_err;
21862181
}
21872182

21882183
return 0;
2184+
2185+
register_err:
2186+
mutex_lock(&dev->domain_lock);
2187+
vduse_domain_destroy(dev->domain);
2188+
dev->domain = NULL;
2189+
mutex_unlock(&dev->domain_lock);
2190+
2191+
domain_err:
2192+
put_device(&dev->vdev->vdpa.dev);
2193+
2194+
return ret;
21892195
}
21902196

21912197
static void vdpa_dev_del(struct vdpa_mgmt_dev *mdev, struct vdpa_device *dev)

0 commit comments

Comments
 (0)