vfio/helpers: Make vfio_device_get_name() return bool

This is to follow the coding standand in qapi/error.h to return bool
for bool-valued functions.

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-22 12:40:00 +08:00 committed by Cédric Le Goater
parent 84e37d0296
commit c6c6cf91c0
6 changed files with 10 additions and 11 deletions

View File

@ -158,7 +158,7 @@ static void vfio_ap_realize(DeviceState *dev, Error **errp)
VFIOAPDevice *vapdev = VFIO_AP_DEVICE(dev); VFIOAPDevice *vapdev = VFIO_AP_DEVICE(dev);
VFIODevice *vbasedev = &vapdev->vdev; VFIODevice *vbasedev = &vapdev->vdev;
if (vfio_device_get_name(vbasedev, errp) < 0) { if (!vfio_device_get_name(vbasedev, errp)) {
return; return;
} }

View File

@ -588,7 +588,7 @@ static void vfio_ccw_realize(DeviceState *dev, Error **errp)
} }
} }
if (vfio_device_get_name(vbasedev, errp) < 0) { if (!vfio_device_get_name(vbasedev, errp)) {
return; return;
} }

View File

@ -607,7 +607,7 @@ bool vfio_has_region_cap(VFIODevice *vbasedev, int region, uint16_t cap_type)
return ret; return ret;
} }
int vfio_device_get_name(VFIODevice *vbasedev, Error **errp) bool vfio_device_get_name(VFIODevice *vbasedev, Error **errp)
{ {
ERRP_GUARD(); ERRP_GUARD();
struct stat st; struct stat st;
@ -616,7 +616,7 @@ int vfio_device_get_name(VFIODevice *vbasedev, Error **errp)
if (stat(vbasedev->sysfsdev, &st) < 0) { if (stat(vbasedev->sysfsdev, &st) < 0) {
error_setg_errno(errp, errno, "no such host device"); error_setg_errno(errp, errno, "no such host device");
error_prepend(errp, VFIO_MSG_PREFIX, vbasedev->sysfsdev); error_prepend(errp, VFIO_MSG_PREFIX, vbasedev->sysfsdev);
return -errno; return false;
} }
/* User may specify a name, e.g: VFIO platform device */ /* User may specify a name, e.g: VFIO platform device */
if (!vbasedev->name) { if (!vbasedev->name) {
@ -625,7 +625,7 @@ int vfio_device_get_name(VFIODevice *vbasedev, Error **errp)
} else { } else {
if (!vbasedev->iommufd) { if (!vbasedev->iommufd) {
error_setg(errp, "Use FD passing only with iommufd backend"); error_setg(errp, "Use FD passing only with iommufd backend");
return -EINVAL; return false;
} }
/* /*
* Give a name with fd so any function printing out vbasedev->name * Give a name with fd so any function printing out vbasedev->name
@ -636,7 +636,7 @@ int vfio_device_get_name(VFIODevice *vbasedev, Error **errp)
} }
} }
return 0; return true;
} }
void vfio_device_set_fd(VFIODevice *vbasedev, const char *str, Error **errp) void vfio_device_set_fd(VFIODevice *vbasedev, const char *str, Error **errp)

View File

@ -2999,7 +2999,7 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
vdev->host.slot, vdev->host.function); vdev->host.slot, vdev->host.function);
} }
if (vfio_device_get_name(vbasedev, errp) < 0) { if (!vfio_device_get_name(vbasedev, errp)) {
return; return;
} }

View File

@ -545,9 +545,8 @@ static int vfio_base_device_init(VFIODevice *vbasedev, Error **errp)
vbasedev->name); vbasedev->name);
} }
ret = vfio_device_get_name(vbasedev, errp); if (!vfio_device_get_name(vbasedev, errp)) {
if (ret) { return -EINVAL;
return ret;
} }
if (!vfio_attach_device(vbasedev->name, vbasedev, if (!vfio_attach_device(vbasedev->name, vbasedev,

View File

@ -279,7 +279,7 @@ int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t iova,
uint64_t size, ram_addr_t ram_addr, Error **errp); uint64_t size, ram_addr_t ram_addr, Error **errp);
/* Returns 0 on success, or a negative errno. */ /* Returns 0 on success, or a negative errno. */
int vfio_device_get_name(VFIODevice *vbasedev, Error **errp); bool vfio_device_get_name(VFIODevice *vbasedev, Error **errp);
void vfio_device_set_fd(VFIODevice *vbasedev, const char *str, Error **errp); void vfio_device_set_fd(VFIODevice *vbasedev, const char *str, Error **errp);
void vfio_device_init(VFIODevice *vbasedev, int type, VFIODeviceOps *ops, void vfio_device_init(VFIODevice *vbasedev, int type, VFIODeviceOps *ops,
DeviceState *dev, bool ram_discard); DeviceState *dev, bool ram_discard);