From nobody Sat Jul 25 17:33:47 2026 Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) (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 C7E142EEE9C for ; Wed, 15 Jul 2026 13:47:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784123222; cv=none; b=k4UigPodtdJdRyweE3IUGTHruXAp9LV0Hf3RxY8DEh7YQ1Hndwdq+Wzby5TJ8CTB9EJ6eIsuSMAt0XXBXan3mJNpH+C3h4sUjC1cpQLrFEqjWwZrf7asZC/rSjSfnibwIxDwc6yNgyeu7jmxPnqpq/DHakInF6QZrrLKpRof78I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784123222; c=relaxed/simple; bh=CMuNYaGnRzSq6CZHFO9VntX54RIhTsLJI3gd5H3i0ow=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Tindt3KbtvDi5gg7VmkyvY459PfjCQX8/TrfahAvxCQm84dxpQaXWZSAVr5bSaw1RpHZzf3FsEJeHRabzP2F8C8ZOYRAWCfBRDQVTRCR4+UPqiDYem4VCdmPCODfdwYP2EEWaj3ylfSjh7OJu7QTzrZHqQGIIU/yC3h2+jzuqzg= 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=Fwh9Ay1z; arc=none smtp.client-ip=209.85.215.195 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="Fwh9Ay1z" Received: by mail-pg1-f195.google.com with SMTP id 41be03b00d2f7-ca80d708489so1514085a12.1 for ; Wed, 15 Jul 2026 06:47:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784123220; x=1784728020; 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=Bxz//7/e5HTtWCDRAkC6j3Yh9BkeNsmi3Lm7ODOArD4=; b=Fwh9Ay1z1EWz+JyWpXDhllwKYL+k/tAMBXQMoYax6OCAJCoA5Xi3vVuoakuY6N/aad TYDPqSs9Kb1TXW25wZy0OZB8RsEq6NNkB3LWTNHIN88HF9uHcd8hXPvimjUkhFZdm1J3 leTd7GXWVly5XnKmFBue0oXwB2sDiDnhPBDmhDXs2a/eVyioQ6HdD5MfZ0qtLIiw5LUM JrPueFa59QIErj9U3YGPPVv7BVrU9tbUfmZvrDmIworGrmUU/Wln66Y1Xys6Ss90t1on zAcFPIq5fO9dMqczwIITfY29DwWhYLoG2YJEeTXxuvI0WTFoi/9ehXMlOu2oF/0Y6DJF c2/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784123220; x=1784728020; 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=Bxz//7/e5HTtWCDRAkC6j3Yh9BkeNsmi3Lm7ODOArD4=; b=qeiBhRfWddynmYUA7vRIuJg99m4SVqM76isjDqoigk9ijzAbdbAYWG1NepfN6C0pCL mopLz9r/cjy66MWU9tPwq8AZRrZ3KxnjOozoliBn7cM5vI8OREia6PKLVJ/zkSiRdQ7i 9uu0weItsIEEVuXKbIU+yoC6WLZL9h3dVTtQ7qQ8fldXgLd0FqjPUTtzXaoWpgAeEMce Azt7KBbexup2PXZLhRqX10A7jaXwqplxLxECBhmo2+27g2tHcXqnfiCmVzhJ7wwXNtU0 KjVB6+/HYJDVC9YNq2z11qiJLuY8hNi5Bwl0ybU0kV/e4fRQmNUx5lmPqK8eB//VtSc2 0N6A== X-Forwarded-Encrypted: i=1; AHgh+RqeO78VGzVVX6JsARqX3cvqvFX1MsDl1MhrdMwRc+ZvZk4jdXI09LTnfJUFHz9S+QMDYY3Ch/gHLAkoE88=@vger.kernel.org X-Gm-Message-State: AOJu0Yzw8pxQOvGK8sMos/W+kwG9sYiM9PrRakgQSWLAcMyfb5vi18GB qgW5WzBU8iCvC1/ymof5TWu/kKi72nHv9zIptBagXJXIOVTe/vzgn/MU X-Gm-Gg: AfdE7ck/qqUzMxogRrrCVVeQ7z5r4uGSCqg9YJmp+LikLtWsH3VoDOCtNQEwP8+EeEP 4Hissk0GbOEfChWgQdDxtJu2gzMaO4Fg2sgV3S3tnVivZFjfAcPAbhdemcmDMw6s9BhUNi3zLXC 0TxRSuFv7uPuXC6RtPtmZYepqUz03lxqT0xZfkVIH7mfeOAS6k4Rzs06ey/bIIeTQQZlqcN1gO/ NppJUwBr8F14jYZ89OcTUFGPru2kbIqPbYq9Eck6QOXP0yrU3OGsGEKeAI2Ia//QOhPNRrZ+20e sAt70HICSTqsGriQ6iiZzm1Cdxu6y3se1qU92O8E3G25UiL0hfWQOjcJaijfhSBnGvOJMza2pcN Dz35yu0lPhKUWsWG9mhGOj4jIr4YfTPnnQf3GC9QeGS9wR8WfFExjIKraIuJNEku0Rj+chBLDlL onph0gHIG5vahgov2hM5GAV3p0Ofzl2g== X-Received: by 2002:a05:6a21:458f:b0:3b5:6b5a:4f31 with SMTP id adf61e73a8af0-3c0f0b726cdmr25977715637.27.1784123219895; Wed, 15 Jul 2026 06:46:59 -0700 (PDT) Received: from workstation.. ([182.180.105.19]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3140e4fc28dsm1954487eec.2.2026.07.15.06.46.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jul 2026 06:46:59 -0700 (PDT) From: Ali Tariq To: kevin.xie@starfivetech.com Cc: lpieralisi@kernel.org, kwilczynski@kernel.org, mani@kernel.org, robh@kernel.org, bhelgaas@google.com, Markus.Elfring@web.de, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Ali Tariq Subject: [PATCH v2] PCI: starfive: Fix resource leaks on error paths in host_init() Date: Wed, 15 Jul 2026 18:45:32 +0500 Message-Id: <20260715134532.619566-1-alitariq45892@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260714113029.326207-1-alitariq45892@gmail.com> References: <20260714113029.326207-1-alitariq45892@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" starfive_pcie_host_init() acquires the PHY, clocks/resets, and an optional regulator in sequence, but does not correctly unwind these resources when a later step fails. If starfive_pcie_clk_rst_init() fails after the PHY has already been successfully enabled, the function returns directly without disabling the PHY, leaking it and leaving it powered. If regulator_enable() fails for the optional vpcie3v3 regulator, the failure is only logged; the function falls through and returns success, leaving the driver believing the regulator is enabled while continuing to configure PCIe hardware that may be unpowered. This also leaves the clocks and PHY enabled with nothing to clean them up. Disable the PHY on the clk/reset failure path, and disable the clocks/resets and PHY, then return the error, if the regulator fails to enable. Build-tested and boot-tested on StarFive VisionFive 2 v1.2A Signed-off-by: Ali Tariq --- Changes in v2: - Use a shared error-handling label instead of duplicating cleanup code --- drivers/pci/controller/plda/pcie-starfive.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/pci/controller/plda/pcie-starfive.c b/drivers/pci/cont= roller/plda/pcie-starfive.c index ba8ef7842e35..fab44054a5de 100644 --- a/drivers/pci/controller/plda/pcie-starfive.c +++ b/drivers/pci/controller/plda/pcie-starfive.c @@ -304,12 +304,14 @@ static int starfive_pcie_host_init(struct plda_pcie_r= p *plda) =20 ret =3D starfive_pcie_clk_rst_init(pcie); if (ret) - return ret; + goto err_disable_phy; =20 if (pcie->vpcie3v3) { ret =3D regulator_enable(pcie->vpcie3v3); - if (ret) + if (ret) { dev_err_probe(dev, ret, "failed to enable vpcie3v3 regulator\n"); + goto err_clk_rst; + } } =20 if (pcie->reset_gpio) @@ -379,6 +381,13 @@ static int starfive_pcie_host_init(struct plda_pcie_rp= *plda) dev_info(dev, "port link down\n"); =20 return 0; + +err_clk_rst: + starfive_pcie_clk_rst_deinit(pcie); +err_disable_phy: + starfive_pcie_disable_phy(pcie); + + return ret; } =20 static const struct plda_pcie_host_ops sf_host_ops =3D { --=20 2.34.1