From: Alessandro Ratti Date: Sat, 21 Mar 2026 10:04:05 +0000 (+0100) Subject: hw/qdev: Consolidate qdev_get_printable_name() into qdev_get_human_name() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3d2a02f42d7e2550951c4e5c8bfac856efe20525;p=thirdparty%2Fqemu.git hw/qdev: Consolidate qdev_get_printable_name() into qdev_get_human_name() Rename qdev_get_printable_name() to qdev_get_human_name(), remove the old qdev_get_human_name() implementation, and switch the three qdev_get_printable_name() callers in hw/virtio/virtio.c. qdev_get_printable_name() subsumes qdev_get_human_name(): both return the device ID when set and fall back to the canonical QOM path, but qdev_get_printable_name() also tries the bus-specific path first, providing more informative output. Suggested-by: Peter Maydell Signed-off-by: Alessandro Ratti Reviewed-by: Markus Armbruster Link: https://lore.kernel.org/r/20260321100405.1525059-4-alessandro@0x65c.net Signed-off-by: Paolo Bonzini --- diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 0efc83f6740..e2aab3d1fc6 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -412,7 +412,7 @@ char *qdev_get_dev_path(DeviceState *dev) return NULL; } -const char *qdev_get_printable_name(DeviceState *dev) +char *qdev_get_human_name(DeviceState *dev) { if (dev->id) { return g_strdup(dev->id); @@ -858,14 +858,6 @@ Object *machine_get_container(const char *name) return container; } -char *qdev_get_human_name(DeviceState *dev) -{ - g_assert(dev != NULL); - - return dev->id ? - g_strdup(dev->id) : object_get_canonical_path(OBJECT(dev)); -} - static MachineInitPhase machine_phase; bool phase_check(MachineInitPhase phase) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 8fcf6cfd0b4..63e2faee994 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -281,7 +281,7 @@ void virtio_init_region_cache(VirtIODevice *vdev, int n) len = address_space_cache_init(&new->desc, vdev->dma_as, addr, size, packed); if (len < size) { - g_autofree const char *devname = qdev_get_printable_name(DEVICE(vdev)); + g_autofree char *devname = qdev_get_human_name(DEVICE(vdev)); virtio_error(vdev, "Failed to map descriptor ring for device %s: " @@ -294,7 +294,7 @@ void virtio_init_region_cache(VirtIODevice *vdev, int n) len = address_space_cache_init(&new->used, vdev->dma_as, vq->vring.used, size, true); if (len < size) { - g_autofree const char *devname = qdev_get_printable_name(DEVICE(vdev)); + g_autofree char *devname = qdev_get_human_name(DEVICE(vdev)); virtio_error(vdev, "Failed to map used ring for device %s: " @@ -307,7 +307,7 @@ void virtio_init_region_cache(VirtIODevice *vdev, int n) len = address_space_cache_init(&new->avail, vdev->dma_as, vq->vring.avail, size, false); if (len < size) { - g_autofree const char *devname = qdev_get_printable_name(DEVICE(vdev)); + g_autofree char *devname = qdev_get_human_name(DEVICE(vdev)); virtio_error(vdev, "Failed to map avalaible ring for device %s: " diff --git a/include/hw/core/qdev.h b/include/hw/core/qdev.h index 226bd662901..e1476223411 100644 --- a/include/hw/core/qdev.h +++ b/include/hw/core/qdev.h @@ -1022,13 +1022,12 @@ Object *machine_get_container(const char *name); * qdev_get_human_name() - Return a human-readable name for a device * @dev: The device. Must be a valid and non-NULL pointer. * - * .. note:: - * This function is intended for user friendly error messages. - * - * Returns: A newly allocated string containing the device id if not null, - * else the object canonical path. + * Returns: A newly allocated string suitable for user-facing error + * messages. * - * Use g_free() to free it. + * Return the device's ID if it has one. Else, return the path of a + * device on its bus if it has one. Else return its canonical QOM + * path. */ char *qdev_get_human_name(DeviceState *dev); @@ -1058,21 +1057,6 @@ extern bool qdev_hot_removed; */ char *qdev_get_dev_path(DeviceState *dev); -/** - * qdev_get_printable_name: Return human readable name for device - * @dev: Device to get name of - * - * Returns: A newly allocated string containing some human - * readable name for the device, suitable for printing in - * user-facing error messages. The function will never return NULL, - * so the name can be used without further checking or fallbacks. - * - * Return the device's ID if it has one. Else, return the path of a - * device on its bus if it has one. Else return its canonical QOM - * path. - */ -const char *qdev_get_printable_name(DeviceState *dev); - void qbus_set_hotplug_handler(BusState *bus, Object *handler); void qbus_set_bus_hotplug_handler(BusState *bus);