Linux Tegra architecture development
 help / color / mirror / Atom feed
From: Pengpeng Hou <hppiscas@163.com>
To: Mathias Nyman <mathias.nyman@intel.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Pengpeng Hou <hppiscas@163.com>,
	Thierry Reding <thierry.reding@kernel.org>,
	Jonathan Hunter <jonathanh@nvidia.com>, JC Kuo <jckuo@nvidia.com>,
	linux-usb@vger.kernel.org, linux-tegra@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH] usb: host: xhci-tegra: Handle PHY failures while exiting ELPG
Date: Sun,  6 Sep 2026 11:41:14 +0800	[thread overview]
Message-ID: <20260906034114.85417-1-hppiscas@163.com> (raw)

tegra_xusb_exit_elpg() ignores phy_init() and phy_power_on() failures
and continues to restore firmware and xHCI state.

Stop at the first failed PHY, undo a successful init for that PHY when
power-on fails, and unwind only the previously enabled PHYs in reverse
order before using the existing partition and clock cleanup.

The issue was found by our static-analysis tool and manually reviewed.

Fixes: 971ee247060d ("usb: xhci: tegra: Enable ELPG for runtime/system PM")
Assisted-by: gpt 5
Signed-off-by: Pengpeng Hou <hppiscas@163.com>
---
 drivers/usb/host/xhci-tegra.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/host/xhci-tegra.c b/drivers/usb/host/xhci-tegra.c
index 6f235d1e117e..7b7cf22a577d 100644
--- a/drivers/usb/host/xhci-tegra.c
+++ b/drivers/usb/host/xhci-tegra.c
@@ -2328,10 +2328,18 @@ static int tegra_xusb_exit_elpg(struct tegra_xusb *tegra, bool is_auto_resume)
 		if (!tegra->phys[i])
 			continue;
 
-		if (!wakeup)
-			phy_init(tegra->phys[i]);
+		if (!wakeup) {
+			err = phy_init(tegra->phys[i]);
+			if (err)
+				goto disable_enabled_phys;
+		}
 
-		phy_power_on(tegra->phys[i]);
+		err = phy_power_on(tegra->phys[i]);
+		if (err) {
+			if (!wakeup)
+				phy_exit(tegra->phys[i]);
+			goto disable_enabled_phys;
+		}
 	}
 	if (tegra->suspended)
 		tegra_xhci_program_utmi_power_lp0_exit(tegra);
@@ -2367,7 +2375,9 @@ static int tegra_xusb_exit_elpg(struct tegra_xusb *tegra, bool is_auto_resume)
 	goto out;
 
 disable_phy:
-	for (i = 0; i < tegra->num_phys; i++) {
+	i = tegra->num_phys;
+disable_enabled_phys:
+	while (i--) {
 		if (!tegra->phys[i])
 			continue;
 
-- 
2.50.1 (Apple Git-155)


                 reply	other threads:[~2026-09-06  3:41 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260906034114.85417-1-hppiscas@163.com \
    --to=hppiscas@163.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jckuo@nvidia.com \
    --cc=jonathanh@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mathias.nyman@intel.com \
    --cc=thierry.reding@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox