Message ID | 20240507064252.457884-9-zhenzhong.duan@intel.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | VFIO: misc cleanups | expand |
On 5/7/24 08:42, Zhenzhong Duan wrote: > 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> Thanks, C. > --- > hw/vfio/container.c | 16 +++++++--------- > 1 file changed, 7 insertions(+), 9 deletions(-) > > diff --git a/hw/vfio/container.c b/hw/vfio/container.c > index 5fb4bee082..b02583ea16 100644 > --- a/hw/vfio/container.c > +++ b/hw/vfio/container.c > @@ -800,8 +800,8 @@ static void vfio_put_group(VFIOGroup *group) > g_free(group); > } > > -static int vfio_get_device(VFIOGroup *group, const char *name, > - VFIODevice *vbasedev, Error **errp) > +static bool vfio_get_device(VFIOGroup *group, const char *name, > + VFIODevice *vbasedev, Error **errp) > { > g_autofree struct vfio_device_info *info = NULL; > int fd; > @@ -813,14 +813,14 @@ static int vfio_get_device(VFIOGroup *group, const char *name, > error_append_hint(errp, > "Verify all devices in group %d are bound to vfio-<bus> " > "or pci-stub and not already in use\n", group->groupid); > - return fd; > + return false; > } > > info = vfio_get_device_info(fd); > if (!info) { > error_setg_errno(errp, errno, "error getting device info"); > close(fd); > - return -1; > + return false; > } > > /* > @@ -835,7 +835,7 @@ static int vfio_get_device(VFIOGroup *group, const char *name, > error_setg(errp, "Inconsistent setting of support for discarding " > "RAM (e.g., balloon) within group"); > close(fd); > - return -1; > + return false; > } > > if (!group->ram_block_discard_allowed) { > @@ -856,7 +856,7 @@ static int vfio_get_device(VFIOGroup *group, const char *name, > > vbasedev->reset_works = !!(info->flags & VFIO_DEVICE_FLAGS_RESET); > > - return 0; > + return true; > } > > static void vfio_put_base_device(VFIODevice *vbasedev) > @@ -909,7 +909,6 @@ static bool vfio_legacy_attach_device(const char *name, VFIODevice *vbasedev, > VFIODevice *vbasedev_iter; > VFIOGroup *group; > VFIOContainerBase *bcontainer; > - int ret; > > if (groupid < 0) { > return false; > @@ -929,8 +928,7 @@ static bool vfio_legacy_attach_device(const char *name, VFIODevice *vbasedev, > return false; > } > } > - ret = vfio_get_device(group, name, vbasedev, errp); > - if (ret) { > + if (!vfio_get_device(group, name, vbasedev, errp)) { > vfio_put_group(group); > return false; > }
diff --git a/hw/vfio/container.c b/hw/vfio/container.c index 5fb4bee082..b02583ea16 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -800,8 +800,8 @@ static void vfio_put_group(VFIOGroup *group) g_free(group); } -static int vfio_get_device(VFIOGroup *group, const char *name, - VFIODevice *vbasedev, Error **errp) +static bool vfio_get_device(VFIOGroup *group, const char *name, + VFIODevice *vbasedev, Error **errp) { g_autofree struct vfio_device_info *info = NULL; int fd; @@ -813,14 +813,14 @@ static int vfio_get_device(VFIOGroup *group, const char *name, error_append_hint(errp, "Verify all devices in group %d are bound to vfio-<bus> " "or pci-stub and not already in use\n", group->groupid); - return fd; + return false; } info = vfio_get_device_info(fd); if (!info) { error_setg_errno(errp, errno, "error getting device info"); close(fd); - return -1; + return false; } /* @@ -835,7 +835,7 @@ static int vfio_get_device(VFIOGroup *group, const char *name, error_setg(errp, "Inconsistent setting of support for discarding " "RAM (e.g., balloon) within group"); close(fd); - return -1; + return false; } if (!group->ram_block_discard_allowed) { @@ -856,7 +856,7 @@ static int vfio_get_device(VFIOGroup *group, const char *name, vbasedev->reset_works = !!(info->flags & VFIO_DEVICE_FLAGS_RESET); - return 0; + return true; } static void vfio_put_base_device(VFIODevice *vbasedev) @@ -909,7 +909,6 @@ static bool vfio_legacy_attach_device(const char *name, VFIODevice *vbasedev, VFIODevice *vbasedev_iter; VFIOGroup *group; VFIOContainerBase *bcontainer; - int ret; if (groupid < 0) { return false; @@ -929,8 +928,7 @@ static bool vfio_legacy_attach_device(const char *name, VFIODevice *vbasedev, return false; } } - ret = vfio_get_device(group, name, vbasedev, errp); - if (ret) { + if (!vfio_get_device(group, name, vbasedev, errp)) { vfio_put_group(group); return false; }
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> --- hw/vfio/container.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)