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

index b36101f3a75b9076af6781fea7b6fe30137b2941..78156185d57ae20ea495f0817491a5b819d67963 100644 (file)
@@ -412,33 +412,21 @@ char *qdev_get_dev_path(DeviceState *dev)
     return NULL;
 }
 
-const char *qdev_get_printable_name(DeviceState *vdev)
+const char *qdev_get_printable_name(DeviceState *dev)
 {
-    /*
-     * Return device ID if explicity set
-     * (e.g. -device virtio-blk-pci,id=foo)
-     * This allows users to correlate errors with their custom device
-     * names.
-     */
-    if (vdev->id) {
-        return g_strdup(vdev->id);
+    if (dev->id) {
+        return g_strdup(dev->id);
     }
     /*
-     * Fall back to the canonical QOM device path (eg. ID for PCI
-     * devices).
-     * This ensures the device is still uniquely and meaningfully
-     * identified.
+     * Fall back to a bus-specific device path, if the bus
+     * provides one (e.g. PCI address "0000:00:04.0").
      */
-    const char *path = qdev_get_dev_path(vdev);
+    const char *path = qdev_get_dev_path(dev);
     if (path) {
         return path;
     }
 
-    /*
-     * Final fallback: if all else fails, return a placeholder string.
-     * This ensures the error message always contains a valid string.
-     */
-    return g_strdup("<unknown device>");
+    return object_get_canonical_path(OBJECT(dev));
 }
 
 void qdev_add_unplug_blocker(DeviceState *dev, Error *reason)
index 337d69ea2c38ae137f1392408d11543e3942bb18..226bd66290117a27566628e83311d524820ab2a7 100644 (file)
@@ -1067,11 +1067,9 @@ char *qdev_get_dev_path(DeviceState *dev);
  * user-facing error messages. The function will never return NULL,
  * so the name can be used without further checking or fallbacks.
  *
- * If the device has an explicitly set ID (e.g. by the user on the
- * command line via "-device thisdev,id=myid") this is preferred.
- * Otherwise we try the canonical QOM device path (which will be
- * the PCI ID for PCI devices, for example). If all else fails
- * we will return the placeholder "<unknown device">.
+ * 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);