From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 3/7] Check return value of qdev_init()
Date: Wed, 7 Oct 2009 01:15:57 +0200 [thread overview]
Message-ID: <02351201de017f987b6db0ea749d0a02bbce982a.1254867902.git.armbru@redhat.com> (raw)
In-Reply-To: <cover.1254867902.git.armbru@redhat.com>
But do so only where it may actually fail. Leave the rest for the
next commit.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
hw/pci-hotplug.c | 4 ++--
hw/pci.c | 1 +
hw/scsi-bus.c | 4 +++-
hw/usb-msd.c | 3 ++-
usb-linux.c | 6 ++++--
5 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/hw/pci-hotplug.c b/hw/pci-hotplug.c
index c38a127..ccd2cf3 100644
--- a/hw/pci-hotplug.c
+++ b/hw/pci-hotplug.c
@@ -172,8 +172,8 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon,
default:
dev = NULL;
}
- if (dev)
- qdev_init(&dev->qdev);
+ if (!dev || qdev_init(&dev->qdev) < 0)
+ return NULL;
return dev;
}
diff --git a/hw/pci.c b/hw/pci.c
index 1debdab..da5cc56 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -833,6 +833,7 @@ static const char * const pci_nic_names[] = {
};
/* Initialize a PCI NIC. */
+/* FIXME callers should check for failure, but don't */
PCIDevice *pci_nic_init(NICInfo *nd, const char *default_model,
const char *default_devaddr)
{
diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c
index fe8991e..41992e5 100644
--- a/hw/scsi-bus.c
+++ b/hw/scsi-bus.c
@@ -82,6 +82,7 @@ void scsi_qdev_register(SCSIDeviceInfo *info)
}
/* handle legacy '-drive if=scsi,...' cmd line args */
+/* FIXME callers should check for failure, but don't */
SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, DriveInfo *dinfo, int unit)
{
const char *driver;
@@ -91,7 +92,8 @@ SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, DriveInfo *dinfo, int unit)
dev = qdev_create(&bus->qbus, driver);
qdev_prop_set_uint32(dev, "scsi-id", unit);
qdev_prop_set_drive(dev, "drive", dinfo);
- qdev_init(dev);
+ if (qdev_init(dev) < 0)
+ return NULL;
return DO_UPCAST(SCSIDevice, qdev, dev);
}
diff --git a/hw/usb-msd.c b/hw/usb-msd.c
index e090014..dd3010e 100644
--- a/hw/usb-msd.c
+++ b/hw/usb-msd.c
@@ -571,7 +571,8 @@ USBDevice *usb_msd_init(const char *filename)
/* create guest device */
dev = usb_create(NULL /* FIXME */, "QEMU USB MSD");
qdev_prop_set_drive(&dev->qdev, "drive", dinfo);
- qdev_init(&dev->qdev);
+ if (qdev_init(&dev->qdev) < 0)
+ return NULL;
return dev;
}
diff --git a/usb-linux.c b/usb-linux.c
index 77cbf1b..9e5d9c4 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -980,12 +980,14 @@ static USBDevice *usb_host_device_open_addr(int bus_num, int addr, const char *p
hostdev_link(dev);
- qdev_init(&d->qdev);
+ if (qdev_init(&d->qdev) < 0)
+ goto fail_no_qdev;
return (USBDevice *) dev;
fail:
if (d)
qdev_free(&d->qdev);
+fail_no_qdev:
if (fd != -1)
close(fd);
return NULL;
@@ -1389,7 +1391,7 @@ static int usb_host_auto_scan(void *opaque, int bus_num, int addr,
/* We got a match */
- /* Allredy attached ? */
+ /* Already attached ? */
if (hostdev_find(bus_num, addr))
return 0;
--
1.6.2.5
next prev parent reply other threads:[~2009-10-06 23:16 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-06 23:15 [Qemu-devel] [PATCH 0/7] Clean up use of qdev_init() Markus Armbruster
2009-10-06 23:15 ` [Qemu-devel] [PATCH 1/7] Unbreak USB autoconnect filters Markus Armbruster
2009-10-06 23:15 ` [Qemu-devel] [PATCH 2/7] Make qdev_init() destroy the device on failure Markus Armbruster
2009-10-06 23:15 ` Markus Armbruster [this message]
2009-10-06 23:15 ` [Qemu-devel] [PATCH 4/7] New qdev_init_nofail() Markus Armbruster
2009-10-06 23:15 ` [Qemu-devel] [PATCH 5/7] Make isa_create() terminate program on failure Markus Armbruster
2009-10-06 23:16 ` [Qemu-devel] [PATCH 6/7] Warn if value of qdev_init() isn't checked Markus Armbruster
2009-10-06 23:16 ` [Qemu-devel] [PATCH 7/7] Clean up test for qdev_init() failure 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=02351201de017f987b6db0ea749d0a02bbce982a.1254867902.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).