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 <[email protected]> Signed-off-by: Alessandro Ratti <[email protected]> --- hw/core/qdev.c | 10 +--------- hw/virtio/virtio.c | 6 +++--- include/hw/core/qdev.h | 26 +++++--------------------- 3 files changed, 9 insertions(+), 33 deletions(-) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 904e710f8e..93347f67bb 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -411,7 +411,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); @@ -857,14 +857,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 8fcf6cfd0b..63e2faee99 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 b87497906a..43d8e58432 100644 --- a/include/hw/core/qdev.h +++ b/include/hw/core/qdev.h @@ -1049,13 +1049,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); @@ -1085,21 +1084,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); -- 2.53.0
