From: Kuan-Wei Chiu <visitorckw@gmail.com>
To: bmeng.cn@gmail.com, trini@konsulko.com
Cc: tuomas.tynkkynen@iki.fi, sjg@chromium.org, daniel@thingy.jp,
jserv@ccns.ncku.edu.tw, eleanor15x@gmail.com,
u-boot@lists.denx.de, Kuan-Wei Chiu <visitorckw@gmail.com>
Subject: [PATCH] virtio: mmio: Return error codes on probe failures
Date: Tue, 7 Apr 2026 09:49:00 +0000 [thread overview]
Message-ID: <20260407094900.420176-1-visitorckw@gmail.com> (raw)
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
next reply other threads:[~2026-04-07 9:49 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-07 9:49 Kuan-Wei Chiu [this message]
2026-04-07 10:17 ` [PATCH] virtio: mmio: Return error codes on probe failures Daniel Palmer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260407094900.420176-1-visitorckw@gmail.com \
--to=visitorckw@gmail.com \
--cc=bmeng.cn@gmail.com \
--cc=daniel@thingy.jp \
--cc=eleanor15x@gmail.com \
--cc=jserv@ccns.ncku.edu.tw \
--cc=sjg@chromium.org \
--cc=trini@konsulko.com \
--cc=tuomas.tynkkynen@iki.fi \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox