[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 39/47] vfio/pci: Make vfio_populate_device() return a bool
From: |
Cédric Le Goater |
Subject: |
[PULL 39/47] vfio/pci: Make vfio_populate_device() return a bool |
Date: |
Wed, 22 May 2024 11:54:34 +0200 |
From: Zhenzhong Duan <zhenzhong.duan@intel.com>
Since vfio_populate_device() takes an 'Error **' argument,
best practices suggest to return a bool. See the qapi/error.h
Rules section.
By this chance, pass errp directly to vfio_populate_device() to
avoid calling error_propagate().
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>
---
hw/vfio/pci.c | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index
4fb5fd0c9f61627c402164fc4bed1868540350e0..46d3c618596d95266543e9a0ebc65c04d9a7cc5d
100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -2740,7 +2740,7 @@ int vfio_populate_vga(VFIOPCIDevice *vdev, Error **errp)
return 0;
}
-static void vfio_populate_device(VFIOPCIDevice *vdev, Error **errp)
+static bool vfio_populate_device(VFIOPCIDevice *vdev, Error **errp)
{
VFIODevice *vbasedev = &vdev->vbasedev;
struct vfio_region_info *reg_info;
@@ -2750,18 +2750,18 @@ static void vfio_populate_device(VFIOPCIDevice *vdev,
Error **errp)
/* Sanity check device */
if (!(vbasedev->flags & VFIO_DEVICE_FLAGS_PCI)) {
error_setg(errp, "this isn't a PCI device");
- return;
+ return false;
}
if (vbasedev->num_regions < VFIO_PCI_CONFIG_REGION_INDEX + 1) {
error_setg(errp, "unexpected number of io regions %u",
vbasedev->num_regions);
- return;
+ return false;
}
if (vbasedev->num_irqs < VFIO_PCI_MSIX_IRQ_INDEX + 1) {
error_setg(errp, "unexpected number of irqs %u", vbasedev->num_irqs);
- return;
+ return false;
}
for (i = VFIO_PCI_BAR0_REGION_INDEX; i < VFIO_PCI_ROM_REGION_INDEX; i++) {
@@ -2773,7 +2773,7 @@ static void vfio_populate_device(VFIOPCIDevice *vdev,
Error **errp)
if (ret) {
error_setg_errno(errp, -ret, "failed to get region %d info", i);
- return;
+ return false;
}
QLIST_INIT(&vdev->bars[i].quirks);
@@ -2783,7 +2783,7 @@ static void vfio_populate_device(VFIOPCIDevice *vdev,
Error **errp)
VFIO_PCI_CONFIG_REGION_INDEX, ®_info);
if (ret) {
error_setg_errno(errp, -ret, "failed to get config info");
- return;
+ return false;
}
trace_vfio_populate_device_config(vdev->vbasedev.name,
@@ -2804,7 +2804,7 @@ static void vfio_populate_device(VFIOPCIDevice *vdev,
Error **errp)
if (ret) {
error_append_hint(errp, "device does not support "
"requested feature x-vga\n");
- return;
+ return false;
}
}
@@ -2821,6 +2821,8 @@ static void vfio_populate_device(VFIOPCIDevice *vdev,
Error **errp)
"Could not enable error recovery for the device",
vbasedev->name);
}
+
+ return true;
}
static void vfio_pci_put_device(VFIOPCIDevice *vdev)
@@ -2977,7 +2979,6 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
VFIOPCIDevice *vdev = VFIO_PCI(pdev);
VFIODevice *vbasedev = &vdev->vbasedev;
char *subsys;
- Error *err = NULL;
int i, ret;
bool is_mdev;
char uuid[UUID_STR_LEN];
@@ -3036,9 +3037,7 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
goto error;
}
- vfio_populate_device(vdev, &err);
- if (err) {
- error_propagate(errp, err);
+ if (!vfio_populate_device(vdev, errp)) {
goto error;
}
--
2.45.1
- [PULL 28/47] vfio/cpr: Make vfio_cpr_register_container() return bool, (continued)
- [PULL 28/47] vfio/cpr: Make vfio_cpr_register_container() return bool, Cédric Le Goater, 2024/05/22
- [PULL 29/47] backends/iommufd: Make iommufd_backend_*() return bool, Cédric Le Goater, 2024/05/22
- [PULL 17/47] vfio/migration: Don't emit STOP_COPY VFIO migration QAPI event twice, Cédric Le Goater, 2024/05/22
- [PULL 38/47] vfio/pci: Make vfio_pci_relocate_msix() and vfio_msix_early_setup() return a bool, Cédric Le Goater, 2024/05/22
- [PULL 34/47] vfio/helpers: Make vfio_device_get_name() return bool, Cédric Le Goater, 2024/05/22
- [PULL 36/47] vfio/ccw: Make vfio_ccw_get_region() return a bool, Cédric Le Goater, 2024/05/22
- [PULL 26/47] vfio/container: Make vfio_get_device() return bool, Cédric Le Goater, 2024/05/22
- [PULL 27/47] vfio/iommufd: Make iommufd_cdev_*() return bool, Cédric Le Goater, 2024/05/22
- [PULL 33/47] vfio/helpers: Make vfio_set_irq_signaling() return bool, Cédric Le Goater, 2024/05/22
- [PULL 37/47] vfio/pci: Make vfio_intx_enable_kvm() return a bool, Cédric Le Goater, 2024/05/22
- [PULL 39/47] vfio/pci: Make vfio_populate_device() return a bool,
Cédric Le Goater <=
- [PULL 42/47] vfio/pci: Make capability related functions return bool, Cédric Le Goater, 2024/05/22
- [PULL 41/47] vfio/pci: Make vfio_populate_vga() return bool, Cédric Le Goater, 2024/05/22
- [PULL 40/47] vfio/pci: Make vfio_intx_enable() return bool, Cédric Le Goater, 2024/05/22
- [PULL 35/47] vfio/platform: Make vfio_populate_device() and vfio_base_device_init() return bool, Cédric Le Goater, 2024/05/22
- [PULL 45/47] vfio/pci-quirks: Make vfio_add_*_cap() return bool, Cédric Le Goater, 2024/05/22
- [PULL 43/47] vfio/pci: Use g_autofree for vfio_region_info pointer, Cédric Le Goater, 2024/05/22
- [PULL 44/47] vfio/pci-quirks: Make vfio_pci_igd_opregion_init() return bool, Cédric Le Goater, 2024/05/22
- [PULL 47/47] vfio/igd: Use g_autofree in vfio_probe_igd_bar4_quirk(), Cédric Le Goater, 2024/05/22
- [PULL 46/47] vfio: Use g_autofree in all call site of vfio_get_region_info(), Cédric Le Goater, 2024/05/22
- Re: [PULL 00/47] vfio queue, Richard Henderson, 2024/05/22