Skip to contentSkip to conversation

usb: dwc3: fix abort on invalid ref clock rate from clk_get_rate()

PATCH In review Frank Wang 3 participants 4 messages Nov 3 – Nov 4

Subsystems (3)
lore
Share & tools
lore

Frank Wang

author
#0 lore raw

PATCH 1/1 usb: dwc3: fix abort on invalid ref clock rate from clk_get_rate()

On 32-bit platforms, "usb start" aborted with
"### ERROR ### Please RESET the board ###". If the clock driver does not implement the "ref" clock, clk_get_rate() returns -ENOENT, which dwc3_ref_clk_period() treated as a valid rate. period became 0 and the fladj calculation divided by zero; the software 64-bit division on 32-bit ARM calls the division-by-zero handler __div0() and hangs (64-bit platforms survive silently since UDIV returns 0).

Skip REFCLKPER/GFLADJ programming when clk_get_rate() returns an error code, as is already done for rate == 0.

Fixes 6bae0eb5b8bd ("usb: dwc3: Calculate REFCLKPER based on reference clock")
---
 drivers/usb/dwc3/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/dwc3/core.c +1 -1
index be198041f08..9a84ec6a60e 100644
@@ -151,7 +151,7 @@ static void dwc3_ref_clk_period(struct dwc3 *dwc)
 
 	if (dwc->ref_clk) {
 		rate = clk_get_rate(dwc->ref_clk);
-		if (!rate)
+		if (!rate || IS_ERR_VALUE(rate))
 			return;
 		period = NSEC_PER_SEC / rate;
 	} else {
Signature · 1 line
2.17.1
#1 lore raw

Hi Frank,

There's a big rebase to sync with upstream Linux driver [1][2], I think it's due to land shortly, does the issue still occur with that?

It would be good to get the rockchips SoCs with the dwc3 controller tested with that rebase.

Peter

[1] https://lists.u-boot-project.org/pipermail/u-boot/2026-October/637669.html
[2] https://lists.u-boot-project.org/pipermail/u-boot/2026-October/637734.html

Quoted 33 lines · Frank Wang

On 32-bit platforms, "usb start" aborted with
"### ERROR ### Please RESET the board ###". If the clock driver does not implement the "ref" clock, clk_get_rate() returns -ENOENT, which dwc3_ref_clk_period() treated as a valid rate. period became 0 and the fladj calculation divided by zero; the software 64-bit division on 32-bit ARM calls the division-by-zero handler __div0() and hangs (64-bit platforms survive silently since UDIV returns 0).

Skip REFCLKPER/GFLADJ programming when clk_get_rate() returns an error code, as is already done for rate == 0.

Fixes 6bae0eb5b8bd ("usb: dwc3: Calculate REFCLKPER based on reference clock")
---
 drivers/usb/dwc3/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/dwc3/core.c +1 -2
index be198041f08..9a84ec6a60e 100644
@@ -151,7 +151,7 @@ static void dwc3_ref_clk_period(struct dwc3 *dwc)
 
        if (dwc->ref_clk) {
                rate = clk_get_rate(dwc->ref_clk);
-               if (!rate)
+               if (!rate || IS_ERR_VALUE(rate))
                        return;
                period = NSEC_PER_SEC / rate;
        } else {
--
Quoted 2 lines

2.17.1

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip

author
#2 lore raw

Hi Peter,

Quoted 5 lines · Peter Robinson

Hi Frank,

There's a big rebase to sync with upstream Linux driver [1][2], I think it's due to land shortly, does the issue still occur with that?

Quoted 7 lines

It would be good to get the rockchips SoCs with the dwc3 controller tested with that rebase.

Peter

[1] https://lists.u-boot-project.org/pipermail/u-boot/2026-October/637669.html
[2] https://lists.u-boot-project.org/pipermail/u-boot/2026-October/637734.html

I checked the usb_dwc3_sync_v10 branch referenced in your email, and found no code changes related to this issue.

In the Linux kernel driver, getting the dwc->ref_clk rate is mandatory, so this issue does not surface. In U-Boot, however, getting the clock rate is optional. Some platform vendor clock drivers do not implement clock rate retrieval for all clock IDs. Therefore, adding a check for the -ENOENT return value can improve code robustness.

Additionally, mainline U-Boot codes do not yet include support for Rockchip 32-bit SoCs with dwc3 controllers.

Best regards,
Frank

Quoted 25 lines · Frank Wang
Quoted 24 lines

On 32-bit platforms, "usb start" aborted with
"### ERROR ### Please RESET the board ###". If the clock driver does not implement the "ref" clock, clk_get_rate() returns -ENOENT, which dwc3_ref_clk_period() treated as a valid rate. period became 0 and the fladj calculation divided by zero; the software 64-bit division on 32-bit ARM calls the division-by-zero handler __div0() and hangs (64-bit platforms survive silently since UDIV returns 0).

Skip REFCLKPER/GFLADJ programming when clk_get_rate() returns an error code, as is already done for rate == 0.

Fixes 6bae0eb5b8bd ("usb: dwc3: Calculate REFCLKPER based on reference clock")
---
 drivers/usb/dwc3/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/dwc3/core.c +0 -0
index be198041f08..9a84ec6a60e 100644
@@ -151,7 +151,7 @@ static void dwc3_ref_clk_period(struct dwc3 *dwc)
 
Quoted 10 lines
Quoted 10 lines
drivers/usb/dwc3/core.c +1 -2
        if (dwc->ref_clk) {
                rate = clk_get_rate(dwc->ref_clk);
-               if (!rate)
+               if (!rate || IS_ERR_VALUE(rate))
                        return;
                period = NSEC_PER_SEC / rate;
        } else {
--

2.17.1

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip

Reviewed-by
#3 lore raw
Quoted 13 lines · Frank Wang

Hi Peter,

Quoted 10 lines · Peter Robinson

Hi Frank,

There's a big rebase to sync with upstream Linux driver [1][2], I think it's due to land shortly, does the issue still occur with that?

It would be good to get the rockchips SoCs with the dwc3 controller tested with that rebase.

Peter

Quoted 8 lines
Quoted 2 lines

[1] https://lists.u-boot-project.org/pipermail/u-boot/2026-October/637669.html
[2] https://lists.u-boot-project.org/pipermail/u-boot/2026-October/637734.html

I checked the usb_dwc3_sync_v10 branch referenced in your email, and found no code changes related to this issue.

In the Linux kernel driver, getting the dwc->ref_clk rate is mandatory, so this issue does not surface. In U-Boot, however, getting the clock rate is optional. Some platform vendor clock drivers do not implement clock rate retrieval for all clock IDs. Therefore, adding a check for the -ENOENT return value can improve code robustness.

It would probably be better to return 0, but alas that ship has sailed.

Quoted 31 lines

Additionally, mainline U-Boot codes do not yet include support for Rockchip 32-bit SoCs with dwc3 controllers.

Best regards,
Frank

Quoted 25 lines · Frank Wang
Quoted 24 lines

On 32-bit platforms, "usb start" aborted with
"### ERROR ### Please RESET the board ###". If the clock driver does not implement the "ref" clock, clk_get_rate() returns -ENOENT, which dwc3_ref_clk_period() treated as a valid rate. period became 0 and the fladj calculation divided by zero; the software 64-bit division on 32-bit ARM calls the division-by-zero handler __div0() and hangs (64-bit platforms survive silently since UDIV returns 0).

Skip REFCLKPER/GFLADJ programming when clk_get_rate() returns an error code, as is already done for rate == 0.

Fixes 6bae0eb5b8bd ("usb: dwc3: Calculate REFCLKPER based on reference clock")
---
  drivers/usb/dwc3/core.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/dwc3/core.c +0 -0
index be198041f08..9a84ec6a60e 100644
@@ -151,7 +151,7 @@ static void dwc3_ref_clk_period(struct dwc3 *dwc)
 
Quoted 11 lines
Quoted 10 lines
Quoted 10 lines
drivers/usb/dwc3/core.c +1 -2
         if (dwc->ref_clk) {
                 rate = clk_get_rate(dwc->ref_clk);
-               if (!rate)
+               if (!rate || IS_ERR_VALUE(rate))
                         return;
                 period = NSEC_PER_SEC / rate;
         } else {
--

2.17.1

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip