From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 2/6] Fix pci_add storage not to exit on bad first argument
Date: Fri, 25 Sep 2009 03:53:49 +0200 [thread overview]
Message-ID: <1f7e6a1805b4e87537d2626cd338981247fce316.1253843232.git.armbru@redhat.com> (raw)
In-Reply-To: <cover.1253843232.git.armbru@redhat.com>
Monitor command "pci_add ADDR storage ..." does its work in
qemu_pci_hot_add_nic(). It called pci_create(..., ADDR) to create the
device. That's wrong, because pci_create() terminates the program
when ADDR is invalid.
Use pci_get_bus_devfn() and pci_create_noinit() instead.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
hw/pci-hotplug.c | 12 ++++++++++--
hw/pci.c | 2 +-
hw/pci.h | 1 +
3 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/hw/pci-hotplug.c b/hw/pci-hotplug.c
index f3dc421..d6093ba 100644
--- a/hw/pci-hotplug.c
+++ b/hw/pci-hotplug.c
@@ -107,6 +107,8 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon,
DriveInfo *dinfo = NULL;
int type = -1;
char buf[128];
+ PCIBus *bus;
+ int devfn;
if (get_param_value(buf, sizeof(buf), "if", opts)) {
if (!strcmp(buf, "scsi"))
@@ -134,16 +136,22 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon,
dinfo = NULL;
}
+ bus = pci_get_bus_devfn(&devfn, devaddr);
+ if (!bus) {
+ monitor_printf(mon, "Invalid PCI device address %s\n", devaddr);
+ return NULL;
+ }
+
switch (type) {
case IF_SCSI:
- dev = pci_create("lsi53c895a", devaddr);
+ dev = pci_create_noinit(bus, devfn, "lsi53c895a");
break;
case IF_VIRTIO:
if (!dinfo) {
monitor_printf(mon, "virtio requires a backing file/device.\n");
return NULL;
}
- dev = pci_create("virtio-blk-pci", devaddr);
+ dev = pci_create_noinit(bus, devfn, "virtio-blk-pci");
qdev_prop_set_drive(&dev->qdev, "drive", dinfo);
break;
default:
diff --git a/hw/pci.c b/hw/pci.c
index 64d70ed..5be21d7 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -265,7 +265,7 @@ int pci_read_devaddr(Monitor *mon, const char *addr, int *domp, int *busp,
return 0;
}
-static PCIBus *pci_get_bus_devfn(int *devfnp, const char *devaddr)
+PCIBus *pci_get_bus_devfn(int *devfnp, const char *devaddr)
{
int dom, bus;
unsigned slot;
diff --git a/hw/pci.h b/hw/pci.h
index caba5c8..356405e 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -260,6 +260,7 @@ int pci_bus_num(PCIBus *s);
void pci_for_each_device(int bus_num, void (*fn)(PCIDevice *d));
PCIBus *pci_find_bus(int bus_num);
PCIDevice *pci_find_device(int bus_num, int slot, int function);
+PCIBus *pci_get_bus_devfn(int *devfnp, const char *devaddr);
int pci_read_devaddr(Monitor *mon, const char *addr, int *domp, int *busp,
unsigned *slotp);
--
1.6.2.5
next prev parent reply other threads:[~2009-09-25 1:54 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-25 1:53 [Qemu-devel] [PATCH 0/6] Fix pci_add not to exit on error & other fixes Markus Armbruster
2009-09-25 1:53 ` [Qemu-devel] [PATCH 1/6] Fix pci_vga_init() not to ignore bus argument Markus Armbruster
2009-09-25 1:53 ` Markus Armbruster [this message]
2009-09-25 16:36 ` [Qemu-devel] Re: [PATCH 2/6] Fix pci_add storage not to exit on bad first argument Markus Armbruster
2009-09-25 1:53 ` [Qemu-devel] [PATCH 3/6] Make it obvious that pci_nic_init() can't fail Markus Armbruster
2009-09-25 1:53 ` [Qemu-devel] [PATCH 4/6] Fix pci_add nic not to exit on bad model Markus Armbruster
2009-09-25 1:53 ` [Qemu-devel] [PATCH 5/6] pci_create() is now unused, remove it Markus Armbruster
2009-09-25 1:53 ` [Qemu-devel] [PATCH 6/6] Rename pci_create_noinit() to pci_create() Markus Armbruster
2009-09-25 10:44 ` [Qemu-devel] [PATCH 0/6] Fix pci_add not to exit on error & other fixes Gerd Hoffmann
2009-09-25 14:12 ` Markus Armbruster
2009-09-25 16:26 ` Luiz Capitulino
2009-09-28 16:05 ` Mark McLoughlin
2009-09-28 16:16 ` Mark McLoughlin
2009-09-28 19:14 ` Markus Armbruster
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=1f7e6a1805b4e87537d2626cd338981247fce316.1253843232.git.armbru@redhat.com \
--to=armbru@redhat.com \
--cc=qemu-devel@nongnu.org \
/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;
as well as URLs for NNTP newsgroup(s).