summaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2016-07-15 12:04:49 +0200
committerMarc-André Lureau <marcandre.lureau@redhat.com>2016-09-08 18:05:22 +0400
commitf73480c36f49562556b80bb5bf8acc45e20dcca1 (patch)
tree9d102ca71a9ba4abb14c01b3ce7a9fd2098b74b1 /hw
parente9529768d4786414725a9675991aeb466a6d600c (diff)
downloadqemu-f73480c36f49562556b80bb5bf8acc45e20dcca1.tar.gz
qemu-f73480c36f49562556b80bb5bf8acc45e20dcca1.tar.bz2
qemu-f73480c36f49562556b80bb5bf8acc45e20dcca1.zip
bus: simplify name handling
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 <marcandre.lureau@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'hw')
-rw-r--r--hw/core/bus.c21
1 files changed, 6 insertions, 15 deletions
diff --git a/hw/core/bus.c b/hw/core/bus.c
index 3e3f8ac740..cf383fc1af 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 = {