Skip to content

Commit 2a3b9cb

Browse files
efarmancohuck
authored andcommitted
vfio-ccw: Refactor cleanup of regions
While we're at it, add a g_free() for the async_cmd_region that is the last thing currently created. g_free() knows how to handle NULL pointers, so this makes it easier to remember what cleanups need to be performed when new regions are added. Signed-off-by: Eric Farman <[email protected]> Reviewed-by: Cornelia Huck <[email protected]> Message-Id: <[email protected]> Signed-off-by: Cornelia Huck <[email protected]>
1 parent f76b348 commit 2a3b9cb

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

hw/vfio/ccw.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,7 @@ static void vfio_ccw_get_region(VFIOCCWDevice *vcdev, Error **errp)
363363
vcdev->io_region_size = info->size;
364364
if (sizeof(*vcdev->io_region) != vcdev->io_region_size) {
365365
error_setg(errp, "vfio: Unexpected size of the I/O region");
366-
g_free(info);
367-
return;
366+
goto out_err;
368367
}
369368

370369
vcdev->io_region_offset = info->offset;
@@ -377,15 +376,20 @@ static void vfio_ccw_get_region(VFIOCCWDevice *vcdev, Error **errp)
377376
vcdev->async_cmd_region_size = info->size;
378377
if (sizeof(*vcdev->async_cmd_region) != vcdev->async_cmd_region_size) {
379378
error_setg(errp, "vfio: Unexpected size of the async cmd region");
380-
g_free(vcdev->io_region);
381-
g_free(info);
382-
return;
379+
goto out_err;
383380
}
384381
vcdev->async_cmd_region_offset = info->offset;
385382
vcdev->async_cmd_region = g_malloc0(info->size);
386383
}
387384

388385
g_free(info);
386+
return;
387+
388+
out_err:
389+
g_free(vcdev->async_cmd_region);
390+
g_free(vcdev->io_region);
391+
g_free(info);
392+
return;
389393
}
390394

391395
static void vfio_ccw_put_region(VFIOCCWDevice *vcdev)

0 commit comments

Comments
 (0)