public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Glauber Costa <gcosta@redhat.com>
To: kvm-devel@lists.sourceforge.net
Cc: avi@qumranet.com
Subject: [PATCH 2/3] [PATCH] unregister pci device
Date: Wed, 26 Mar 2008 18:09:51 -0300	[thread overview]
Message-ID: <1206565792-19627-3-git-send-email-gcosta@redhat.com> (raw)
In-Reply-To: <1206565792-19627-1-git-send-email-gcosta@redhat.com>

If we fail after we have allocated the pci device, we have
to get rid of it. Otherwise, a bogus device will be found on
the bus

Signed-off-by: Glauber Costa <gcosta@redhat.com>
---
 qemu/hw/passthrough/passthrough.c |   11 +++++++----
 qemu/hw/pci.c                     |    6 ++++++
 qemu/hw/pci.h                     |    2 ++
 3 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/qemu/hw/passthrough/passthrough.c b/qemu/hw/passthrough/passthrough.c
index a416098..64f0af9 100644
--- a/qemu/hw/passthrough/passthrough.c
+++ b/qemu/hw/passthrough/passthrough.c
@@ -389,13 +389,13 @@ pt_dev_t *register_real_device(PCIBus * 
 	if (pt_get_real_device(pci_dev, r_bus, r_dev, r_func)) {
 		fprintf(logfile, "register_real_device: Error: Couldn't get "
 			"real device (%s)!\n", e_dev_name);
-		return NULL;
+		goto out;
 	}
 
 	/* handle real device's MMIO/PIO BARs */
 	if (pt_register_regions(pci_dev->real_device.regions,
 				pci_dev->real_device.region_number, pci_dev))
-		return (NULL);
+		goto out;
 
 	/* handle interrupt routing */
 	e_device = (pci_dev->dev.devfn >> 3) & 0x1f;
@@ -412,7 +412,7 @@ pt_dev_t *register_real_device(PCIBus * 
 		if (rc) {
 			fprintf(logfile, "pt_bind %d failed rc=%d\n",
 				pci_dev->mirq, rc);
-			return NULL;
+			goto out;
 		}
 		sprintf(pci_dev->sirq, "%d", pci_dev->mirq);
 	}
@@ -433,7 +433,7 @@ pt_dev_t *register_real_device(PCIBus * 
 			fprintf(stderr, "Could not notify kernel about "
 				"passthrough device\n");
 			perror("pt-ioctl:");
-			return NULL;
+			goto out;
 		}
 		fprintf(logfile, "Registered host PCI device %02x:%02x.%1x as "
 			"guest device %02x:%02x.%1x with hypercall support\n",
@@ -445,6 +445,9 @@ pt_dev_t *register_real_device(PCIBus * 
 		r_bus, r_dev, r_func, e_dev_name);
 
 	return (pci_dev);
+out:
+	pci_unregister_device(e_bus, &pci_dev->dev);
+	return NULL;
 }
 
 #define	MAX_PTDEVS 4
diff --git a/qemu/hw/pci.c b/qemu/hw/pci.c
index 72b65db..b605744 100644
--- a/qemu/hw/pci.c
+++ b/qemu/hw/pci.c
@@ -185,6 +185,12 @@ PCIDevice *pci_register_device(PCIBus *b
     return pci_dev;
 }
 
+void pci_unregister_device(PCIBus *bus, PCIDevice *dev)
+{
+	bus->devices[dev->devfn] = NULL;
+	qemu_free(dev);
+}
+
 void pci_register_io_region(PCIDevice *pci_dev, int region_num,
                             uint32_t size, int type,
                             PCIMapIORegionFunc *map_func)
diff --git a/qemu/hw/pci.h b/qemu/hw/pci.h
index e870987..220189f 100644
--- a/qemu/hw/pci.h
+++ b/qemu/hw/pci.h
@@ -70,6 +70,8 @@ PCIDevice *pci_register_device(PCIBus *b
                                PCIConfigReadFunc *config_read,
                                PCIConfigWriteFunc *config_write);
 
+void pci_unregister_device(PCIBus *bus, PCIDevice *dev);
+
 void pci_register_io_region(PCIDevice *pci_dev, int region_num,
                             uint32_t size, int type,
                             PCIMapIORegionFunc *map_func);
-- 
1.4.2


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace

  parent reply	other threads:[~2008-03-26 21:09 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-26 21:09 [PATCH 0/3] fixups for pci passthrough Glauber Costa
2008-03-26 21:09 ` [PATCH 1/3] [PATCH] passthrough Glauber Costa
2008-03-27  7:49   ` Avi Kivity
2008-03-26 21:09 ` Glauber Costa [this message]
2008-03-27  7:50   ` [PATCH 2/3] [PATCH] unregister pci device Avi Kivity
2008-03-27 11:40     ` Glauber Costa
2008-03-27 11:43       ` Avi Kivity
2008-03-26 21:09 ` [PATCH 3/3] [PATCH] remove warnings Glauber Costa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1206565792-19627-3-git-send-email-gcosta@redhat.com \
    --to=gcosta@redhat.com \
    --cc=avi@qumranet.com \
    --cc=kvm-devel@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox