[PATCH 11/13] virtio: emul_blk: Free disk data on remove

Heinrich Schuchardt xypron.glpk at gmx.de
Wed May 27 20:47:02 CEST 2026


On 5/27/26 18:10, Simon Glass wrote:
> 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 <sjg at chromium.org>

Why don't you add the function in the patch introducing
drivers/virtio/emul_blk.c?

Best regards

Heinrich

> ---
> 
>   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),
>   };



More information about the U-Boot mailing list