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 <peter.maydell@linaro.org> Signed-off-by: Alessandro Ratti <alessandro@0x65c.net> Reviewed-by: Markus Armbruster <armbru@redhat.com> Link: https://lore.kernel.org/r/20260321100405.1525059-4-alessandro@0x65c.net Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 0efc83f..e2aab3d 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c
@@ -412,7 +412,7 @@ 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 @@ 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 8fcf6cf..63e2fae 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c
@@ -281,7 +281,7 @@ 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 @@ 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 @@ 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 226bd66..e147622 100644 --- a/include/hw/core/qdev.h +++ b/include/hw/core/qdev.h
@@ -1022,13 +1022,12 @@ * 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 suitable for user-facing error + * messages. * - * Returns: A newly allocated string containing the device id if not null, - * else the object canonical path. - * - * 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 @@ */ 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);