Patchwork [RFC,07/15] qdev: allow qdev_prop_parse() to report errors

login
register
mail settings
Submitter Eduardo Habkost
Date Aug. 7, 2012, 7:56 p.m.
Message ID <1344369413-9053-8-git-send-email-ehabkost@redhat.com>
Download mbox | patch
Permalink /patch/175784/
State New
Headers show

Comments

Eduardo Habkost - Aug. 7, 2012, 7:56 p.m.
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/qdev-monitor.c    |  6 +++++-
 hw/qdev-properties.c | 21 ++++++++-------------
 hw/qdev.h            |  3 ++-
 3 files changed, 15 insertions(+), 15 deletions(-)

Patch

diff --git a/hw/qdev-monitor.c b/hw/qdev-monitor.c
index b22a37a..99784c1 100644
--- a/hw/qdev-monitor.c
+++ b/hw/qdev-monitor.c
@@ -101,13 +101,17 @@  static void qdev_print_devinfo(ObjectClass *klass, void *opaque)
 static int set_property(const char *name, const char *value, void *opaque)
 {
     DeviceState *dev = opaque;
+    Error *err = NULL;
 
     if (strcmp(name, "driver") == 0)
         return 0;
     if (strcmp(name, "bus") == 0)
         return 0;
 
-    if (qdev_prop_parse(dev, name, value) == -1) {
+    qdev_prop_parse(dev, name, value, &err);
+    if (err) {
+        qerror_report_err(err);
+        error_free(err);
         return -1;
     }
     return 0;
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index 8aca0d4..a52884f 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -1087,25 +1087,17 @@  void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev,
     }
 }
 
-int qdev_prop_parse(DeviceState *dev, const char *name, const char *value)
+void qdev_prop_parse(DeviceState *dev, const char *name, const char *value,
+                     Error **errp)
 {
     char *legacy_name;
-    Error *err = NULL;
-
     legacy_name = g_strdup_printf("legacy-%s", name);
     if (object_property_get_type(OBJECT(dev), legacy_name, NULL)) {
-        object_property_parse(OBJECT(dev), value, legacy_name, &err);
+        object_property_parse(OBJECT(dev), value, legacy_name, errp);
     } else {
-        object_property_parse(OBJECT(dev), value, name, &err);
+        object_property_parse(OBJECT(dev), value, name, errp);
     }
     g_free(legacy_name);
-
-    if (err) {
-        qerror_report_err(err);
-        error_free(err);
-        return -1;
-    }
-    return 0;
 }
 
 void qdev_prop_set_bit(DeviceState *dev, const char *name, bool value)
@@ -1250,11 +1242,14 @@  void qdev_prop_set_globals(DeviceState *dev)
 
     do {
         GlobalProperty *prop;
+        Error *err = NULL;
         QTAILQ_FOREACH(prop, &global_props, next) {
             if (strcmp(object_class_get_name(class), prop->driver) != 0) {
                 continue;
             }
-            if (qdev_prop_parse(dev, prop->property, prop->value) != 0) {
+            qdev_prop_parse(dev, prop->property, prop->value, &err);
+            if (err) {
+                qerror_report_err(err);
                 exit(1);
             }
         }
diff --git a/hw/qdev.h b/hw/qdev.h
index d699194..41db6c0 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -311,7 +311,8 @@  extern PropertyInfo qdev_prop_pci_host_devaddr;
 
 /* Set properties between creation and init.  */
 void *qdev_get_prop_ptr(DeviceState *dev, Property *prop);
-int qdev_prop_parse(DeviceState *dev, const char *name, const char *value);
+void qdev_prop_parse(DeviceState *dev, const char *name, const char *value,
+                     Error **errp);
 void qdev_prop_set_bit(DeviceState *dev, const char *name, bool value);
 void qdev_prop_set_uint8(DeviceState *dev, const char *name, uint8_t value);
 void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value);