virtio: mmio: Return error codes on probe failures

Currently, virtio_mmio_probe() returns 0 when it encounters an invalid
magic value, an unsupported version, or a dummy device (ID 0). In
U-Boot's driver model, returning 0 indicates a successful probe. This
causes the system to incorrectly register and activate invalid or
placeholder devices, potentially leading to undefined behavior or
crashes later on.

Update the probe function to return appropriate error codes (-ENODEV
for invalid magic values and dummy devices, and -ENXIO for unsupported
versions). This fix correctly instructs the DM to abort the binding
process.

Fixes: fdc4aca89ecb ("virtio: Add virtio over mmio transport driver")
Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
Acked-by: Daniel Palmer <daniel@thingy.jp>
This commit is contained in:
Kuan-Wei Chiu 2026-04-07 09:49:00 +00:00 committed by Tom Rini
parent 7fbed708d9
commit 70101c3217

View File

@ -354,7 +354,7 @@ static int virtio_mmio_probe(struct udevice *udev)
magic = readl(priv->base + VIRTIO_MMIO_MAGIC_VALUE);
if (magic != ('v' | 'i' << 8 | 'r' << 16 | 't' << 24)) {
debug("(%s): wrong magic value 0x%08x!\n", udev->name, magic);
return 0;
return -ENODEV;
}
/* Check device version */
@ -362,7 +362,7 @@ static int virtio_mmio_probe(struct udevice *udev)
if (priv->version < 1 || priv->version > 2) {
debug("(%s): version %d not supported!\n",
udev->name, priv->version);
return 0;
return -ENXIO;
}
/* Check device ID */
@ -372,7 +372,7 @@ static int virtio_mmio_probe(struct udevice *udev)
* virtio-mmio device with an ID 0 is a (dummy) placeholder
* with no function. End probing now with no error reported.
*/
return 0;
return -ENODEV;
}
uc_priv->vendor = readl(priv->base + VIRTIO_MMIO_VENDOR_ID);