]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
hw/qdev: Consolidate qdev_get_printable_name() into qdev_get_human_name()
authorAlessandro Ratti <alessandro@0x65c.net>
Sat, 21 Mar 2026 10:04:05 +0000 (11:04 +0100)
committerPaolo Bonzini <pbonzini@redhat.com>
Thu, 30 Apr 2026 15:55:03 +0000 (17:55 +0200)
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>
hw/core/qdev.c
hw/virtio/virtio.c
include/hw/core/qdev.h

index 0efc83f67407fc97eceedd1cc0bcc1fc5e2f4b29..e2aab3d1fc61246ba2f1e147c0ff71c7c7712c55 100644 (file)
@@ -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)
index 8fcf6cfd0b43263cd53975b88c035a2492dccc57..63e2faee99438232ac39d2cea1e00ec586de0034 100644 (file)
@@ -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: "
index 226bd66290117a27566628e83311d524820ab2a7..e147622341151c110e22695d26d8a0600355322c 100644 (file)
@@ -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);