* [PATCH] USB: ehci-omap: Fix missing usb_phy_init() error handling
@ 2025-12-02 8:00 Haotian Zhang
2025-12-02 8:30 ` Greg KH
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Haotian Zhang @ 2025-12-02 8:00 UTC (permalink / raw)
To: stern, gregkh; +Cc: linux-usb, linux-omap, linux-kernel, Haotian Zhang
usb_phy_init() may fail if the PHY clock or regulator setup fails,
but ehci_hcd_omap_probe() does not check its return value,
potentially causing later operations to act on an uninitialized PHY.
Add proper error checking for usb_phy_init() calls. Add a new
error label to properly remove the hcd.
Fixes: 4e5c9e6fa2d2 ("USB: ehci-omap: Tweak PHY initialization sequence")
Fixes: 49f092198f4f ("USB: ehci-omap: Fix detection in HSIC mode")
Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
---
drivers/usb/host/ehci-omap.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/host/ehci-omap.c b/drivers/usb/host/ehci-omap.c
index db4a1acb27da..30b3586fd696 100644
--- a/drivers/usb/host/ehci-omap.c
+++ b/drivers/usb/host/ehci-omap.c
@@ -166,7 +166,11 @@ static int ehci_hcd_omap_probe(struct platform_device *pdev)
omap->phy[i] = phy;
if (pdata->port_mode[i] == OMAP_EHCI_PORT_MODE_PHY) {
- usb_phy_init(omap->phy[i]);
+ ret = usb_phy_init(omap->phy[i]);
+ if (ret) {
+ dev_err(dev, "Failed to init PHY %d\n", i);
+ goto err_phy;
+ }
/* bring PHY out of suspend */
usb_phy_set_suspend(omap->phy[i], 0);
}
@@ -205,13 +209,19 @@ static int ehci_hcd_omap_probe(struct platform_device *pdev)
pdata->port_mode[i] == OMAP_EHCI_PORT_MODE_PHY)
continue;
- usb_phy_init(omap->phy[i]);
+ ret = usb_phy_init(omap->phy[i]);
+ if (ret) {
+ dev_err(dev, "Failed to init PHY %d\n", i);
+ goto err_remove_hcd;
+ }
/* bring PHY out of suspend */
usb_phy_set_suspend(omap->phy[i], 0);
}
return 0;
+err_remove_hcd:
+ usb_remove_hcd(hcd);
err_pm_runtime:
pm_runtime_put_sync(dev);
pm_runtime_disable(dev);
--
2.50.1.windows.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] USB: ehci-omap: Fix missing usb_phy_init() error handling
2025-12-02 8:00 [PATCH] USB: ehci-omap: Fix missing usb_phy_init() error handling Haotian Zhang
@ 2025-12-02 8:30 ` Greg KH
2025-12-02 16:05 ` Alan Stern
2025-12-03 3:28 ` [PATCH v2] " Haotian Zhang
2 siblings, 0 replies; 5+ messages in thread
From: Greg KH @ 2025-12-02 8:30 UTC (permalink / raw)
To: Haotian Zhang; +Cc: stern, linux-usb, linux-omap, linux-kernel
On Tue, Dec 02, 2025 at 04:00:27PM +0800, Haotian Zhang wrote:
> usb_phy_init() may fail if the PHY clock or regulator setup fails,
> but ehci_hcd_omap_probe() does not check its return value,
> potentially causing later operations to act on an uninitialized PHY.
>
> Add proper error checking for usb_phy_init() calls. Add a new
> error label to properly remove the hcd.
>
> Fixes: 4e5c9e6fa2d2 ("USB: ehci-omap: Tweak PHY initialization sequence")
> Fixes: 49f092198f4f ("USB: ehci-omap: Fix detection in HSIC mode")
> Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
How was this found and tested?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] USB: ehci-omap: Fix missing usb_phy_init() error handling
2025-12-02 8:00 [PATCH] USB: ehci-omap: Fix missing usb_phy_init() error handling Haotian Zhang
2025-12-02 8:30 ` Greg KH
@ 2025-12-02 16:05 ` Alan Stern
2025-12-03 3:28 ` [PATCH v2] " Haotian Zhang
2 siblings, 0 replies; 5+ messages in thread
From: Alan Stern @ 2025-12-02 16:05 UTC (permalink / raw)
To: Haotian Zhang; +Cc: gregkh, linux-usb, linux-omap, linux-kernel
On Tue, Dec 02, 2025 at 04:00:27PM +0800, Haotian Zhang wrote:
> usb_phy_init() may fail if the PHY clock or regulator setup fails,
> but ehci_hcd_omap_probe() does not check its return value,
> potentially causing later operations to act on an uninitialized PHY.
>
> Add proper error checking for usb_phy_init() calls. Add a new
> error label to properly remove the hcd.
>
> Fixes: 4e5c9e6fa2d2 ("USB: ehci-omap: Tweak PHY initialization sequence")
> Fixes: 49f092198f4f ("USB: ehci-omap: Fix detection in HSIC mode")
> Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
> ---
> drivers/usb/host/ehci-omap.c | 14 ++++++++++++--
> 1 file changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/usb/host/ehci-omap.c b/drivers/usb/host/ehci-omap.c
> index db4a1acb27da..30b3586fd696 100644
> --- a/drivers/usb/host/ehci-omap.c
> +++ b/drivers/usb/host/ehci-omap.c
> @@ -166,7 +166,11 @@ static int ehci_hcd_omap_probe(struct platform_device *pdev)
> omap->phy[i] = phy;
>
> if (pdata->port_mode[i] == OMAP_EHCI_PORT_MODE_PHY) {
> - usb_phy_init(omap->phy[i]);
> + ret = usb_phy_init(omap->phy[i]);
> + if (ret) {
> + dev_err(dev, "Failed to init PHY %d\n", i);
> + goto err_phy;
> + }
> /* bring PHY out of suspend */
> usb_phy_set_suspend(omap->phy[i], 0);
> }
> @@ -205,13 +209,19 @@ static int ehci_hcd_omap_probe(struct platform_device *pdev)
> pdata->port_mode[i] == OMAP_EHCI_PORT_MODE_PHY)
> continue;
>
> - usb_phy_init(omap->phy[i]);
> + ret = usb_phy_init(omap->phy[i]);
> + if (ret) {
> + dev_err(dev, "Failed to init PHY %d\n", i);
> + goto err_remove_hcd;
> + }
> /* bring PHY out of suspend */
> usb_phy_set_suspend(omap->phy[i], 0);
> }
>
> return 0;
>
> +err_remove_hcd:
> + usb_remove_hcd(hcd);
> err_pm_runtime:
> pm_runtime_put_sync(dev);
> pm_runtime_disable(dev);
This basically looks okay. But...
I don't know much about the usb-phy code. Is it really okay to call
usb_phy_shutdown() for something that hasn't gone through
usb_phy_init()? (Yes, the original code already does this -- maybe
the original code is also wrong.)
Alan Stern
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH v2] USB: ehci-omap: Fix missing usb_phy_init() error handling
2025-12-02 8:00 [PATCH] USB: ehci-omap: Fix missing usb_phy_init() error handling Haotian Zhang
2025-12-02 8:30 ` Greg KH
2025-12-02 16:05 ` Alan Stern
@ 2025-12-03 3:28 ` Haotian Zhang
2025-12-17 13:22 ` Greg KH
2 siblings, 1 reply; 5+ messages in thread
From: Haotian Zhang @ 2025-12-03 3:28 UTC (permalink / raw)
To: stern; +Cc: gregkh, linux-usb, linux-omap, linux-kernel, Haotian Zhang
usb_phy_init() may fail if the PHY clock or regulator setup fails,
but ehci_hcd_omap_probe() does not check its return value,
potentially causing later operations to act on an uninitialized PHY.
Original cleanup also calls usb_phy_shutdown() on uninitialized
PHYs, which is unsafe.
Add proper error checking for usb_phy_init() calls. Add a new
error label to properly remove the hcd. Use local bool array to
track successfully initialized PHYs, only shutdown properly
initialized PHYs during cleanup.
Fixes: 4e5c9e6fa2d2 ("USB: ehci-omap: Tweak PHY initialization sequence")
Fixes: 49f092198f4f ("USB: ehci-omap: Fix detection in HSIC mode")
Suggested-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
---
Changes in v2:
-Add a local bool array to track successfully initialized PHYs.
-Check if PHY is successfully initialized before
calling usb_phy_shutdown().
---
drivers/usb/host/ehci-omap.c | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/drivers/usb/host/ehci-omap.c b/drivers/usb/host/ehci-omap.c
index db4a1acb27da..f36083ee317c 100644
--- a/drivers/usb/host/ehci-omap.c
+++ b/drivers/usb/host/ehci-omap.c
@@ -89,6 +89,7 @@ static int ehci_hcd_omap_probe(struct platform_device *pdev)
int irq;
int i;
struct omap_hcd *omap;
+ bool phy_initialized[OMAP3_HS_USB_PORTS] = { false };
if (usb_disabled())
return -ENODEV;
@@ -166,7 +167,12 @@ static int ehci_hcd_omap_probe(struct platform_device *pdev)
omap->phy[i] = phy;
if (pdata->port_mode[i] == OMAP_EHCI_PORT_MODE_PHY) {
- usb_phy_init(omap->phy[i]);
+ ret = usb_phy_init(omap->phy[i]);
+ if (ret) {
+ dev_err(dev, "Failed to init PHY %d\n", i);
+ goto err_phy;
+ }
+ phy_initialized[i] = true;
/* bring PHY out of suspend */
usb_phy_set_suspend(omap->phy[i], 0);
}
@@ -205,20 +211,27 @@ static int ehci_hcd_omap_probe(struct platform_device *pdev)
pdata->port_mode[i] == OMAP_EHCI_PORT_MODE_PHY)
continue;
- usb_phy_init(omap->phy[i]);
+ ret = usb_phy_init(omap->phy[i]);
+ if (ret) {
+ dev_err(dev, "Failed to init PHY %d\n", i);
+ goto err_remove_hcd;
+ }
+ phy_initialized[i] = true;
/* bring PHY out of suspend */
usb_phy_set_suspend(omap->phy[i], 0);
}
return 0;
+err_remove_hcd:
+ usb_remove_hcd(hcd);
err_pm_runtime:
pm_runtime_put_sync(dev);
pm_runtime_disable(dev);
err_phy:
for (i = 0; i < omap->nports; i++) {
- if (omap->phy[i])
+ if (omap->phy[i] && phy_initialized[i])
usb_phy_shutdown(omap->phy[i]);
}
--
2.50.1.windows.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH v2] USB: ehci-omap: Fix missing usb_phy_init() error handling
2025-12-03 3:28 ` [PATCH v2] " Haotian Zhang
@ 2025-12-17 13:22 ` Greg KH
0 siblings, 0 replies; 5+ messages in thread
From: Greg KH @ 2025-12-17 13:22 UTC (permalink / raw)
To: Haotian Zhang; +Cc: stern, linux-usb, linux-omap, linux-kernel
On Wed, Dec 03, 2025 at 11:28:22AM +0800, Haotian Zhang wrote:
> usb_phy_init() may fail if the PHY clock or regulator setup fails,
> but ehci_hcd_omap_probe() does not check its return value,
> potentially causing later operations to act on an uninitialized PHY.
> Original cleanup also calls usb_phy_shutdown() on uninitialized
> PHYs, which is unsafe.
>
> Add proper error checking for usb_phy_init() calls. Add a new
> error label to properly remove the hcd. Use local bool array to
> track successfully initialized PHYs, only shutdown properly
> initialized PHYs during cleanup.
>
> Fixes: 4e5c9e6fa2d2 ("USB: ehci-omap: Tweak PHY initialization sequence")
> Fixes: 49f092198f4f ("USB: ehci-omap: Fix detection in HSIC mode")
> Suggested-by: Alan Stern <stern@rowland.harvard.edu>
> Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
> ---
> Changes in v2:
> -Add a local bool array to track successfully initialized PHYs.
> -Check if PHY is successfully initialized before
> calling usb_phy_shutdown().
> ---
> drivers/usb/host/ehci-omap.c | 19 ++++++++++++++++---
> 1 file changed, 16 insertions(+), 3 deletions(-)
Again, how was this found and tested?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-12-17 13:22 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-02 8:00 [PATCH] USB: ehci-omap: Fix missing usb_phy_init() error handling Haotian Zhang
2025-12-02 8:30 ` Greg KH
2025-12-02 16:05 ` Alan Stern
2025-12-03 3:28 ` [PATCH v2] " Haotian Zhang
2025-12-17 13:22 ` Greg KH
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox