The Property.name field won't always be set and we need to be 100% sure its usage will be restricted to qdev/TYPE_DEVICE code. Renaming the field is a good way to ensure that and make its purpose more clear.
Signed-off-by: Eduardo Habkost <ehabk...@redhat.com> --- This is a new patch added in v2 of the series --- Cc: Paolo Bonzini <pbonz...@redhat.com> Cc: "Daniel P. Berrangé" <berra...@redhat.com> Cc: Eduardo Habkost <ehabk...@redhat.com> Cc: qemu-devel@nongnu.org --- include/hw/qdev-properties.h | 11 +++++++++-- hw/core/qdev-properties.c | 20 ++++++++++---------- softmmu/qdev-monitor.c | 8 ++++---- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h index bbc5244ed0..b301fe64d7 100644 --- a/include/hw/qdev-properties.h +++ b/include/hw/qdev-properties.h @@ -13,7 +13,14 @@ * is true. */ struct Property { - const char *name; + /** + * @qdev_prop_name: qdev property name + * + * qdev_prop_name is used only by TYPE_DEVICE code + * (device_class_set_props(), qdev_class_add_property(), and + * others). + */ + const char *qdev_prop_name; const PropertyInfo *info; ptrdiff_t offset; uint8_t bitnr; @@ -63,7 +70,7 @@ extern const PropertyInfo qdev_prop_arraylen; extern const PropertyInfo qdev_prop_link; #define DEFINE_PROP(_name, _state, _field, _prop, _type, ...) { \ - .name = (_name), \ + .qdev_prop_name = (_name), \ .info = &(_prop), \ .offset = offsetof(_state, _field) \ + type_check(_type, typeof_field(_state, _field)), \ diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index e9e2a34f3b..5a4aa87fc9 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -596,7 +596,7 @@ static void set_prop_arraylen(Object *obj, Visitor *v, const char *name, arrayprop->release = prop->arrayinfo->release; arrayprop->propname = propname; arrayprop->prop.info = prop->arrayinfo; - arrayprop->prop.name = propname; + arrayprop->prop.qdev_prop_name = propname; /* This ugly piece of pointer arithmetic sets up the offset so * that when the underlying get/set hooks call qdev_get_prop_ptr * they get the right answer despite the array element not actually @@ -627,8 +627,8 @@ static Property *qdev_prop_walk(Property *props, const char *name) if (!props) { return NULL; } - while (props->name) { - if (strcmp(props->name, name) == 0) { + while (props->qdev_prop_name) { + if (strcmp(props->qdev_prop_name, name) == 0) { return props; } props++; @@ -889,7 +889,7 @@ object_class_property_add_field(ObjectClass *oc, const char *name, void qdev_property_add_static(DeviceState *dev, Property *prop) { - object_property_add_field(OBJECT(dev), prop->name, prop); + object_property_add_field(OBJECT(dev), prop->qdev_prop_name, prop); } /** @@ -932,7 +932,7 @@ static void qdev_class_add_legacy_property(DeviceClass *dc, Property *prop) return; } - name = g_strdup_printf("legacy-%s", prop->name); + name = g_strdup_printf("legacy-%s", prop->qdev_prop_name); object_class_property_add(OBJECT_CLASS(dc), name, "str", prop->info->print ? qdev_get_legacy_property : prop->info->get, NULL, NULL, prop); @@ -944,9 +944,9 @@ void device_class_set_props(DeviceClass *dc, Property *props) Property *prop; dc->props_ = props; - for (prop = props; prop && prop->name; prop++) { + for (prop = props; prop && prop->qdev_prop_name; prop++) { qdev_class_add_legacy_property(dc, prop); - object_class_property_add_field(oc, prop->name, prop); + object_class_property_add_field(oc, prop->qdev_prop_name, prop); } } @@ -959,9 +959,9 @@ void qdev_alias_all_properties(DeviceState *target, Object *source) do { DeviceClass *dc = DEVICE_CLASS(class); - for (prop = dc->props_; prop && prop->name; prop++) { - object_property_add_alias(source, prop->name, - OBJECT(target), prop->name); + for (prop = dc->props_; prop && prop->qdev_prop_name; prop++) { + object_property_add_alias(source, prop->qdev_prop_name, + OBJECT(target), prop->qdev_prop_name); } class = object_class_get_parent(class); } while (class != object_class_by_name(TYPE_DEVICE)); diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c index 79164e4a3f..786b9ce572 100644 --- a/softmmu/qdev-monitor.c +++ b/softmmu/qdev-monitor.c @@ -697,14 +697,14 @@ static void qdev_print_props(Monitor *mon, DeviceState *dev, Property *props, { if (!props) return; - for (; props->name; props++) { + for (; props->qdev_prop_name; props++) { char *value; - char *legacy_name = g_strdup_printf("legacy-%s", props->name); + char *legacy_name = g_strdup_printf("legacy-%s", props->qdev_prop_name); if (object_property_get_type(OBJECT(dev), legacy_name, NULL)) { value = object_property_get_str(OBJECT(dev), legacy_name, NULL); } else { - value = object_property_print(OBJECT(dev), props->name, true, + value = object_property_print(OBJECT(dev), props->qdev_prop_name, true, NULL); } g_free(legacy_name); @@ -712,7 +712,7 @@ static void qdev_print_props(Monitor *mon, DeviceState *dev, Property *props, if (!value) { continue; } - qdev_printf("%s = %s\n", props->name, + qdev_printf("%s = %s\n", props->qdev_prop_name, *value ? value : "<null>"); g_free(value); } -- 2.28.0