From: Cédric Le Goater Date: Mon, 17 Jun 2024 06:34:01 +0000 (+0200) Subject: vfio/container: Introduce vfio_create_container() X-Git-Tag: qemu-xen-4.20.0~100^2~8 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=58f5c13260c2bf8fe158d0e176d1595858157946;p=qemu-xen.git vfio/container: Introduce vfio_create_container() This routine allocates the QEMU struct type representing the VFIO container. It is minimal currently and future changes will do more initialization. Reviewed-by: Zhenzhong Duan Reviewed-by: Eric Auger Tested-by: Eric Auger Signed-off-by: Cédric Le Goater --- diff --git a/hw/vfio/container.c b/hw/vfio/container.c index bb6abe60ee..a869194279 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -430,6 +430,16 @@ static bool vfio_set_iommu(VFIOContainer *container, int group_fd, return true; } +static VFIOContainer *vfio_create_container(int fd, VFIOGroup *group, + Error **errp) +{ + VFIOContainer *container; + + container = g_malloc0(sizeof(*container)); + container->fd = fd; + return container; +} + static int vfio_get_iommu_info(VFIOContainer *container, struct vfio_iommu_type1_info **info) { @@ -604,13 +614,14 @@ static bool vfio_connect_container(VFIOGroup *group, AddressSpace *as, goto close_fd_exit; } - container = g_malloc0(sizeof(*container)); - container->fd = fd; - bcontainer = &container->bcontainer; - + container = vfio_create_container(fd, group, errp); + if (!container) { + goto close_fd_exit; + } if (!vfio_set_iommu(container, group->fd, errp)) { goto free_container_exit; } + bcontainer = &container->bcontainer; if (!vfio_cpr_register_container(bcontainer, errp)) { goto free_container_exit;