Patchwork [04/16] qemu-option: parse_option_size(): use error_set()

login
register
mail settings
Submitter Luiz Capitulino
Date May 17, 2012, 2:33 p.m.
Message ID <1337265221-7136-5-git-send-email-lcapitulino@redhat.com>
Download mbox | patch
Permalink /patch/159964/
State New
Headers show

Comments

Luiz Capitulino - May 17, 2012, 2:33 p.m.
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 qemu-option.c |   20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)
Laszlo Ersek - May 18, 2012, 2:03 p.m.
On 05/17/12 16:33, Luiz Capitulino wrote:

> @@ -291,8 +290,10 @@ int set_option_parameter(QEMUOptionParameter *list, const char *name,
>          break;
>  
>      case OPT_SIZE:
> -        if (parse_option_size(name, value, &list->value.n) == -1)
> -            return -1;
> +        parse_option_size(name, value, &list->value.n, &local_err);
> +        if (error_is_set(&local_err)) {
> +            goto exit_err;
> +        }
>          break;
>  
>      default:
> @@ -602,7 +603,8 @@ static int qemu_opt_parse(QemuOpt *opt)
>                              &local_err);
>          break;
>      case QEMU_OPT_SIZE:
> -        return parse_option_size(opt->name, opt->str, &opt->value.uint);
> +        parse_option_size(opt->name, opt->str, &opt->value.uint, &local_err);
> +        break;
>      default:
>          abort();
>      }

... and then the set_option_parameter() change would look like the
qemu_opt_parse() change (no if or goto). But it's fine.

Laszlo
Luiz Capitulino - May 18, 2012, 2:49 p.m.
On Fri, 18 May 2012 16:03:30 +0200
Laszlo Ersek <lersek@redhat.com> wrote:

> On 05/17/12 16:33, Luiz Capitulino wrote:
> 
> > @@ -291,8 +290,10 @@ int set_option_parameter(QEMUOptionParameter *list, const char *name,
> >          break;
> >  
> >      case OPT_SIZE:
> > -        if (parse_option_size(name, value, &list->value.n) == -1)
> > -            return -1;
> > +        parse_option_size(name, value, &list->value.n, &local_err);
> > +        if (error_is_set(&local_err)) {
> > +            goto exit_err;
> > +        }
> >          break;
> >  
> >      default:
> > @@ -602,7 +603,8 @@ static int qemu_opt_parse(QemuOpt *opt)
> >                              &local_err);
> >          break;
> >      case QEMU_OPT_SIZE:
> > -        return parse_option_size(opt->name, opt->str, &opt->value.uint);
> > +        parse_option_size(opt->name, opt->str, &opt->value.uint, &local_err);
> > +        break;
> >      default:
> >          abort();
> >      }
> 
> ... and then the set_option_parameter() change would look like the
> qemu_opt_parse() change (no if or goto). But it's fine.

I'll simplify if I respin.

Patch

diff --git a/qemu-option.c b/qemu-option.c
index a8b50af..61354af 100644
--- a/qemu-option.c
+++ b/qemu-option.c
@@ -203,7 +203,8 @@  static void parse_option_number(const char *name, const char *value,
     }
 }
 
-static int parse_option_size(const char *name, const char *value, uint64_t *ret)
+static void parse_option_size(const char *name, const char *value,
+                              uint64_t *ret, Error **errp)
 {
     char *postfix;
     double sizef;
@@ -229,16 +230,14 @@  static int parse_option_size(const char *name, const char *value, uint64_t *ret)
             *ret = (uint64_t) sizef;
             break;
         default:
-            qerror_report(QERR_INVALID_PARAMETER_VALUE, name, "a size");
+            error_set(errp, QERR_INVALID_PARAMETER_VALUE, name, "a size");
             error_printf_unless_qmp("You may use k, M, G or T suffixes for "
                     "kilobytes, megabytes, gigabytes and terabytes.\n");
-            return -1;
+            return;
         }
     } else {
-        qerror_report(QERR_INVALID_PARAMETER_VALUE, name, "a size");
-        return -1;
+        error_set(errp, QERR_INVALID_PARAMETER_VALUE, name, "a size");
     }
-    return 0;
 }
 
 /*
@@ -291,8 +290,10 @@  int set_option_parameter(QEMUOptionParameter *list, const char *name,
         break;
 
     case OPT_SIZE:
-        if (parse_option_size(name, value, &list->value.n) == -1)
-            return -1;
+        parse_option_size(name, value, &list->value.n, &local_err);
+        if (error_is_set(&local_err)) {
+            goto exit_err;
+        }
         break;
 
     default:
@@ -602,7 +603,8 @@  static int qemu_opt_parse(QemuOpt *opt)
                             &local_err);
         break;
     case QEMU_OPT_SIZE:
-        return parse_option_size(opt->name, opt->str, &opt->value.uint);
+        parse_option_size(opt->name, opt->str, &opt->value.uint, &local_err);
+        break;
     default:
         abort();
     }