Migration struct is a common data structure. Memory allocation of migration struct is not unique to In-Band approach. So, move it from vfio_migration_init() to vfio_migration_probe().
Signed-off-by: Lei Rao <lei....@intel.com> --- hw/vfio/migration.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index 770f535e81..11ce87bb1a 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -807,17 +807,15 @@ static int vfio_migration_init(VFIODevice *vbasedev, { int ret; Object *obj; - VFIOMigration *migration; char id[256] = ""; g_autofree char *path = NULL, *oid = NULL; + VFIOMigration *migration = vbasedev->migration; obj = vbasedev->ops->vfio_get_object(vbasedev); if (!obj) { return -EINVAL; } - vbasedev->migration = g_new0(VFIOMigration, 1); - ret = vfio_region_setup(obj, vbasedev, &vbasedev->migration->region, info->index, "migration"); if (ret) { @@ -833,9 +831,6 @@ static int vfio_migration_init(VFIODevice *vbasedev, goto err; } - migration = vbasedev->migration; - migration->vbasedev = vbasedev; - oid = vmstate_if_get_id(VMSTATE_IF(DEVICE(obj))); if (oid) { path = g_strdup_printf("%s/vfio", oid); @@ -876,6 +871,9 @@ int vfio_migration_probe(VFIODevice *vbasedev, Error **errp) goto add_blocker; } + vbasedev->migration = g_new0(VFIOMigration, 1); + vbasedev->migration->vbasedev = vbasedev; + ret = vfio_get_dev_region_info(vbasedev, VFIO_REGION_TYPE_MIGRATION_DEPRECATED, VFIO_REGION_SUBTYPE_MIGRATION_DEPRECATED, @@ -903,6 +901,8 @@ add_blocker: error_free(vbasedev->migration_blocker); vbasedev->migration_blocker = NULL; } + g_free(vbasedev->migration); + vbasedev->migration = NULL; return ret; } -- 2.32.0