diff mbox

[v2,06/12] vfio/pci: Pass an error object to vfio_pci_igd_opregion_init

Message ID 1474404352-28958-7-git-send-email-eric.auger@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Eric Auger Sept. 20, 2016, 8:45 p.m. UTC
Pass an error object to prepare for migration to VFIO-PCI realize.

In vfio_probe_igd_bar4_quirk, simply report the error without
propagating.

Transform vfio_pci_igd_opregion_init into a void function. The
-EINVAL returned value only is used in vfio_initfn and during
migration to realize, this will not be used anymore.

Signed-off-by: Eric Auger <eric.auger@redhat.com>
---
 hw/vfio/pci-quirks.c | 19 +++++++++----------
 hw/vfio/pci.c        |  6 +++---
 hw/vfio/pci.h        |  5 +++--
 3 files changed, 15 insertions(+), 15 deletions(-)
diff mbox

Patch

diff --git a/hw/vfio/pci-quirks.c b/hw/vfio/pci-quirks.c
index bec694c..57921de 100644
--- a/hw/vfio/pci-quirks.c
+++ b/hw/vfio/pci-quirks.c
@@ -1055,8 +1055,8 @@  typedef struct VFIOIGDQuirk {
  * the table and to write the base address of that memory to the ASLS register
  * of the IGD device.
  */
-int vfio_pci_igd_opregion_init(VFIOPCIDevice *vdev,
-                               struct vfio_region_info *info)
+void vfio_pci_igd_opregion_init(VFIOPCIDevice *vdev,
+                               struct vfio_region_info *info, Error **errp)
 {
     int ret;
 
@@ -1064,10 +1064,10 @@  int vfio_pci_igd_opregion_init(VFIOPCIDevice *vdev,
     ret = pread(vdev->vbasedev.fd, vdev->igd_opregion,
                 info->size, info->offset);
     if (ret != info->size) {
-        error_report("vfio: Error reading IGD OpRegion");
+        error_setg(errp, "failed to read IGD OpRegion");
         g_free(vdev->igd_opregion);
         vdev->igd_opregion = NULL;
-        return -EINVAL;
+        return;
     }
 
     /*
@@ -1091,8 +1091,6 @@  int vfio_pci_igd_opregion_init(VFIOPCIDevice *vdev,
     pci_set_long(vdev->pdev.config + IGD_ASLS, 0);
     pci_set_long(vdev->pdev.wmask + IGD_ASLS, ~0);
     pci_set_long(vdev->emulated_config_bits + IGD_ASLS, ~0);
-
-    return 0;
 }
 
 /*
@@ -1363,6 +1361,7 @@  static void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr)
     uint64_t *bdsm_size;
     uint32_t gmch;
     uint16_t cmd_orig, cmd;
+    Error *err = NULL;
 
     /*
      * This must be an Intel VGA device at address 00:02.0 for us to even
@@ -1487,10 +1486,10 @@  static void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr)
     }
 
     /* Setup OpRegion access */
-    ret = vfio_pci_igd_opregion_init(vdev, opregion);
-    if (ret) {
-        error_report("IGD device %s failed to setup OpRegion, "
-                     "legacy mode disabled", vdev->vbasedev.name);
+    vfio_pci_igd_opregion_init(vdev, opregion, &err);
+    if (err) {
+        error_append_hint(&err, "IGD legacy mode disabled\n");
+        error_reportf_err(err, ERR_PREFIX, vdev->vbasedev.name);
         goto out;
     }
 
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index 07a44f5..f9a4fe7 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -2720,10 +2720,10 @@  static int vfio_initfn(PCIDevice *pdev)
             goto out_teardown;
         }
 
-        ret = vfio_pci_igd_opregion_init(vdev, opregion);
+        vfio_pci_igd_opregion_init(vdev, opregion, &err);
         g_free(opregion);
-        if (ret) {
-            error_setg_errno(&err, -ret, "IGD OpRegion initialization failed");
+        if (err) {
+            ret = -EINVAL;
             goto out_teardown;
         }
     }
diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h
index 7d482d9..5336aa4 100644
--- a/hw/vfio/pci.h
+++ b/hw/vfio/pci.h
@@ -163,7 +163,8 @@  void vfio_setup_resetfn_quirk(VFIOPCIDevice *vdev);
 
 int vfio_populate_vga(VFIOPCIDevice *vdev);
 
-int vfio_pci_igd_opregion_init(VFIOPCIDevice *vdev,
-                               struct vfio_region_info *info);
+void vfio_pci_igd_opregion_init(VFIOPCIDevice *vdev,
+                                struct vfio_region_info *info,
+                                Error **errp);
 
 #endif /* HW_VFIO_VFIO_PCI_H */