From 8e615e34f9f5dc0ee3a39a468ec96ea537c4afe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Thu, 24 Aug 2017 10:46:00 +0200 Subject: [PATCH] hmp: Use qapi_enum_parse() in hmp_migrate_set_capability() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The error message on invalid capability name changes from Invalid parameter "NAME" to invalid parameter value: NAME No worse than before. Signed-off-by: Marc-André Lureau Message-Id: <20170822132255.23945-9-marcandre.lureau@redhat.com> Reviewed-by: Markus Armbruster [Rebased, commit message rewritten] Cc: "Dr. David Alan Gilbert" Signed-off-by: Markus Armbruster Message-Id: <1503564371-26090-6-git-send-email-armbru@redhat.com> --- hmp.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/hmp.c b/hmp.c index 03c1a783b6..7e0bd3d63b 100644 --- a/hmp.c +++ b/hmp.c @@ -1527,23 +1527,20 @@ 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, -1, &err); + 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) {