* [PATCH] virtio: mmio: Return error codes on probe failures
@ 2026-04-07 9:49 Kuan-Wei Chiu
2026-04-07 10:17 ` Daniel Palmer
0 siblings, 1 reply; 2+ messages in thread
From: Kuan-Wei Chiu @ 2026-04-07 9:49 UTC (permalink / raw)
To: bmeng.cn, trini
Cc: tuomas.tynkkynen, sjg, daniel, jserv, eleanor15x, u-boot,
Kuan-Wei Chiu
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>
---
drivers/virtio/virtio_mmio.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
index 1cd737aca24..62afe609ec0 100644
--- a/drivers/virtio/virtio_mmio.c
+++ b/drivers/virtio/virtio_mmio.c
@@ -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);
--
2.53.0.1213.gd9a14994de-goog
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] virtio: mmio: Return error codes on probe failures
2026-04-07 9:49 [PATCH] virtio: mmio: Return error codes on probe failures Kuan-Wei Chiu
@ 2026-04-07 10:17 ` Daniel Palmer
0 siblings, 0 replies; 2+ messages in thread
From: Daniel Palmer @ 2026-04-07 10:17 UTC (permalink / raw)
To: Kuan-Wei Chiu
Cc: bmeng.cn, trini, tuomas.tynkkynen, sjg, jserv, eleanor15x, u-boot
Hi Kuan-Wei,
On Tue, 7 Apr 2026 at 18:49, Kuan-Wei Chiu <visitorckw@gmail.com> wrote:
>
> 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>
> ---
> drivers/virtio/virtio_mmio.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
> index 1cd737aca24..62afe609ec0 100644
> --- a/drivers/virtio/virtio_mmio.c
> +++ b/drivers/virtio/virtio_mmio.c
> @@ -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);
>
> --
> 2.53.0.1213.gd9a14994de-goog
>
I'm surprised I didn't notice this when working out the endian issues on m68k.
I have build/boot tested on m68k and the change looks correct to me.
Since I'm not the maintainer for this thing I guess:
Acked-by: Daniel Palmer <daniel@thingy.jp>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-04-07 10:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-07 9:49 [PATCH] virtio: mmio: Return error codes on probe failures Kuan-Wei Chiu
2026-04-07 10:17 ` Daniel Palmer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox