Skip to contentSkip to conversation

virtio: free device name when the driver is not configured

PATCH In review Yuho Choi 3 participants 3 messages Oct 27 – Nov 11 virtio core

lore
Share & tools
lore

Yuho Choi

author
#0 lore raw

PATCH 1/1 virtio: free device name when the driver is not configured

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")
---
 drivers/virtio/virtio-uclass.c | 1 +
 1 file changed, 1 insertion(+)
drivers/virtio/virtio-uclass.c +1 -0
index c163b2fd7d5..e745369b257 100644
@@ -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) {
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 15 lines · Yuho Choi

virtio: free device name when the driver is not configured

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.

Quoted 7 lines

Free the name on this path as well.

Fixes 8fb49b4c7a82 ("dm: Add a new uclass driver for VirtIO transport devices")
 drivers/virtio/virtio-uclass.c | 1 +
 1 file changed, 1 insertion(+)
#2 lore raw
In reply to Yuho Choi
Quoted 8 lines · Yuho Choi

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.

[...]

Applied to u-boot/main, thanks!

[1/1] virtio: free device name when the driver is not configured

      commit: d373cca5b88c7dcb0bb859d239921915ef692c8b
Signature · 1 line
Tom