From nobody Mon Sep 28 10:00:08 2026 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 25A7939EF0C for ; Mon, 24 Aug 2026 07:55:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787558136; cv=none; b=rfsPapPPvmazXr5NFx9kBvPHbiFX1MflLSb2t79O1Rrur7wtQRV6xxfXNdFsieOWjmc3Z8DSS7UyvfOEIPbu0gEMGAX/6zIp2EERxNSo1FsU4qjJZ1WfXCkgGZ6c8+nbnAnBywB0DJ+wvzxObkEia/joi09XcbqzWp7nhZj9lvM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787558136; c=relaxed/simple; bh=82tOHDC7nJrDfycmSAVW9nOEAnMjFI64BjxgfbPacuc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CeJ4lgJywhFYO+ba99HnKE58Kx9pnSMPCJ2ap/ZZblplEck3k1UQo4L+DNLwu5dzZRz5fLTH3M8s/8i6qtcja7lLA93v2DgyB/eri6/nUXVQTjxDCyDWrP/J5Y+Ng/alPBP4pE3QWT/dS7WBM0GlKDVQ9NHCq3paRa9ExYeNI4w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Q+F2sjGi; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Q+F2sjGi" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-2caed617615so31635815ad.3 for ; Mon, 24 Aug 2026 00:55:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787558131; x=1788162931; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=fD7HDEqAve3vYidUjX8s8f4KzZ+OcpC6vSRwhTvcNpE=; b=Q+F2sjGi/imctSJIPOeAbZn6gkD/wlGGjPmMEj37Xo5VFlWDOqU3K7EeGD9A6KomyO 2Pm9WPddigKNB+qBG44t0Vk212GtLf3biav5uKAgzRjVZ6KxUK0akmnpX/95CxRIl8sY MJkyx/WKDCTE9tfHW3z9Zx6clauwBS5iVwqsmkK/IjTucop3EJmICUh4FHdszRWn7E8c ZN0lAXqGHIcvvYcCPRH0myj9VhaWhxSSBPP1QRu3ntQQQ2E64XQX6G7ZefiUNyi50Di5 IBAzDpSGq6i7qnAXCdBvayRzhY25l5lbLHr2ZAAlJAnK5XDXiPppHzQA/OtJEXHxkgri XxSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787558131; x=1788162931; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=fD7HDEqAve3vYidUjX8s8f4KzZ+OcpC6vSRwhTvcNpE=; b=KLpeaLFEfW7ri6WdlJY5du4eOk0cuCfEfBK/yE80C71hYevzyIUUsMPx0QK9P44QUV j2nC8V9W/oWApN9kNl93vDVoW7Xz1dT3A7Y8TshoWiytoUq7wuuax1e+tdB8ikCZv23d PCq3TWoUkct16Ka8O6LqHKOIninwv55WF8nDPTuOxuhUPb6+5wTXer6L09ni46lLAHC9 bQgZRUJaehofs1/a2WI22XS5sYTwPk4A0fR4PVvVickskI6J50MwQ3z3LYR3ODnVB5fJ Qj3LYTzKnVXkrKMZEiq0laNNqAqk/l+v+baIabIWEnp6/gfzeZcI1m1PSplIyf+O6IYS D9eA== X-Forwarded-Encrypted: i=1; AHgh+RpuFCmqvoRXMJjqxPiiUQtzImbQI/Mrq/rIpfQz5we+5yT1IH4WvA+CFOtmBZFKlD9oKgKvITfVWGNS11E=@vger.kernel.org X-Gm-Message-State: AFuF++nuKNu8QDPPmXci509yGuNT4zn8P9iHz2+dG1vtXdRVEq06Giae 6b4zeLipQNCC4zJswOm+PrJSufNzkWvcbWpq0Wa2MLzEbYqnOeQ5h8NB X-Gm-Gg: AR+sD10P7obipo9UyIevC7CTlbU43uvpLn/KEbhiugGQ6Vjg1YijVB7vGHQeSmLPamG glyrvgGwi7RhJA+OVFhHYYM5pVUtm1BrzJy8ZNZIVQro/TJgmdcdtb2eIaQfgnkz+lP39yD3FGU kvWz+O8o6Vr4UuGp+6sLIDASpuvv3xS64btVjBCS/iRjbHnKbF4dCuE7qUCG1r5Z74nlK2/7Qmu F2cCqP+0RAfZA8cX+a9YlovZ3clKe3IkIbGSIUW54gj7RNgqOuMYXWMwJdHLhZYiVWSty/FiHcc 9T3pUia2eb2w7fe/sdrT6u1rhZbbWtxUDXg7qIzaQs2eAWzBgG1eXAA8JfO5L9y+bKXzBVfy5AF N5IuH5IgusJ+IKih4idtJmE9Bg1yMuBH1PG1npyf3Jlc06JHHiK8IYabEfyW4oAjRl/bi48LyOT lGPWMWjdioWGBL2X4OfFqw+4Q2flTqutZb0aEPhhLZYL01A2ED4TSa4dx2N4Grrx4hjT7D/aKh9 Et0al1uZx37EgPUtYm8HJA76l/yDGE8X7Dk3gmCjkuoaFiVQ5mG X-Received: by 2002:a17:902:f70b:b0:2d6:3c2f:6a4 with SMTP id d9443c01a7336-2d670d07a21mr311514175ad.13.1787558131477; Mon, 24 Aug 2026 00:55:31 -0700 (PDT) Received: from hanzj-mi.. (ec2-99-79-140-187.ca-central-1.compute.amazonaws.com. [99.79.140.187]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2d67679e55bsm14421565ad.30.2026.08.24.00.55.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Aug 2026 00:55:31 -0700 (PDT) From: hanzhijian To: Richard Zhu , Lucas Stach , Lorenzo Pieralisi , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Manivannan Sadhasivam , Bjorn Helgaas Cc: Rob Herring , Frank Li , Sascha Hauer , kernel@pengutronix.de, Fabio Estevam , linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, imx@lists.linux.dev, linux-kernel@vger.kernel.org, hanzhijian , sashiko-bot@kernel.org Subject: [PATCH v3] PCI: imx6: fix resource leaks in probe error paths Date: Mon, 24 Aug 2026 15:55:12 +0800 Message-ID: <20260824075512.3386898-1-hanzhijian1991@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260823071129.2980059-1-hanzhijian1991@gmail.com> References: <20260823071129.2980059-1-hanzhijian1991@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" imx_pcie_probe() leaks both pwrctrl devices and power domains on failure: - imx_pcie_attach_pd() attaches the "pcie" and "pcie_phy" power domains and creates device links to them, but the device links are only kept in a local variable and nothing detaches the domains on probe failure or deferral, so all of them leak. - A failure of devm_pm_runtime_set_active_enabled() returns directly without destroying the pwrctrl devices. - A partial failure inside imx_pcie_attach_pd() leaks the power domains and device links that were already attached. Save the device links, add imx_pcie_detach_pd() to release the power domains and device links in reverse order of acquisition, call it from the probe error paths, and make imx_pcie_attach_pd() release everything it has attached so far on failure. Reported-by: sashiko-bot@kernel.org Link: https://lore.kernel.org/all/20260822013640.182C01F000E9@smtp.kernel.o= rg/ Signed-off-by: hanzhijian --- drivers/pci/controller/dwc/pci-imx6.c | 42 ++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller= /dwc/pci-imx6.c index 39790e66b..467006d83 100644 --- a/drivers/pci/controller/dwc/pci-imx6.c +++ b/drivers/pci/controller/dwc/pci-imx6.c @@ -182,6 +182,9 @@ struct imx_pcie { struct device *pd_pcie; /* power domain for pcie phy */ struct device *pd_pcie_phy; + /* device links for the power domains */ + struct device_link *pd_link; + struct device_link *pd_phy_link; struct phy *phy; const struct imx_pcie_drvdata *drvdata; =20 @@ -639,6 +642,26 @@ static int imx6q_pcie_abort_handler(unsigned long addr, } #endif =20 +static void imx_pcie_detach_pd(struct imx_pcie *imx_pcie) +{ + if (imx_pcie->pd_phy_link) { + device_link_del(imx_pcie->pd_phy_link); + imx_pcie->pd_phy_link =3D NULL; + } + if (!IS_ERR_OR_NULL(imx_pcie->pd_pcie_phy)) { + dev_pm_domain_detach(imx_pcie->pd_pcie_phy, true); + imx_pcie->pd_pcie_phy =3D NULL; + } + if (imx_pcie->pd_link) { + device_link_del(imx_pcie->pd_link); + imx_pcie->pd_link =3D NULL; + } + if (!IS_ERR_OR_NULL(imx_pcie->pd_pcie)) { + dev_pm_domain_detach(imx_pcie->pd_pcie, true); + imx_pcie->pd_pcie =3D NULL; + } +} + static int imx_pcie_attach_pd(struct device *dev) { struct imx_pcie *imx_pcie =3D dev_get_drvdata(dev); @@ -660,12 +683,18 @@ static int imx_pcie_attach_pd(struct device *dev) DL_FLAG_RPM_ACTIVE); if (!link) { dev_err(dev, "Failed to add device_link to pcie pd\n"); + imx_pcie_detach_pd(imx_pcie); return -EINVAL; } + imx_pcie->pd_link =3D link; =20 imx_pcie->pd_pcie_phy =3D dev_pm_domain_attach_by_name(dev, "pcie_phy"); - if (IS_ERR(imx_pcie->pd_pcie_phy)) - return PTR_ERR(imx_pcie->pd_pcie_phy); + if (IS_ERR(imx_pcie->pd_pcie_phy)) { + int ret =3D PTR_ERR(imx_pcie->pd_pcie_phy); + + imx_pcie_detach_pd(imx_pcie); + return ret; + } =20 link =3D device_link_add(dev, imx_pcie->pd_pcie_phy, DL_FLAG_STATELESS | @@ -673,8 +702,10 @@ static int imx_pcie_attach_pd(struct device *dev) DL_FLAG_RPM_ACTIVE); if (!link) { dev_err(dev, "Failed to add device_link to pcie_phy pd\n"); + imx_pcie_detach_pd(imx_pcie); return -EINVAL; } + imx_pcie->pd_phy_link =3D link; =20 return 0; } @@ -1956,8 +1987,10 @@ static int imx_pcie_probe(struct platform_device *pd= ev) return ret; =20 ret =3D pci_pwrctrl_create_devices(dev); - if (ret) + if (ret) { + imx_pcie_detach_pd(imx_pcie); return dev_err_probe(dev, ret, "failed to create pwrctrl devices\n"); + } =20 pci->use_parent_dt_ranges =3D true; if (imx_pcie->drvdata->mode =3D=3D DW_PCIE_EP_TYPE) { @@ -1975,7 +2008,7 @@ static int imx_pcie_probe(struct platform_device *pde= v) pm_runtime_no_callbacks(dev); ret =3D devm_pm_runtime_set_active_enabled(dev); if (ret < 0) - return ret; + goto err_pwrctrl_destroy; } =20 if (imx_check_flag(imx_pcie, IMX_PCIE_FLAG_SKIP_L23_READY)) @@ -2001,6 +2034,7 @@ static int imx_pcie_probe(struct platform_device *pde= v) err_pwrctrl_destroy: if (ret !=3D -EPROBE_DEFER) pci_pwrctrl_destroy_devices(dev); + imx_pcie_detach_pd(imx_pcie); return ret; } =20 --=20 2.43.0