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>
Alessandro Ratti committed
Mar 21, 2026 at 11:04 UTC
3d2a02f42d7e2550951c4e5c8bfac856efe20525
3 files changed
+9
-33
hw/core/qdev.c
+1
-9
@@ -412,7 +412,7 @@ char *qdev_get_dev_path(DeviceState *dev)
412
return NULL;
413
}
414
415
-const char *qdev_get_printable_name(DeviceState *dev)
415
+char *qdev_get_human_name(DeviceState *dev)
416
{
417
if (dev->id) {
418
return g_strdup(dev->id);
@@ -858,14 +858,6 @@ Object *machine_get_container(const char *name)
858
return container;
859
}
860
861
-char *qdev_get_human_name(DeviceState *dev)
862
-{
863
- g_assert(dev != NULL);
864
-
865
- return dev->id ?
866
- g_strdup(dev->id) : object_get_canonical_path(OBJECT(dev));
867
-}
868
-
861
static MachineInitPhase machine_phase;
862
863
bool phase_check(MachineInitPhase phase)
hw/virtio/virtio.c
+3
-3
@@ -281,7 +281,7 @@ void virtio_init_region_cache(VirtIODevice *vdev, int n)
281
len = address_space_cache_init(&new->desc, vdev->dma_as,
282
addr, size, packed);
283
if (len < size) {
284
- g_autofree const char *devname = qdev_get_printable_name(DEVICE(vdev));
284
+ g_autofree char *devname = qdev_get_human_name(DEVICE(vdev));
285
286
virtio_error(vdev,
287
"Failed to map descriptor ring for device %s: "
@@ -294,7 +294,7 @@ void virtio_init_region_cache(VirtIODevice *vdev, int n)
294
len = address_space_cache_init(&new->used, vdev->dma_as,
295
vq->vring.used, size, true);
296
if (len < size) {
297
- g_autofree const char *devname = qdev_get_printable_name(DEVICE(vdev));
297
+ g_autofree char *devname = qdev_get_human_name(DEVICE(vdev));
298
299
virtio_error(vdev,
300
"Failed to map used ring for device %s: "
@@ -307,7 +307,7 @@ void virtio_init_region_cache(VirtIODevice *vdev, int n)
307
len = address_space_cache_init(&new->avail, vdev->dma_as,
308
vq->vring.avail, size, false);
309
if (len < size) {
310
- g_autofree const char *devname = qdev_get_printable_name(DEVICE(vdev));
310
+ g_autofree char *devname = qdev_get_human_name(DEVICE(vdev));
311
312
virtio_error(vdev,
313
"Failed to map avalaible ring for device %s: "
include/hw/core/qdev.h
+5
-21
@@ -1022,13 +1022,12 @@ Object *machine_get_container(const char *name);
1022
* qdev_get_human_name() - Return a human-readable name for a device
1023
* @dev: The device. Must be a valid and non-NULL pointer.
1024
*
1025
- * .. note::
1026
- * This function is intended for user friendly error messages.
1027
- *
1028
- * Returns: A newly allocated string containing the device id if not null,
1029
- * else the object canonical path.
1025
+ * Returns: A newly allocated string suitable for user-facing error
1026
+ * messages.
1027
*
1031
- * Use g_free() to free it.
1028
+ * Return the device's ID if it has one. Else, return the path of a
1029
+ * device on its bus if it has one. Else return its canonical QOM
1030
+ * path.
1031
*/
1032
char *qdev_get_human_name(DeviceState *dev);
1033
@@ -1058,21 +1057,6 @@ extern bool qdev_hot_removed;
1057
*/
1058
char *qdev_get_dev_path(DeviceState *dev);
1059
1061
-/**
1062
- * qdev_get_printable_name: Return human readable name for device
1063
- * @dev: Device to get name of
1064
- *
1065
- * Returns: A newly allocated string containing some human
1066
- * readable name for the device, suitable for printing in
1067
- * user-facing error messages. The function will never return NULL,
1068
- * so the name can be used without further checking or fallbacks.
1069
- *
1070
- * Return the device's ID if it has one. Else, return the path of a
1071
- * device on its bus if it has one. Else return its canonical QOM
1072
- * path.
1073
- */
1074
-const char *qdev_get_printable_name(DeviceState *dev);
1075
-
1060
void qbus_set_hotplug_handler(BusState *bus, Object *handler);
1061
void qbus_set_bus_hotplug_handler(BusState *bus);
1062