U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Yuho Choi <oss.patchbox@gmail.com>
To: Bin Meng <bmeng.cn@gmail.com>
Cc: Tom Rini <trini@konsulko.com>,
	Tuomas Tynkkynen <tuomas.tynkkynen@iki.fi>,
	Simon Glass <sjg@chromium.org>,
	u-boot@lists.u-boot-project.org,
	Yuho Choi <oss.patchbox@gmail.com>
Subject: [PATCH] virtio: free device name when the driver is not configured
Date: Tue, 27 Oct 2026 14:52:31 -0400	[thread overview]
Message-ID: <20261027185337.51168-1-oss.patchbox@gmail.com> (raw)

virtio_uclass_post_probe() duplicates the name for the child device with
strdup() and passes it to device_bind_driver(). If the driver for the
reported device type is not built, device_bind_driver() returns -ENOENT
and the function returns 0 without freeing the name. Ownership of the
name only passes to the device through device_set_name_alloced() after
a successful bind.

This happens on each probe of a virtio transport whose device type is
listed in virtio_drv_name[] but whose driver is disabled, e.g. a
virtio-9p device on a QEMU target without CONFIG_VIRTIO_9P, or the
virtio-blk node of the sandbox test device tree, as sandbox_defconfig
does not enable CONFIG_VIRTIO_BLK.

Free the name on this path as well.

Fixes: 8fb49b4c7a82 ("dm: Add a new uclass driver for VirtIO transport devices")
Signed-off-by: Yuho Choi <oss.patchbox@gmail.com>
---
 drivers/virtio/virtio-uclass.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/virtio/virtio-uclass.c b/drivers/virtio/virtio-uclass.c
index c163b2fd7d5..e745369b257 100644
--- a/drivers/virtio/virtio-uclass.c
+++ b/drivers/virtio/virtio-uclass.c
@@ -239,6 +239,7 @@ static int virtio_uclass_post_probe(struct udevice *udev)
 	ret = device_bind_driver(udev, name, str, &vdev);
 	if (ret == -ENOENT) {
 		debug("(%s): %s driver not configured\n", udev->name, name);
+		free(str);
 		return 0;
 	}
 	if (ret) {
-- 
2.43.0


             reply	other threads:[~2026-10-27 19:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-27 18:52 Yuho Choi [this message]
2026-10-28  7:37 ` [PATCH] virtio: free device name when the driver is not configured Simon Glass

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=20261027185337.51168-1-oss.patchbox@gmail.com \
    --to=oss.patchbox@gmail.com \
    --cc=bmeng.cn@gmail.com \
    --cc=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --cc=tuomas.tynkkynen@iki.fi \
    --cc=u-boot@lists.u-boot-project.org \
    /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