提交 dd0ba250 编写于 作者: P Paolo Bonzini

qdev: let QOM free properties

Drop the special free callback.  Instead, register a "regular"
release method in the non-legacy property.
Reviewed-by: NAnthony Liguori <aliguori@us.ibm.com>
Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
上级 7b009e5d
...@@ -510,9 +510,10 @@ PropertyInfo qdev_prop_hex64 = { ...@@ -510,9 +510,10 @@ PropertyInfo qdev_prop_hex64 = {
/* --- string --- */ /* --- string --- */
static void free_string(DeviceState *dev, Property *prop) static void release_string(Object *obj, const char *name, void *opaque)
{ {
g_free(*(char **)qdev_get_prop_ptr(dev, prop)); Property *prop = opaque;
g_free(*(char **)qdev_get_prop_ptr(DEVICE(obj), prop));
} }
static int print_string(DeviceState *dev, Property *prop, char *dest, size_t len) static int print_string(DeviceState *dev, Property *prop, char *dest, size_t len)
...@@ -572,7 +573,7 @@ PropertyInfo qdev_prop_string = { ...@@ -572,7 +573,7 @@ PropertyInfo qdev_prop_string = {
.type = PROP_TYPE_STRING, .type = PROP_TYPE_STRING,
.size = sizeof(char*), .size = sizeof(char*),
.print = print_string, .print = print_string,
.free = free_string, .release = release_string,
.get = get_string, .get = get_string,
.set = set_string, .set = set_string,
}; };
...@@ -592,8 +593,10 @@ static int parse_drive(DeviceState *dev, const char *str, void **ptr) ...@@ -592,8 +593,10 @@ static int parse_drive(DeviceState *dev, const char *str, void **ptr)
return 0; return 0;
} }
static void free_drive(DeviceState *dev, Property *prop) static void release_drive(Object *obj, const char *name, void *opaque)
{ {
DeviceState *dev = DEVICE(obj);
Property *prop = opaque;
BlockDriverState **ptr = qdev_get_prop_ptr(dev, prop); BlockDriverState **ptr = qdev_get_prop_ptr(dev, prop);
if (*ptr) { if (*ptr) {
...@@ -667,7 +670,7 @@ PropertyInfo qdev_prop_drive = { ...@@ -667,7 +670,7 @@ PropertyInfo qdev_prop_drive = {
.size = sizeof(BlockDriverState *), .size = sizeof(BlockDriverState *),
.get = get_drive, .get = get_drive,
.set = set_drive, .set = set_drive,
.free = free_drive, .release = release_drive,
}; };
/* --- character device --- */ /* --- character device --- */
...@@ -686,8 +689,10 @@ static int parse_chr(DeviceState *dev, const char *str, void **ptr) ...@@ -686,8 +689,10 @@ static int parse_chr(DeviceState *dev, const char *str, void **ptr)
return 0; return 0;
} }
static void free_chr(DeviceState *dev, Property *prop) static void release_chr(Object *obj, const char *name, void *opaque)
{ {
DeviceState *dev = DEVICE(obj);
Property *prop = opaque;
CharDriverState **ptr = qdev_get_prop_ptr(dev, prop); CharDriverState **ptr = qdev_get_prop_ptr(dev, prop);
if (*ptr) { if (*ptr) {
...@@ -721,7 +726,7 @@ PropertyInfo qdev_prop_chr = { ...@@ -721,7 +726,7 @@ PropertyInfo qdev_prop_chr = {
.size = sizeof(CharDriverState*), .size = sizeof(CharDriverState*),
.get = get_chr, .get = get_chr,
.set = set_chr, .set = set_chr,
.free = free_chr, .release = release_chr,
}; };
/* --- netdev device --- */ /* --- netdev device --- */
......
...@@ -595,7 +595,7 @@ void qdev_property_add_static(DeviceState *dev, Property *prop, ...@@ -595,7 +595,7 @@ void qdev_property_add_static(DeviceState *dev, Property *prop,
object_property_add(OBJECT(dev), prop->name, prop->info->name, object_property_add(OBJECT(dev), prop->name, prop->info->name,
prop->info->get, prop->info->set, prop->info->get, prop->info->set,
NULL, prop->info->release,
prop, errp); prop, errp);
} }
...@@ -626,7 +626,6 @@ static void device_finalize(Object *obj) ...@@ -626,7 +626,6 @@ static void device_finalize(Object *obj)
{ {
DeviceState *dev = DEVICE(obj); DeviceState *dev = DEVICE(obj);
BusState *bus; BusState *bus;
Property *prop;
DeviceClass *dc = DEVICE_GET_CLASS(dev); DeviceClass *dc = DEVICE_GET_CLASS(dev);
if (dev->state == DEV_STATE_INITIALIZED) { if (dev->state == DEV_STATE_INITIALIZED) {
...@@ -645,11 +644,6 @@ static void device_finalize(Object *obj) ...@@ -645,11 +644,6 @@ static void device_finalize(Object *obj)
} }
} }
QTAILQ_REMOVE(&dev->parent_bus->children, dev, sibling); QTAILQ_REMOVE(&dev->parent_bus->children, dev, sibling);
for (prop = qdev_get_props(dev); prop && prop->name; prop++) {
if (prop->info->free) {
prop->info->free(dev, prop);
}
}
} }
void device_reset(DeviceState *dev) void device_reset(DeviceState *dev)
......
...@@ -145,9 +145,9 @@ struct PropertyInfo { ...@@ -145,9 +145,9 @@ struct PropertyInfo {
int64_t max; int64_t max;
int (*parse)(DeviceState *dev, Property *prop, const char *str); int (*parse)(DeviceState *dev, Property *prop, const char *str);
int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len); int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len);
void (*free)(DeviceState *dev, Property *prop);
ObjectPropertyAccessor *get; ObjectPropertyAccessor *get;
ObjectPropertyAccessor *set; ObjectPropertyAccessor *set;
ObjectPropertyRelease *release;
}; };
typedef struct GlobalProperty { typedef struct GlobalProperty {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册