Skip to contentSkip to conversation

usb: octeon-hcd: release the USB block when initialization fails

PATCH Superseded Orgad Shaneh 1 participant 2 messages Sep 17 – Oct 11 USB

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: octeon-hcd: release the USB block when initialization fails

cvmx_usb_initialize() gets as far as selecting the reference clock, enabling USBN_CLK_CTL and taking the PHY out of reset (steps 2b-2e) before anything can go wrong, and its only caller frees the HCD and returns without touching the hardware. Both of its error returns therefore leave the USB block clocked and out of reset on a failed probe.

Release it on the way out with cvmx_usb_shutdown(), which is the undo the retry path a few lines above already uses. It cannot refuse with -EBUSY here: the pipe lists it checks are initialised by octeon_usb_probe() before cvmx_usb_initialize() is called, and no pipe can have been opened yet.

Fixes 22bce6d2b3fd ("usb: octeon-hcd: fail the probe when the USB core does not respond")
Assisted-by Claude:claude-opus-5

---

The -EAGAIN return predates that commit; it has the same problem and is fixed here as well.

Found by the Sashiko review bot on the v2 posting of the series that added the -ENODEV path.

drivers/usb/host/octeon-hcd.c +18 -3
@@ -708,6 +708,7 @@
 	int channel;
 	int divisor;
 	int retries = 0;
+	int status;
 	union cvmx_usbcx_hcfg usbcx_hcfg;
 	union cvmx_usbnx_clk_ctl usbn_clk_ctl;
 	union cvmx_usbcx_gintsts usbc_gintsts;
@@ -872,7 +873,8 @@
 	if (usbcx_gahbcfg.u32 == 0xffffffff || usbcx_gahbcfg.u32 == 0) {
 		dev_err(dev, "USB core is not responding (GHWCFG3=0x%08x)\n",
 			usbcx_gahbcfg.u32);
-		return -ENODEV;
+		status = -ENODEV;
+		goto err_shutdown;
 	}
 
 	usbcx_gahbcfg.u32 = 0;
@@ -961,14 +963,27 @@
 	dev_dbg(dev, "gintsts after reset: 0x%x\n", (int)usbc_gintsts.u32);
 	if (!usbc_gintsts.s.disconnint && !usbc_gintsts.s.prtint)
 		return 0;
-	if (retries++ >= 5)
-		return -EAGAIN;
+	if (retries++ >= 5) {
+		status = -EAGAIN;
+		goto err_shutdown;
+	}
 	dev_info(dev, "controller reset failed (gintsts=0x%x) - retrying\n",
 		 (int)usbc_gintsts.u32);
 	msleep(50);
 	cvmx_usb_shutdown(usb);
 	msleep(50);
 	goto retry;
+
+err_shutdown:
+	/*
+	 * Steps 2b-2e above selected the reference clock, enabled
+	 * USBN_CLK_CTL and took the PHY out of reset, and the caller only
+	 * frees the HCD, so hand the block back before giving up. The pipe
+	 * lists cvmx_usb_shutdown() checks are initialised by the caller
+	 * before it gets here, so it cannot refuse with -EBUSY.
+	 */
+	cvmx_usb_shutdown(usb);
+	return status;
 }
 
 /**
Signature · 1 line
2.47.0
#1 lore raw

Hi Greg,

A gentle ping on this one. It fixes 22bce6d2b3fd ("usb: octeon-hcd: fail the probe when the USB core does not respond"), which is already in
mainline: when the core does not respond, the new error path leaves the USB clock enabled and the PHY out of reset.

If it looks fine, could it go to Linus through usb-linus, next to the commit it fixes? If you would like anything changed, I will respin.

Thanks,
Orgad