qom: Change object_get_canonical_path_component() not to malloc
object_get_canonical_path_component() returns a malloced copy of a property name on success, null on failure. 19 of its 25 callers immediately free the returned copy. Change object_get_canonical_path_component() to return the property name directly. Since modifying the name would be wrong, adjust the return type to const char *. Drop the free from the 19 callers become simpler, add the g_strdup() to the other six. Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-Id: <20200714160202.3121879-4-armbru@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Reviewed-by: Li Qiang <liq3ea@gmail.com>
This commit is contained in:
parent
af3d69058e
commit
7a309cc95b
@ -33,7 +33,7 @@ char *
|
||||
host_memory_backend_get_name(HostMemoryBackend *backend)
|
||||
{
|
||||
if (!backend->use_canonical_path) {
|
||||
return object_get_canonical_path_component(OBJECT(backend));
|
||||
return g_strdup(object_get_canonical_path_component(OBJECT(backend)));
|
||||
}
|
||||
|
||||
return object_get_canonical_path(OBJECT(backend));
|
||||
|
@ -771,7 +771,7 @@ static void throttle_group_obj_complete(UserCreatable *obj, Error **errp)
|
||||
|
||||
/* set group name to object id if it exists */
|
||||
if (!tg->name && tg->parent_obj.parent) {
|
||||
tg->name = object_get_canonical_path_component(OBJECT(obj));
|
||||
tg->name = g_strdup(object_get_canonical_path_component(OBJECT(obj)));
|
||||
}
|
||||
/* We must have a group name at this point */
|
||||
assert(tg->name);
|
||||
|
@ -2059,7 +2059,7 @@ static void handle_query_thread_extra(GdbCmdContext *gdb_ctx, void *user_ctx)
|
||||
/* Print the CPU model and name in multiprocess mode */
|
||||
ObjectClass *oc = object_get_class(OBJECT(cpu));
|
||||
const char *cpu_model = object_class_get_name(oc);
|
||||
g_autofree char *cpu_name =
|
||||
const char *cpu_name =
|
||||
object_get_canonical_path_component(OBJECT(cpu));
|
||||
g_string_printf(rs, "%s %s [%s]", cpu_model, cpu_name,
|
||||
cpu->halted ? "halted " : "running");
|
||||
|
@ -190,7 +190,7 @@ static void xlnx_zynqmp_create_rpu(MachineState *ms, XlnxZynqMPState *s,
|
||||
qdev_prop_set_uint32(DEVICE(&s->rpu_cluster), "cluster-id", 1);
|
||||
|
||||
for (i = 0; i < num_rpus; i++) {
|
||||
char *name;
|
||||
const char *name;
|
||||
|
||||
object_initialize_child(OBJECT(&s->rpu_cluster), "rpu-cpu[*]",
|
||||
&s->rpu_cpu[i],
|
||||
@ -204,7 +204,6 @@ static void xlnx_zynqmp_create_rpu(MachineState *ms, XlnxZynqMPState *s,
|
||||
} else {
|
||||
s->boot_cpu_ptr = &s->rpu_cpu[i];
|
||||
}
|
||||
g_free(name);
|
||||
|
||||
object_property_set_bool(OBJECT(&s->rpu_cpu[i]), "reset-hivecs", true,
|
||||
&error_abort);
|
||||
@ -341,7 +340,7 @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp)
|
||||
|
||||
/* Realize APUs before realizing the GIC. KVM requires this. */
|
||||
for (i = 0; i < num_apus; i++) {
|
||||
char *name;
|
||||
const char *name;
|
||||
|
||||
object_property_set_int(OBJECT(&s->apu_cpu[i]), "psci-conduit",
|
||||
QEMU_PSCI_CONDUIT_SMC, &error_abort);
|
||||
@ -354,7 +353,6 @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp)
|
||||
} else {
|
||||
s->boot_cpu_ptr = &s->apu_cpu[i];
|
||||
}
|
||||
g_free(name);
|
||||
|
||||
object_property_set_bool(OBJECT(&s->apu_cpu[i]), "has_el3", s->secure,
|
||||
NULL);
|
||||
|
@ -1397,9 +1397,8 @@ static void nvme_check_constraints(NvmeCtrl *n, Error **errp)
|
||||
|
||||
if (!n->params.cmb_size_mb && n->pmrdev) {
|
||||
if (host_memory_backend_is_mapped(n->pmrdev)) {
|
||||
char *path = object_get_canonical_path_component(OBJECT(n->pmrdev));
|
||||
error_setg(errp, "can't use already busy memdev: %s", path);
|
||||
g_free(path);
|
||||
error_setg(errp, "can't use already busy memdev: %s",
|
||||
object_get_canonical_path_component(OBJECT(n->pmrdev)));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -315,7 +315,7 @@ static int query_memdev(Object *obj, void *opaque)
|
||||
|
||||
m->value = g_malloc0(sizeof(*m->value));
|
||||
|
||||
m->value->id = object_get_canonical_path_component(obj);
|
||||
m->value->id = g_strdup(object_get_canonical_path_component(obj));
|
||||
m->value->has_id = !!m->value->id;
|
||||
|
||||
m->value->size = object_property_get_uint(obj, "size",
|
||||
|
@ -1073,9 +1073,8 @@ MemoryRegion *machine_consume_memdev(MachineState *machine,
|
||||
MemoryRegion *ret = host_memory_backend_get_memory(backend);
|
||||
|
||||
if (memory_region_is_mapped(ret)) {
|
||||
char *path = object_get_canonical_path_component(OBJECT(backend));
|
||||
error_report("memory backend %s can't be used multiple times.", path);
|
||||
g_free(path);
|
||||
error_report("memory backend %s can't be used multiple times.",
|
||||
object_get_canonical_path_component(OBJECT(backend)));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
host_memory_backend_set_mapped(backend, true);
|
||||
|
@ -137,13 +137,12 @@ static void nvdimm_prepare_memory_region(NVDIMMDevice *nvdimm, Error **errp)
|
||||
|
||||
if (size <= nvdimm->label_size || !pmem_size) {
|
||||
HostMemoryBackend *hostmem = dimm->hostmem;
|
||||
char *path = object_get_canonical_path_component(OBJECT(hostmem));
|
||||
|
||||
error_setg(errp, "the size of memdev %s (0x%" PRIx64 ") is too "
|
||||
"small to contain nvdimm label (0x%" PRIx64 ") and "
|
||||
"aligned PMEM (0x%" PRIx64 ")",
|
||||
path, memory_region_size(mr), nvdimm->label_size, align);
|
||||
g_free(path);
|
||||
object_get_canonical_path_component(OBJECT(hostmem)),
|
||||
memory_region_size(mr), nvdimm->label_size, align);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -179,9 +179,8 @@ static void pc_dimm_realize(DeviceState *dev, Error **errp)
|
||||
error_setg(errp, "'" PC_DIMM_MEMDEV_PROP "' property is not set");
|
||||
return;
|
||||
} else if (host_memory_backend_is_mapped(dimm->hostmem)) {
|
||||
char *path = object_get_canonical_path_component(OBJECT(dimm->hostmem));
|
||||
error_setg(errp, "can't use already busy memdev: %s", path);
|
||||
g_free(path);
|
||||
error_setg(errp, "can't use already busy memdev: %s",
|
||||
object_get_canonical_path_component(OBJECT(dimm->hostmem)));
|
||||
return;
|
||||
}
|
||||
if (((nb_numa_nodes > 0) && (dimm->node >= nb_numa_nodes)) ||
|
||||
|
@ -1037,9 +1037,8 @@ static void ivshmem_plain_realize(PCIDevice *dev, Error **errp)
|
||||
error_setg(errp, "You must specify a 'memdev'");
|
||||
return;
|
||||
} else if (host_memory_backend_is_mapped(s->hostmem)) {
|
||||
char *path = object_get_canonical_path_component(OBJECT(s->hostmem));
|
||||
error_setg(errp, "can't use already busy memdev: %s", path);
|
||||
g_free(path);
|
||||
error_setg(errp, "can't use already busy memdev: %s",
|
||||
object_get_canonical_path_component(OBJECT(s->hostmem)));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -513,7 +513,7 @@ static void realize(DeviceState *d, Error **errp)
|
||||
SpaprDrc *drc = SPAPR_DR_CONNECTOR(d);
|
||||
Object *root_container;
|
||||
gchar *link_name;
|
||||
char *child_name;
|
||||
const char *child_name;
|
||||
|
||||
trace_spapr_drc_realize(spapr_drc_index(drc));
|
||||
/* NOTE: we do this as part of realize/unrealize due to the fact
|
||||
@ -529,7 +529,6 @@ static void realize(DeviceState *d, Error **errp)
|
||||
trace_spapr_drc_realize_child(spapr_drc_index(drc), child_name);
|
||||
object_property_add_alias(root_container, link_name,
|
||||
drc->owner, child_name);
|
||||
g_free(child_name);
|
||||
g_free(link_name);
|
||||
vmstate_register(VMSTATE_IF(drc), spapr_drc_index(drc), &vmstate_spapr_drc,
|
||||
drc);
|
||||
|
@ -57,7 +57,7 @@ spapr_drc_detach(uint32_t index) "drc: 0x%"PRIx32
|
||||
spapr_drc_awaiting_quiesce(uint32_t index) "drc: 0x%"PRIx32
|
||||
spapr_drc_reset(uint32_t index) "drc: 0x%"PRIx32
|
||||
spapr_drc_realize(uint32_t index) "drc: 0x%"PRIx32
|
||||
spapr_drc_realize_child(uint32_t index, char *childname) "drc: 0x%"PRIx32", child name: %s"
|
||||
spapr_drc_realize_child(uint32_t index, const char *childname) "drc: 0x%"PRIx32", child name: %s"
|
||||
spapr_drc_realize_complete(uint32_t index) "drc: 0x%"PRIx32
|
||||
spapr_drc_unrealize(uint32_t index) "drc: 0x%"PRIx32
|
||||
|
||||
|
@ -786,9 +786,8 @@ static void virtio_crypto_device_realize(DeviceState *dev, Error **errp)
|
||||
error_setg(errp, "'cryptodev' parameter expects a valid object");
|
||||
return;
|
||||
} else if (cryptodev_backend_is_used(vcrypto->cryptodev)) {
|
||||
char *path = object_get_canonical_path_component(OBJECT(vcrypto->conf.cryptodev));
|
||||
error_setg(errp, "can't use already used cryptodev backend: %s", path);
|
||||
g_free(path);
|
||||
error_setg(errp, "can't use already used cryptodev backend: %s",
|
||||
object_get_canonical_path_component(OBJECT(vcrypto->conf.cryptodev)));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -409,11 +409,9 @@ static void virtio_mem_device_realize(DeviceState *dev, Error **errp)
|
||||
error_setg(errp, "'%s' property is not set", VIRTIO_MEM_MEMDEV_PROP);
|
||||
return;
|
||||
} else if (host_memory_backend_is_mapped(vmem->memdev)) {
|
||||
char *path = object_get_canonical_path_component(OBJECT(vmem->memdev));
|
||||
|
||||
error_setg(errp, "'%s' property specifies a busy memdev: %s",
|
||||
VIRTIO_MEM_MEMDEV_PROP, path);
|
||||
g_free(path);
|
||||
VIRTIO_MEM_MEMDEV_PROP,
|
||||
object_get_canonical_path_component(OBJECT(vmem->memdev)));
|
||||
return;
|
||||
} else if (!memory_region_is_ram(&vmem->memdev->mr) ||
|
||||
memory_region_is_rom(&vmem->memdev->mr) ||
|
||||
|
@ -112,9 +112,8 @@ static void virtio_pmem_realize(DeviceState *dev, Error **errp)
|
||||
}
|
||||
|
||||
if (host_memory_backend_is_mapped(pmem->memdev)) {
|
||||
char *path = object_get_canonical_path_component(OBJECT(pmem->memdev));
|
||||
error_setg(errp, "can't use already busy memdev: %s", path);
|
||||
g_free(path);
|
||||
error_setg(errp, "can't use already busy memdev: %s",
|
||||
object_get_canonical_path_component(OBJECT(pmem->memdev)));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1462,7 +1462,7 @@ Object *object_get_internal_root(void);
|
||||
* path is the path within the composition tree starting from the root.
|
||||
* %NULL if the object doesn't have a parent (and thus a canonical path).
|
||||
*/
|
||||
char *object_get_canonical_path_component(const Object *obj);
|
||||
const char *object_get_canonical_path_component(const Object *obj);
|
||||
|
||||
/**
|
||||
* object_get_canonical_path:
|
||||
|
@ -165,7 +165,7 @@ static void iothread_complete(UserCreatable *obj, Error **errp)
|
||||
{
|
||||
Error *local_error = NULL;
|
||||
IOThread *iothread = IOTHREAD(obj);
|
||||
char *name, *thread_name;
|
||||
char *thread_name;
|
||||
|
||||
iothread->stopping = false;
|
||||
iothread->running = true;
|
||||
@ -195,12 +195,11 @@ static void iothread_complete(UserCreatable *obj, Error **errp)
|
||||
/* This assumes we are called from a thread with useful CPU affinity for us
|
||||
* to inherit.
|
||||
*/
|
||||
name = object_get_canonical_path_component(OBJECT(obj));
|
||||
thread_name = g_strdup_printf("IO %s", name);
|
||||
thread_name = g_strdup_printf("IO %s",
|
||||
object_get_canonical_path_component(OBJECT(obj)));
|
||||
qemu_thread_create(&iothread->thread, thread_name, iothread_run,
|
||||
iothread, QEMU_THREAD_JOINABLE);
|
||||
g_free(thread_name);
|
||||
g_free(name);
|
||||
|
||||
/* Wait for initialization to complete */
|
||||
while (iothread->thread_id == -1) {
|
||||
@ -303,7 +302,7 @@ type_init(iothread_register_types)
|
||||
|
||||
char *iothread_get_id(IOThread *iothread)
|
||||
{
|
||||
return object_get_canonical_path_component(OBJECT(iothread));
|
||||
return g_strdup(object_get_canonical_path_component(OBJECT(iothread)));
|
||||
}
|
||||
|
||||
AioContext *iothread_get_aio_context(IOThread *iothread)
|
||||
|
@ -1185,12 +1185,10 @@ void print_net_client(Monitor *mon, NetClientState *nc)
|
||||
monitor_printf(mon, "filters:\n");
|
||||
}
|
||||
QTAILQ_FOREACH(nf, &nc->filters, next) {
|
||||
char *path = object_get_canonical_path_component(OBJECT(nf));
|
||||
|
||||
monitor_printf(mon, " - %s: type=%s", path,
|
||||
monitor_printf(mon, " - %s: type=%s",
|
||||
object_get_canonical_path_component(OBJECT(nf)),
|
||||
object_get_typename(OBJECT(nf)));
|
||||
netfilter_print_info(mon, nf);
|
||||
g_free(path);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1931,7 +1931,7 @@ object_property_add_const_link(Object *obj, const char *name,
|
||||
NULL, OBJ_PROP_LINK_DIRECT);
|
||||
}
|
||||
|
||||
char *object_get_canonical_path_component(const Object *obj)
|
||||
const char *object_get_canonical_path_component(const Object *obj)
|
||||
{
|
||||
ObjectProperty *prop = NULL;
|
||||
GHashTableIter iter;
|
||||
@ -1947,7 +1947,7 @@ char *object_get_canonical_path_component(const Object *obj)
|
||||
}
|
||||
|
||||
if (prop->opaque == obj) {
|
||||
return g_strdup(prop->name);
|
||||
return prop->name;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1966,7 +1966,7 @@ char *object_get_canonical_path(const Object *obj)
|
||||
}
|
||||
|
||||
do {
|
||||
char *component = object_get_canonical_path_component(obj);
|
||||
const char *component = object_get_canonical_path_component(obj);
|
||||
|
||||
if (!component) {
|
||||
/* A canonical path must be complete, so discard what was
|
||||
@ -1978,7 +1978,6 @@ char *object_get_canonical_path(const Object *obj)
|
||||
|
||||
newpath = g_strdup_printf("/%s%s", component, path ? path : "");
|
||||
g_free(path);
|
||||
g_free(component);
|
||||
path = newpath;
|
||||
obj = obj->parent;
|
||||
} while (obj != root);
|
||||
|
@ -96,10 +96,8 @@ static void print_qom_composition(Monitor *mon, Object *obj, int indent);
|
||||
|
||||
static int qom_composition_compare(const void *a, const void *b, void *ignore)
|
||||
{
|
||||
g_autofree char *ac = object_get_canonical_path_component(a);
|
||||
g_autofree char *bc = object_get_canonical_path_component(b);
|
||||
|
||||
return g_strcmp0(ac, bc);
|
||||
return g_strcmp0(object_get_canonical_path_component(a),
|
||||
object_get_canonical_path_component(b));
|
||||
}
|
||||
|
||||
static int insert_qom_composition_child(Object *obj, void *opaque)
|
||||
@ -112,18 +110,17 @@ static int insert_qom_composition_child(Object *obj, void *opaque)
|
||||
|
||||
static void print_qom_composition(Monitor *mon, Object *obj, int indent)
|
||||
{
|
||||
char *name;
|
||||
const char *name;
|
||||
GQueue children;
|
||||
Object *child;
|
||||
|
||||
if (obj == object_get_root()) {
|
||||
name = g_strdup("");
|
||||
name = "";
|
||||
} else {
|
||||
name = object_get_canonical_path_component(obj);
|
||||
}
|
||||
monitor_printf(mon, "%*s/%s (%s)\n", indent, "", name,
|
||||
object_get_typename(obj));
|
||||
g_free(name);
|
||||
|
||||
g_queue_init(&children);
|
||||
object_child_foreach(obj, insert_qom_composition_child, &children);
|
||||
|
@ -42,11 +42,10 @@ typedef struct PRManagerHelper {
|
||||
|
||||
static void pr_manager_send_status_changed_event(PRManagerHelper *pr_mgr)
|
||||
{
|
||||
char *id = object_get_canonical_path_component(OBJECT(pr_mgr));
|
||||
const char *id = object_get_canonical_path_component(OBJECT(pr_mgr));
|
||||
|
||||
if (id) {
|
||||
qapi_event_send_pr_manager_status_changed(id, !!pr_mgr->ioc);
|
||||
g_free(id);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -128,7 +128,7 @@ static int query_one_pr_manager(Object *object, void *opaque)
|
||||
|
||||
elem = g_new0(PRManagerInfoList, 1);
|
||||
info = g_new0(PRManagerInfo, 1);
|
||||
info->id = object_get_canonical_path_component(object);
|
||||
info->id = g_strdup(object_get_canonical_path_component(object));
|
||||
info->connected = pr_manager_is_connected(pr_mgr);
|
||||
elem->value = info;
|
||||
elem->next = NULL;
|
||||
|
@ -1764,7 +1764,7 @@ const char *memory_region_name(const MemoryRegion *mr)
|
||||
{
|
||||
if (!mr->name) {
|
||||
((MemoryRegion *)mr)->name =
|
||||
object_get_canonical_path_component(OBJECT(mr));
|
||||
g_strdup(object_get_canonical_path_component(OBJECT(mr)));
|
||||
}
|
||||
return mr->name;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user