vfio/container: Make vfio_get_device() return bool

This is to follow the coding standand to return bool if 'Error **'
is used to pass error.

Suggested-by: Cédric Le Goater <clg@redhat.com>
Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
Reviewed-by: Cédric Le Goater <clg@redhat.com>
Signed-off-by: Cédric Le Goater <clg@redhat.com>
This commit is contained in:
Zhenzhong Duan 2024-05-07 14:42:49 +08:00 committed by Cédric Le Goater
parent 534ed2e472
commit be1ff306bb

View file

@ -802,8 +802,8 @@ static void vfio_put_group(VFIOGroup *group)
g_free(group); g_free(group);
} }
static int vfio_get_device(VFIOGroup *group, const char *name, static bool vfio_get_device(VFIOGroup *group, const char *name,
VFIODevice *vbasedev, Error **errp) VFIODevice *vbasedev, Error **errp)
{ {
g_autofree struct vfio_device_info *info = NULL; g_autofree struct vfio_device_info *info = NULL;
int fd; int fd;
@ -815,14 +815,14 @@ static int vfio_get_device(VFIOGroup *group, const char *name,
error_append_hint(errp, error_append_hint(errp,
"Verify all devices in group %d are bound to vfio-<bus> " "Verify all devices in group %d are bound to vfio-<bus> "
"or pci-stub and not already in use\n", group->groupid); "or pci-stub and not already in use\n", group->groupid);
return fd; return false;
} }
info = vfio_get_device_info(fd); info = vfio_get_device_info(fd);
if (!info) { if (!info) {
error_setg_errno(errp, errno, "error getting device info"); error_setg_errno(errp, errno, "error getting device info");
close(fd); close(fd);
return -1; return false;
} }
/* /*
@ -837,7 +837,7 @@ static int vfio_get_device(VFIOGroup *group, const char *name,
error_setg(errp, "Inconsistent setting of support for discarding " error_setg(errp, "Inconsistent setting of support for discarding "
"RAM (e.g., balloon) within group"); "RAM (e.g., balloon) within group");
close(fd); close(fd);
return -1; return false;
} }
if (!group->ram_block_discard_allowed) { if (!group->ram_block_discard_allowed) {
@ -858,7 +858,7 @@ static int vfio_get_device(VFIOGroup *group, const char *name,
vbasedev->reset_works = !!(info->flags & VFIO_DEVICE_FLAGS_RESET); vbasedev->reset_works = !!(info->flags & VFIO_DEVICE_FLAGS_RESET);
return 0; return true;
} }
static void vfio_put_base_device(VFIODevice *vbasedev) static void vfio_put_base_device(VFIODevice *vbasedev)
@ -911,7 +911,6 @@ static bool vfio_legacy_attach_device(const char *name, VFIODevice *vbasedev,
VFIODevice *vbasedev_iter; VFIODevice *vbasedev_iter;
VFIOGroup *group; VFIOGroup *group;
VFIOContainerBase *bcontainer; VFIOContainerBase *bcontainer;
int ret;
if (groupid < 0) { if (groupid < 0) {
return false; return false;
@ -931,8 +930,7 @@ static bool vfio_legacy_attach_device(const char *name, VFIODevice *vbasedev,
return false; return false;
} }
} }
ret = vfio_get_device(group, name, vbasedev, errp); if (!vfio_get_device(group, name, vbasedev, errp)) {
if (ret) {
vfio_put_group(group); vfio_put_group(group);
return false; return false;
} }