qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v2 08/54] hmp: use qapi_enum_parse() in hmp_migr


From: Dr. David Alan Gilbert
Subject: Re: [Qemu-devel] [PATCH v2 08/54] hmp: use qapi_enum_parse() in hmp_migrate_set_capability
Date: Thu, 24 Aug 2017 12:29:28 +0100
User-agent: Mutt/1.8.3 (2017-05-23)

* Marc-André Lureau (address@hidden) wrote:
> Signed-off-by: Marc-André Lureau <address@hidden>
> ---
>  hmp.c | 24 +++++++++++-------------
>  1 file changed, 11 insertions(+), 13 deletions(-)
> 
> diff --git a/hmp.c b/hmp.c
> index 29e42ab661..4ba50e8e26 100644
> --- a/hmp.c
> +++ b/hmp.c
> @@ -1544,23 +1544,21 @@ void hmp_migrate_set_capability(Monitor *mon, const 
> QDict *qdict)
>      bool state = qdict_get_bool(qdict, "state");
>      Error *err = NULL;
>      MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
> -    int i;
> +    int val;
>  
> -    for (i = 0; i < MIGRATION_CAPABILITY__MAX; i++) {
> -        if (strcmp(cap, MigrationCapability_lookup[i]) == 0) {
> -            caps->value = g_malloc0(sizeof(*caps->value));
> -            caps->value->capability = i;
> -            caps->value->state = state;
> -            caps->next = NULL;
> -            qmp_migrate_set_capabilities(caps, &err);
> -            break;
> -        }
> +    val = qapi_enum_parse(MigrationCapability_lookup, cap,
> +                          MIGRATION_CAPABILITY__MAX, -1, &err);

It would be nice to macro that to something like:
   MigrationCapability_parse(cap, -1, &err);

which would stop the inevitable case of someone using the wrong _lookup
with the wrong _MAX.

I also wonder if having the qapi_enum_parse return a bool and take a
&int would be nicer - it would get rid of the need for the -1 default
and mean actually it could be an unsigned.

Still, those are only suggestions, so:

Reviewed-by: Dr. David Alan Gilbert <address@hidden>

> +    if (val < 0) {
> +        goto end;
>      }
>  
> -    if (i == MIGRATION_CAPABILITY__MAX) {
> -        error_setg(&err, QERR_INVALID_PARAMETER, cap);
> -    }
> +    caps->value = g_malloc0(sizeof(*caps->value));
> +    caps->value->capability = val;
> +    caps->value->state = state;
> +    caps->next = NULL;
> +    qmp_migrate_set_capabilities(caps, &err);
>  
> +end:
>      qapi_free_MigrationCapabilityStatusList(caps);
>  
>      if (err) {
> -- 
> 2.14.1.146.gd35faa819
> 
--
Dr. David Alan Gilbert / address@hidden / Manchester, UK



reply via email to

[Prev in Thread] Current Thread [Next in Thread]