diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2011-12-18 17:05:06 +0100 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2011-12-19 10:27:33 -0600 |
commit | e3cb6ba65d265f2cc1313ee26e879407ff24663c (patch) | |
tree | abdafc651bed08dddfe08dab94a54c10cad2b6ba | |
parent | 0d41d9aabbed72750ca41e94ce1fda94dd1919d1 (diff) | |
download | qemu-e3cb6ba65d265f2cc1313ee26e879407ff24663c.zip qemu-e3cb6ba65d265f2cc1313ee26e879407ff24663c.tar.gz qemu-e3cb6ba65d265f2cc1313ee26e879407ff24663c.tar.bz2 |
qom: push permission checks up into qdev_property_add_legacy
qdev_property_get and qdev_property_set can generate permission
denied errors themselves. Do not duplicate this functionality in
qdev_get/set_legacy_property, and clean up excessive indentation.
Reviewed-by: Anthony Liguori <anthony@codemonkey.ws>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
-rw-r--r-- | hw/qdev.c | 46 |
1 files changed, 19 insertions, 27 deletions
@@ -1135,46 +1135,38 @@ static void qdev_get_legacy_property(DeviceState *dev, Visitor *v, void *opaque, { Property *prop = opaque; - if (prop->info->print) { - char buffer[1024]; - char *ptr = buffer; + char buffer[1024]; + char *ptr = buffer; - prop->info->print(dev, prop, buffer, sizeof(buffer)); - visit_type_str(v, &ptr, name, errp); - } else { - error_set(errp, QERR_PERMISSION_DENIED); - } + prop->info->print(dev, prop, buffer, sizeof(buffer)); + visit_type_str(v, &ptr, name, errp); } static void qdev_set_legacy_property(DeviceState *dev, Visitor *v, void *opaque, const char *name, Error **errp) { Property *prop = opaque; + Error *local_err = NULL; + char *ptr = NULL; + int ret; if (dev->state != DEV_STATE_CREATED) { error_set(errp, QERR_PERMISSION_DENIED); return; } - if (prop->info->parse) { - Error *local_err = NULL; - char *ptr = NULL; + visit_type_str(v, &ptr, name, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } - visit_type_str(v, &ptr, name, &local_err); - if (!local_err) { - int ret; - ret = prop->info->parse(dev, prop, ptr); - if (ret != 0) { - error_set(errp, QERR_INVALID_PARAMETER_VALUE, - name, prop->info->name); - } - g_free(ptr); - } else { - error_propagate(errp, local_err); - } - } else { - error_set(errp, QERR_PERMISSION_DENIED); + ret = prop->info->parse(dev, prop, ptr); + if (ret != 0) { + error_set(errp, QERR_INVALID_PARAMETER_VALUE, + name, prop->info->name); } + g_free(ptr); } /** @@ -1194,8 +1186,8 @@ void qdev_property_add_legacy(DeviceState *dev, Property *prop, type = g_strdup_printf("legacy<%s>", prop->info->name); qdev_property_add(dev, prop->name, type, - qdev_get_legacy_property, - qdev_set_legacy_property, + prop->info->print ? qdev_get_legacy_property : NULL, + prop->info->parse ? qdev_set_legacy_property : NULL, NULL, prop, errp); |