Patchwork [v2,04/15] qdev_prop_parse(): push error handling to callers

login
register
mail settings
Submitter Laszlo Ersek
Date Feb. 5, 2013, 8:39 p.m.
Message ID <1360096768-8863-5-git-send-email-lersek@redhat.com>
Download mbox | patch
Permalink /patch/218359/
State New
Headers show

Comments

Laszlo Ersek - Feb. 5, 2013, 8:39 p.m.
Error consumption is moved from qdev_prop_parse() to its direct callers.

Conversion status (call chains covered or substituted by error propagation
marked with square brackets):

do_device_add -> [qemu_find_opts -> error_report]
do_device_add -> qdev_device_add -> qerror_report
do_device_add -> qdev_device_add -> qbus_find -> qbus_find_recursive
  -> qerror_report
do_device_add -> qdev_device_add -> qbus_find -> qerror_report
do_device_add -> qdev_device_add -> set_property -> [qdev_prop_parse
  -> qerror_report_err]

Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---
 hw/qdev-monitor.c    |    5 ++++-
 hw/qdev-properties.c |    9 ++++++---
 2 files changed, 10 insertions(+), 4 deletions(-)
Eduardo Habkost - Feb. 7, 2013, 5:05 p.m.
On Tue, Feb 05, 2013 at 09:39:17PM +0100, Laszlo Ersek wrote:
> Error consumption is moved from qdev_prop_parse() to its direct callers.
> 
> Conversion status (call chains covered or substituted by error propagation
> marked with square brackets):
> 
> do_device_add -> [qemu_find_opts -> error_report]
> do_device_add -> qdev_device_add -> qerror_report
> do_device_add -> qdev_device_add -> qbus_find -> qbus_find_recursive
>   -> qerror_report
> do_device_add -> qdev_device_add -> qbus_find -> qerror_report
> do_device_add -> qdev_device_add -> set_property -> [qdev_prop_parse
>   -> qerror_report_err]
> 
> Signed-off-by: Laszlo Ersek <lersek@redhat.com>

Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>


> ---
>  hw/qdev-monitor.c    |    5 ++++-
>  hw/qdev-properties.c |    9 ++++++---
>  2 files changed, 10 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/qdev-monitor.c b/hw/qdev-monitor.c
> index 02297e1..5eb1c8c 100644
> --- a/hw/qdev-monitor.c
> +++ b/hw/qdev-monitor.c
> @@ -103,13 +103,16 @@ 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, NULL) == -1) {
> +    if (qdev_prop_parse(dev, name, value, &err) == -1) {
> +        qerror_report_err(err);
> +        error_free(err);
>          return -1;
>      }
>      return 0;
> diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
> index e2dbbbe..8e3d014 100644
> --- a/hw/qdev-properties.c
> +++ b/hw/qdev-properties.c
> @@ -850,8 +850,7 @@ int qdev_prop_parse(DeviceState *dev, const char *name, const char *value,
>      g_free(legacy_name);
>  
>      if (err) {
> -        qerror_report_err(err);
> -        error_free(err);
> +        error_propagate(errp, err);
>          return -1;
>      }
>      return 0;
> @@ -963,10 +962,14 @@ void qdev_prop_set_globals(DeviceState *dev)
>      do {
>          GlobalProperty *prop;
>          QTAILQ_FOREACH(prop, &global_props, next) {
> +            Error *err = NULL;
> +
>              if (strcmp(object_class_get_name(class), prop->driver) != 0) {
>                  continue;
>              }
> -            if (qdev_prop_parse(dev, prop->property, prop->value, NULL) != 0) {
> +            if (qdev_prop_parse(dev, prop->property, prop->value, &err) != 0) {
> +                qerror_report_err(err);
> +                error_free(err);
>                  exit(1);
>              }
>          }
> -- 
> 1.7.1
> 
>

Patch

diff --git a/hw/qdev-monitor.c b/hw/qdev-monitor.c
index 02297e1..5eb1c8c 100644
--- a/hw/qdev-monitor.c
+++ b/hw/qdev-monitor.c
@@ -103,13 +103,16 @@  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, NULL) == -1) {
+    if (qdev_prop_parse(dev, name, value, &err) == -1) {
+        qerror_report_err(err);
+        error_free(err);
         return -1;
     }
     return 0;
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index e2dbbbe..8e3d014 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -850,8 +850,7 @@  int qdev_prop_parse(DeviceState *dev, const char *name, const char *value,
     g_free(legacy_name);
 
     if (err) {
-        qerror_report_err(err);
-        error_free(err);
+        error_propagate(errp, err);
         return -1;
     }
     return 0;
@@ -963,10 +962,14 @@  void qdev_prop_set_globals(DeviceState *dev)
     do {
         GlobalProperty *prop;
         QTAILQ_FOREACH(prop, &global_props, next) {
+            Error *err = NULL;
+
             if (strcmp(object_class_get_name(class), prop->driver) != 0) {
                 continue;
             }
-            if (qdev_prop_parse(dev, prop->property, prop->value, NULL) != 0) {
+            if (qdev_prop_parse(dev, prop->property, prop->value, &err) != 0) {
+                qerror_report_err(err);
+                error_free(err);
                 exit(1);
             }
         }