Patchwork [RFC,42/48] error: Convert do_device_add() to QError

login
register
mail settings
Submitter Markus Armbruster
Date Feb. 24, 2010, 5:55 p.m.
Message ID <1267034160-3517-43-git-send-email-armbru@redhat.com>
Download mbox | patch
Permalink /patch/46162/
State New
Headers show

Comments

Markus Armbruster - Feb. 24, 2010, 5:55 p.m.
Conversion to QObject is still missing.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/qdev.c |   19 +++++++++----------
 1 files changed, 9 insertions(+), 10 deletions(-)

Patch

diff --git a/hw/qdev.c b/hw/qdev.c
index 4e348fd..a028e9c 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -200,15 +200,15 @@  DeviceState *qdev_device_add(QemuOpts *opts)
 
     driver = qemu_opt_get(opts, "driver");
     if (!driver) {
-        qemu_error("-device: no driver specified");
+        qemu_error_new(QERR_MISSING_PARAMETER, "driver");
         return NULL;
     }
 
     /* find driver */
     info = qdev_find_info(NULL, driver);
     if (!info || info->no_user) {
-        qemu_error("Device \"%s\" not found.  Try -device '?' for a list.",
-                   driver);
+        qemu_error_new(QERR_INVALID_PARAMETER, "driver");
+        error_printf_unless_qmp("Try with argument '?' for a list.\n");
         return NULL;
     }
 
@@ -220,21 +220,20 @@  DeviceState *qdev_device_add(QemuOpts *opts)
             return NULL;
         }
         if (bus->info != info->bus_info) {
-            qemu_error("Device '%s' can't go on a %s bus",
-                       driver, bus->info->name);
+            qemu_error_new(QERR_BAD_BUS_FOR_DEVICE,
+                           driver, bus->info->name);
             return NULL;
         }
     } else {
         bus = qbus_find_recursive(main_system_bus, NULL, info->bus_info);
         if (!bus) {
-            qemu_error("Did not find %s bus for %s",
-                       info->bus_info->name, info->name);
+            qemu_error_new(QERR_NO_BUS_FOR_DEVICE,
+                           info->name, info->bus_info->name);
             return NULL;
         }
     }
     if (qdev_hotplug && !bus->allow_hotplug) {
-        qemu_error("Bus %s does not support hotplugging",
-                   bus->name);
+        qemu_error_new(QERR_BUS_NO_HOTPLUG, bus->name);
         return NULL;
     }
 
@@ -249,7 +248,7 @@  DeviceState *qdev_device_add(QemuOpts *opts)
         return NULL;
     }
     if (qdev_init(qdev) < 0) {
-        qemu_error("Error initializing device %s", driver);
+        qemu_error_new(QERR_DEVICE_INIT_FAILED, driver);
         return NULL;
     }
     qdev->opts = opts;