The probe function allocates 1MB for the emulated disk contents but
there is no corresponding free on remove, so the memory leaks every
time the device is torn down. This shows up as a 1MB leak per test in
several bootstd tests.

Add a remove method to free the buffer.

Signed-off-by: Simon Glass <[email protected]>
---

 drivers/virtio/emul_blk.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/virtio/emul_blk.c b/drivers/virtio/emul_blk.c
index 62ee125cf3c..ec5e715a460 100644
--- a/drivers/virtio/emul_blk.c
+++ b/drivers/virtio/emul_blk.c
@@ -154,6 +154,15 @@ static int virtio_blk_emul_probe(struct udevice *dev)
        return 0;
 }
 
+static int virtio_blk_emul_remove(struct udevice *dev)
+{
+       struct virtio_blk_emul_priv *priv = dev_get_priv(dev);
+
+       free(priv->disk_data);
+
+       return 0;
+}
+
 static struct virtio_emul_ops blk_emul_ops = {
        .process_request = blk_emul_process_req,
        .get_config = blk_emul_get_config,
@@ -171,6 +180,7 @@ U_BOOT_DRIVER(virtio_blk_emul) = {
        .id     = UCLASS_VIRTIO_EMUL,
        .of_match = virtio_blk_emul_ids,
        .probe  = virtio_blk_emul_probe,
+       .remove = virtio_blk_emul_remove,
        .ops    = &blk_emul_ops,
        .priv_auto      = sizeof(struct virtio_blk_emul_priv),
 };
-- 
2.43.0

Reply via email to