From patchwork Mon Mar 16 18:30:37 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 2025 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=1773685893; bh=Pom+VkAuDGqc8465EJICb0T0YPXdH/rkadv0bH/EZk0=; 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=UW1RXKDXZi9wby3IUSyaUmzEtFO0h/tUEWpyv5MCLu/UupE4BRHAcerdzCq4tnhVQ XeNUsYJKIhx1/2mByIYfTUAQrrIiYDsJ96C+e4a8Qw+7qfI1MfkSmrbBRhBEb6HjSg ZyNEslnickrVqwYniOt4iGu+qxJyNFsmWHa7JV+HZrnhLkpuJlTzrt1OYSzQryUPr+ SE/G/NaUGDgSHSuvCZORp1Y9dofVFegitXHUjU5eXPhKDyrX35FDMhER/pNsHZx5A7 v0l6iER6NhmrFNBO3hg1zeAs4Xmln03h+G+ftwL3PeYayseAVFjubPAOgHwcAlRktX K62WJoU4gv8Kg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id AF6666A0AB for ; Mon, 16 Mar 2026 12:31:33 -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 WvJWVtLh8DVu for ; Mon, 16 Mar 2026 12:31:33 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685893; bh=Pom+VkAuDGqc8465EJICb0T0YPXdH/rkadv0bH/EZk0=; 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=UW1RXKDXZi9wby3IUSyaUmzEtFO0h/tUEWpyv5MCLu/UupE4BRHAcerdzCq4tnhVQ XeNUsYJKIhx1/2mByIYfTUAQrrIiYDsJ96C+e4a8Qw+7qfI1MfkSmrbBRhBEb6HjSg ZyNEslnickrVqwYniOt4iGu+qxJyNFsmWHa7JV+HZrnhLkpuJlTzrt1OYSzQryUPr+ SE/G/NaUGDgSHSuvCZORp1Y9dofVFegitXHUjU5eXPhKDyrX35FDMhER/pNsHZx5A7 v0l6iER6NhmrFNBO3hg1zeAs4Xmln03h+G+ftwL3PeYayseAVFjubPAOgHwcAlRktX K62WJoU4gv8Kg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 489366A0A5 for ; Mon, 16 Mar 2026 12:31:33 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685889; bh=pOeABCh/lMVj7ZIFVlpy9eNXukJsEY16cr8CrPy+A4Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S4knwDiNCXJeQ/hxFqVKtOnrhnj9o2enctEB3fkN2mHjEvwxkH7N0Qk0SaNepFke5 JghZWwl1ez3MCBGosT3pgJNTQ500SepIm6dSq9JIoDEgmM4DQ3DVrrBttKf6KceuEm p42VhN6RMIaqxigqlPXnySw3+cE5kuHWvhpUADe5zot/HrRPbA1f+u+pQapDXwKNuq Wfo1FLAwwi5+QxmBOE6Ho3DQsOaA2vmdiN0NGQGIQPOEPSoqFByZvFjerijngN3zep KtOHg7lKUyTwT0ic8wtaQLunMxRhD15hMO8X1g/a/Q+yseIq/Bvk9Y1q+qB3/dXkCT eXazPxhBcVSdg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id CEDE66A09E; Mon, 16 Mar 2026 12:31:29 -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 iorScMAfoY7s; Mon, 16 Mar 2026 12:31:29 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773685887; bh=4gnKBr7YPqHupZmXsM1yQJygHosO2R2QlTUOxQFe5ho=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tc4FeTAeaD8Fiu7IQGBzgvNT7yXVxh1Kfg4Gz+KWanun6ELuClMO07B53v5sqidwA d2+9V7o8ViKjUNncbdFNK6UxzcCHbk8Ww1LiiLesZ/MCSV0+2yk3Y1q6/U+4RUHVlC elGKdA1pcL36Sy+8qPwJD93aSW7uvYSzvrfmdiLZahVGyYcgdPOl+GBItLCI37yScb hune7TbL8eXMXDKz/2v9FJ7YRPDKP8hRJ409+cnbMTYVSPMqs9lBRYp1kwPpjjq+er jUX3BqV6IMHzyH89STFoRSncLI/LvUQdvYILQTkJPgtK5hRsQMA8UeOYpsJQK7L0WN kQ2Li8iFAcEiA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id EA7A46A07B; Mon, 16 Mar 2026 12:31:26 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Mon, 16 Mar 2026 12:30:37 -0600 Message-ID: <20260316183050.3855921-15-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260316183050.3855921-1-sjg@u-boot.org> References: <20260316183050.3855921-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 7ZNS75DUOVWIQKD4Z3WQSJNUAYKYLRUV X-Message-ID-Hash: 7ZNS75DUOVWIQKD4Z3WQSJNUAYKYLRUV 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 14/17] pci: Fix PCI regions array leak on device removal 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 decode_regions() allocates hose->regions in pci_uclass_pre_probe() but the array is never freed when the PCI bus device is removed. Add a pre_remove() handler to free it. Fixes: e002474158d1 ("pci: pci-uclass: Dynamically allocate the PCI regions") Signed-off-by: Simon Glass --- drivers/pci/pci-uclass.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c index c370f8c6400..27bc92f0e4c 100644 --- a/drivers/pci/pci-uclass.c +++ b/drivers/pci/pci-uclass.c @@ -1874,6 +1874,16 @@ int pci_sriov_get_totalvfs(struct udevice *pdev) } #endif /* SRIOV */ +static int pci_uclass_pre_remove(struct udevice *bus) +{ + struct pci_controller *hose = dev_get_uclass_priv(bus); + + free(hose->regions); + hose->regions = NULL; + + return 0; +} + UCLASS_DRIVER(pci) = { .id = UCLASS_PCI, .name = "pci", @@ -1881,6 +1891,7 @@ UCLASS_DRIVER(pci) = { .post_bind = dm_scan_fdt_dev, .pre_probe = pci_uclass_pre_probe, .post_probe = pci_uclass_post_probe, + .pre_remove = pci_uclass_pre_remove, .child_post_bind = pci_uclass_child_post_bind, .per_device_auto = sizeof(struct pci_controller), .per_child_plat_auto = sizeof(struct pci_child_plat),