diff mbox

[4/7] qmp: Fix device-list-properties not to crash for abstract device

Message ID 1442577640-11612-5-git-send-email-armbru@redhat.com
State New
Headers show

Commit Message

Markus Armbruster Sept. 18, 2015, noon UTC
Broken in commit f4eb32b "qmp: show QOM properties in
device-list-properties", v2.1.

Cc: qemu-stable@nongnu.org
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 qmp.c                          |  6 ++++++
 tests/device-introspect-test.c | 11 ++++-------
 2 files changed, 10 insertions(+), 7 deletions(-)

Comments

Eric Blake Sept. 18, 2015, 3:58 p.m. UTC | #1
On 09/18/2015 06:00 AM, Markus Armbruster wrote:
> Broken in commit f4eb32b "qmp: show QOM properties in
> device-list-properties", v2.1.
> 
> Cc: qemu-stable@nongnu.org
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  qmp.c                          |  6 ++++++
>  tests/device-introspect-test.c | 11 ++++-------
>  2 files changed, 10 insertions(+), 7 deletions(-)
> 

> +++ b/tests/device-introspect-test.c
> @@ -45,13 +45,10 @@ static void test_one_device(const char *type)
>      QDict *resp;
>      char *help;
>  
> -    /* FIXME device-list-properties crashes for abstract device, skip  */
> -    if (strcmp(type, "device")) {

Ah, this answers part of my confusion on 3/7.  I was looking for so
condition on 'abstract', but the skip was based on a condition on
'device' (which happens to be abstract).  Don't know if a different
wording on that comment would help; maybe:

FIXME device-list-properties crashes for device, because it is abstract;
skip

Reviewed-by: Eric Blake <eblake@redhat.com>
diff mbox

Patch

diff --git a/qmp.c b/qmp.c
index 9623c80..6f370d5 100644
--- a/qmp.c
+++ b/qmp.c
@@ -520,6 +520,12 @@  DevicePropertyInfoList *qmp_device_list_properties(const char *typename,
         return NULL;
     }
 
+    if (object_class_is_abstract(klass)) {
+        error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "name",
+                   "non-abstract device type");
+        return NULL;
+    }
+
     obj = object_new(typename);
 
     QTAILQ_FOREACH(prop, &obj->properties, node) {
diff --git a/tests/device-introspect-test.c b/tests/device-introspect-test.c
index bcaaf2a..3e40877 100644
--- a/tests/device-introspect-test.c
+++ b/tests/device-introspect-test.c
@@ -45,13 +45,10 @@  static void test_one_device(const char *type)
     QDict *resp;
     char *help;
 
-    /* FIXME device-list-properties crashes for abstract device, skip  */
-    if (strcmp(type, "device")) {
-        resp = qmp("{'execute': 'device-list-properties',"
-                   " 'arguments': {'typename': %s}}",
-                   type);
-        QDECREF(resp);
-    }
+    resp = qmp("{'execute': 'device-list-properties',"
+               " 'arguments': {'typename': %s}}",
+               type);
+    QDECREF(resp);
 
     help = hmp("device_add \"%s,help\"", type);
     g_free(help);