[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 22/26] bus: simplify name handling
From: |
Marc-André Lureau |
Subject: |
[Qemu-devel] [PULL 22/26] bus: simplify name handling |
Date: |
Tue, 6 Sep 2016 16:26:35 +0400 |
Simplify a bit the code by using g_strdup_printf() and store it in a
non-const value so casting is no longer needed, and ownership is
clearer.
Signed-off-by: Marc-André Lureau <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
---
hw/core/bus.c | 21 ++++++---------------
include/hw/qdev-core.h | 2 +-
2 files changed, 7 insertions(+), 16 deletions(-)
diff --git a/hw/core/bus.c b/hw/core/bus.c
index 3e3f8ac..cf383fc 100644
--- a/hw/core/bus.c
+++ b/hw/core/bus.c
@@ -78,8 +78,7 @@ static void qbus_realize(BusState *bus, DeviceState *parent,
const char *name)
{
const char *typename = object_get_typename(OBJECT(bus));
BusClass *bc;
- char *buf;
- int i, len, bus_id;
+ int i, bus_id;
bus->parent = parent;
@@ -88,23 +87,15 @@ static void qbus_realize(BusState *bus, DeviceState
*parent, const char *name)
} else if (bus->parent && bus->parent->id) {
/* parent device has id -> use it plus parent-bus-id for bus name */
bus_id = bus->parent->num_child_bus;
-
- len = strlen(bus->parent->id) + 16;
- buf = g_malloc(len);
- snprintf(buf, len, "%s.%d", bus->parent->id, bus_id);
- bus->name = buf;
+ bus->name = g_strdup_printf("%s.%d", bus->parent->id, bus_id);
} else {
/* no id -> use lowercase bus type plus global bus-id for bus name */
bc = BUS_GET_CLASS(bus);
bus_id = bc->automatic_ids++;
-
- len = strlen(typename) + 16;
- buf = g_malloc(len);
- len = snprintf(buf, len, "%s.%d", typename, bus_id);
- for (i = 0; i < len; i++) {
- buf[i] = qemu_tolower(buf[i]);
+ bus->name = g_strdup_printf("%s.%d", typename, bus_id);
+ for (i = 0; bus->name[i]; i++) {
+ bus->name[i] = qemu_tolower(bus->name[i]);
}
- bus->name = buf;
}
if (bus->parent) {
@@ -229,7 +220,7 @@ static void qbus_finalize(Object *obj)
{
BusState *bus = BUS(obj);
- g_free((char *)bus->name);
+ g_free(bus->name);
}
static const TypeInfo bus_info = {
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index 4b4b33b..2c97347 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -224,7 +224,7 @@ typedef struct BusChild {
struct BusState {
Object obj;
DeviceState *parent;
- const char *name;
+ char *name;
HotplugHandler *hotplug_handler;
int max_index;
bool realized;
--
2.10.0
- [Qemu-devel] [PULL 12/26] portio: keep references on portio, (continued)
- [Qemu-devel] [PULL 12/26] portio: keep references on portio, Marc-André Lureau, 2016/09/06
- [Qemu-devel] [PULL 13/26] pc: simplify passing qemu_irq, Marc-André Lureau, 2016/09/06
- [Qemu-devel] [PULL 14/26] pc: don't leak a20_line, Marc-André Lureau, 2016/09/06
- [Qemu-devel] [PULL 16/26] acpi-build: fix array leak, Marc-André Lureau, 2016/09/06
- [Qemu-devel] [PULL 15/26] machine: use class base init generated name, Marc-André Lureau, 2016/09/06
- [Qemu-devel] [PULL 17/26] tests: fix qom-test leaks, Marc-André Lureau, 2016/09/06
- [Qemu-devel] [PULL 18/26] pc: free i8259, Marc-André Lureau, 2016/09/06
- [Qemu-devel] [PULL 19/26] pc: keep gsi reference, Marc-André Lureau, 2016/09/06
- [Qemu-devel] [PULL 20/26] sd: free timer, Marc-André Lureau, 2016/09/06
- [Qemu-devel] [PULL 21/26] ipmi: free extern timer, Marc-André Lureau, 2016/09/06
- [Qemu-devel] [PULL 22/26] bus: simplify name handling,
Marc-André Lureau <=
- [Qemu-devel] [PULL 23/26] tests: add qtest_add_data_func_full, Marc-André Lureau, 2016/09/06
- [Qemu-devel] [PULL 24/26] tests: pc-cpu-test leaks fixes, Marc-André Lureau, 2016/09/06
- [Qemu-devel] [PULL 25/26] tests: fix rsp leak in postcopy-test, Marc-André Lureau, 2016/09/06
- [Qemu-devel] [PULL 26/26] tests: fix postcopy-test leaks, Marc-André Lureau, 2016/09/06
- Re: [Qemu-devel] [PULL 00/26] Leak patches, Peter Maydell, 2016/09/06