958e1b
From 041c25ce0ca658d4426ec18a116a464e4bac9862 Mon Sep 17 00:00:00 2001
958e1b
From: Marcel Apfelbaum <marcel.a@redhat.com>
958e1b
Date: Thu, 20 Nov 2014 10:33:13 +0100
958e1b
Subject: [PATCH 1/2] hw/pci: fixed error flow in pci_qdev_init
958e1b
958e1b
Message-id: <1416479594-22022-2-git-send-email-marcel.a@redhat.com>
958e1b
Patchwork-id: 62484
958e1b
O-Subject: [RHEL-7.1 qemu-kvm PATCH 1/2] hw/pci: fixed error flow in pci_qdev_init
958e1b
Bugzilla: 1046007
958e1b
RH-Acked-by: Dr. David Alan Gilbert (git) <dgilbert@redhat.com>
958e1b
RH-Acked-by: Amos Kong <akong@redhat.com>
958e1b
RH-Acked-by: Eric Blake <eblake@redhat.com>
958e1b
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
958e1b
958e1b
Verify return code for pci_add_option_rom.
958e1b
958e1b
Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com>
958e1b
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
958e1b
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
958e1b
Reviewed-by: Markus Armbruster <armbru@redhat.com>
958e1b
(cherry picked from commit 178e785fb4507ec3462dc772bbe08303416ece47)
958e1b
Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com>
958e1b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
958e1b
---
958e1b
 hw/pci/pci.c | 7 ++++++-
958e1b
 1 file changed, 6 insertions(+), 1 deletion(-)
958e1b
958e1b
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
958e1b
index 703b111..0918f4e 100644
958e1b
--- a/hw/pci/pci.c
958e1b
+++ b/hw/pci/pci.c
958e1b
@@ -1733,7 +1733,12 @@ static int pci_qdev_init(DeviceState *qdev)
958e1b
         pci_dev->romfile = g_strdup(pc->romfile);
958e1b
         is_default_rom = true;
958e1b
     }
958e1b
-    pci_add_option_rom(pci_dev, is_default_rom);
958e1b
+
958e1b
+    rc = pci_add_option_rom(pci_dev, is_default_rom);
958e1b
+    if (rc != 0) {
958e1b
+        pci_unregister_device(DEVICE(pci_dev));
958e1b
+        return rc;
958e1b
+    }
958e1b
 
958e1b
     if (bus->hotplug) {
958e1b
         /* Let buses differentiate between hotplug and when device is
958e1b
-- 
958e1b
1.8.3.1
958e1b