[PATCH] usb: host: xhci-tegra: Handle PHY failures while exiting ELPG

From: Pengpeng Hou

Date: Sat Sep 05 2026 - 23:41:56 EST


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@xxxxxxx>
---
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)