@samitouri / QOSamiQemu / commits / 0d2b113425

hw/qdev: Clarify fallback order in qdev_get_printable_name()

Replace the uninformative "<unknown device>" final fallback with the canonical QOM path (e.g. /machine/peripheral-anon/device[0]). Also clean up comments to accurately describe qdev_get_dev_path() behavior, drop an unnecessary comment on the dev->id check, and rename the @vdev parameter to @dev for consistency with surrounding code. Update the doc comment in qdev.h to reflect the new fallback chain. Signed-off-by: Alessandro Ratti <alessandro@0x65c.net> Reviewed-by: Markus Armbruster <armbru@redhat.com> Link: https://lore.kernel.org/r/20260321100405.1525059-2-alessandro@0x65c.net Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Alessandro Ratti committed Mar 21, 2026 at 11:04 UTC 0d2b1134255269a2ad042c4fcfe166d349097ea2
2 files changed +10 -24
hw/core/qdev.c
+7 -19
@@ -412,33 +412,21 @@ char *qdev_get_dev_path(DeviceState *dev)
412 return NULL;
413 }
414
415 -const char *qdev_get_printable_name(DeviceState *vdev)
415 +const char *qdev_get_printable_name(DeviceState *dev)
416 {
417 - /*
418 - * Return device ID if explicity set
419 - * (e.g. -device virtio-blk-pci,id=foo)
420 - * This allows users to correlate errors with their custom device
421 - * names.
422 - */
423 - if (vdev->id) {
424 - return g_strdup(vdev->id);
417 + if (dev->id) {
418 + return g_strdup(dev->id);
419 }
420 /*
427 - * Fall back to the canonical QOM device path (eg. ID for PCI
428 - * devices).
429 - * This ensures the device is still uniquely and meaningfully
430 - * identified.
421 + * Fall back to a bus-specific device path, if the bus
422 + * provides one (e.g. PCI address "0000:00:04.0").
423 */
432 - const char *path = qdev_get_dev_path(vdev);
424 + const char *path = qdev_get_dev_path(dev);
425 if (path) {
426 return path;
427 }
428
437 - /*
438 - * Final fallback: if all else fails, return a placeholder string.
439 - * This ensures the error message always contains a valid string.
440 - */
441 - return g_strdup("<unknown device>");
429 + return object_get_canonical_path(OBJECT(dev));
430 }
431
432 void qdev_add_unplug_blocker(DeviceState *dev, Error *reason)
include/hw/core/qdev.h
+3 -5
@@ -1067,11 +1067,9 @@ char *qdev_get_dev_path(DeviceState *dev);
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 - * If the device has an explicitly set ID (e.g. by the user on the
1071 - * command line via "-device thisdev,id=myid") this is preferred.
1072 - * Otherwise we try the canonical QOM device path (which will be
1073 - * the PCI ID for PCI devices, for example). If all else fails
1074 - * we will return the placeholder "<unknown device">.
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