From patchwork Thu Apr 16 02:29:33 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 2172 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1776306661; bh=Z/IuJKsE+jP5/S8H8clonrIMBzyFZoPHTHYyLUSLl+M=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=BQ0voqH15VPYxG19q48W+q0njK+WSkQ+TTLbrIw6eLI42TZpCn7ZZMa3nBHpOU/ZE jPv6rJy5mzUs6ZZtl62Ls68pdOqgRpmyg1TYZwlburqzsNdG85/7zT0dwE1MDJqVer ugEzoYojQI50vv68c5ZOMEQdv0CJAVvqjRF6LEFk= Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 9FC616A4A8 for ; Wed, 15 Apr 2026 20:31:01 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id Op_l3kBaoUvU for ; Wed, 15 Apr 2026 20:31:01 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1776306659; bh=Z/IuJKsE+jP5/S8H8clonrIMBzyFZoPHTHYyLUSLl+M=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=cs4QEwtZXUg8PVctNYydOZOksyD7BH06sz8FlCIUVkwXn3Xc/j0SE8B44yhbGeTgk m4JgQraffII6b6hwQfzav5kI+aqe/lQDgMer+as1je+b2GcIHM50Gz9Y3ueaXBaFy9 yZPDQ6L48gp7XC0NtknkGj9yb46BqgrpFwibV8UE= Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 8F7156A4B1 for ; Wed, 15 Apr 2026 20:30:59 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1776306656; bh=ufUXgzOdq16W/GprXnxNPZruSuY8EapNDyMGM/vOp/w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gKQiyr7HJ7wU0PyTTpKixUK+2fOU2ti6BOB2sLZWfbRw6629tSnSBx2lIVbkhdEei eRavb1EfE1uOQCXflW5a/D1iv40NSAlPhg2+1X9Ic3CDbfZLIK4Utnr9z3sk8yr8LY m+y75Rtgei77fM0U2Ub3N25yxDwsvKbo1msS8nDg= Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id D5B1E6A4A6; Wed, 15 Apr 2026 20:30:56 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id U3wF_2XqpYOu; Wed, 15 Apr 2026 20:30:56 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1776306652; bh=qGDcGe+RmY07Br4Z+xx5dqHvUptpIsza4x8Ye15C2uY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BTzRs54HR4EBzF8169ioUi9z3HyiQKSfTFYoOXkuJyknXNk/Tib5/PyFs4xbCHxKi thRt7YblfPjNK/viNC3VuYED9QRGwTO2kyIeX5Pv+jP7MSsM1IKvLoOzc03boIeYsI i8Wd9AWhuL26USgzWKylOZF3Yubt398cQwFgz4/c= Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 974F16A44C; Wed, 15 Apr 2026 20:30:52 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Wed, 15 Apr 2026 20:29:33 -0600 Message-ID: <20260416023021.626949-9-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260416023021.626949-1-sjg@u-boot.org> References: <20260416023021.626949-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: WCJVUSGWMSF4YCX6UOZ5VCC3KZ2HJIKI X-Message-ID-Hash: WCJVUSGWMSF4YCX6UOZ5VCC3KZ2HJIKI X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Simon Glass X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 08/33] virtio: emul_blk: Free disk data on remove List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass 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 --- 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 1d42b34b8ab..e9eab4a6470 100644 --- a/drivers/virtio/emul_blk.c +++ b/drivers/virtio/emul_blk.c @@ -131,6 +131,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_request, .get_config = blk_emul_get_config, @@ -148,6 +157,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), };