From: "Gao, Lu" <lu....@verisilicon.com> Array property needs corresponding `len-` property set first to add actual array properties. Then we need to make sure `len-` property is set first before array property.
But when the model is used with like `-device driver[,prop[=value][,...]]` in QEMU command line options, this is not guaranteed in current property set from qdict. Array property might be handled before 'len-' property, then leads to an error. Signed-off-by: Lu Gao <lu....@verisilicon.com> Signed-off-by: Jianxian Wen <jianxian....@verisilicon.com> --- qom/object_interfaces.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c index 7d31589b04..87500401a4 100644 --- a/qom/object_interfaces.c +++ b/qom/object_interfaces.c @@ -18,6 +18,7 @@ #include "qapi/opts-visitor.h" #include "qemu/config-file.h" #include "qemu/keyval.h" +#include "hw/qdev-properties.h" bool user_creatable_complete(UserCreatable *uc, Error **errp) { @@ -52,8 +53,22 @@ static void object_set_properties_from_qdict(Object *obj, const QDict *qdict, return; } for (e = qdict_first(qdict); e; e = qdict_next(qdict, e)) { - if (!object_property_set(obj, e->key, v, errp)) { - goto out; + /* set "len-" first for the array props to be allocated first */ + if (strncmp(e->key, PROP_ARRAY_LEN_PREFIX, + strlen(PROP_ARRAY_LEN_PREFIX)) == 0) { + if (!object_property_set(obj, e->key, v, errp)) { + goto out; + } + } + } + + for (e = qdict_first(qdict); e; e = qdict_next(qdict, e)) { + /* "len-" has been set above */ + if (strncmp(e->key, PROP_ARRAY_LEN_PREFIX, + strlen(PROP_ARRAY_LEN_PREFIX)) != 0) { + if (!object_property_set(obj, e->key, v, errp)) { + goto out; + } } } visit_check_struct(v, errp); -- 2.17.1