diff mbox series

[1/3] usb: dwc3: handle return value of clk_get_rate() correctly

Message ID 20240203-hisi-dwc3-v1-1-448050c7b690@outlook.com
State New
Delegated to: Marek Vasut
Headers show
Series usb: dwv3: add glue driver for hi3798mv200 | expand

Commit Message

Yang Xiwen via B4 Relay Feb. 2, 2024, 11:01 p.m. UTC
From: Yang Xiwen <forbidden405@outlook.com>

clk_get_rate() return -ve on error, not 0. Fix it by replacing judging
NULL with IS_ERR_VALUE().

Fixes: 6bae0eb5b8bd("usb: dwc3: Calculate REFCLKPER based on reference clock")
Signed-off-by: Yang Xiwen <forbidden405@outlook.com>
---
 drivers/usb/dwc3/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Dan Carpenter Feb. 5, 2024, 7:25 a.m. UTC | #1
On Sat, Feb 03, 2024 at 07:01:54AM +0800, Yang Xiwen via B4 Relay wrote:
> From: Yang Xiwen <forbidden405@outlook.com>
> 
> clk_get_rate() return -ve on error, not 0. Fix it by replacing judging
> NULL with IS_ERR_VALUE().
  ^^^^

s/NULL/zero/.

I'd be surprised if clk_get_rate() *never* returns zero.  The Linux
kernel's clk_get_rate() function returns zero and not error codes, btw.

regards,
dan carpenter
Yang Xiwen Feb. 5, 2024, 8:40 a.m. UTC | #2
On 2/5/2024 3:25 PM, Dan Carpenter wrote:
> On Sat, Feb 03, 2024 at 07:01:54AM +0800, Yang Xiwen via B4 Relay wrote:
>> From: Yang Xiwen <forbidden405@outlook.com>
>>
>> clk_get_rate() return -ve on error, not 0. Fix it by replacing judging
>> NULL with IS_ERR_VALUE().
>    ^^^^
>
> s/NULL/zero/.
>
> I'd be surprised if clk_get_rate() *never* returns zero.  The Linux
> kernel's clk_get_rate() function returns zero and not error codes, btw.
Yes, it's really surprising. U-Boot clk APIs are a little different from 
Linux kernel's. Sadly it's a bit too late to fix it since there are 
really plenty of existing users. Maybe we need to put some hints in the 
docs.
> regards,
> dan carpenter
>
>
diff mbox series

Patch

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 4b4fcd8a22..06ff68105e 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -137,7 +137,7 @@  static void dwc3_ref_clk_period(struct dwc3 *dwc)
 
 	if (dwc->ref_clk) {
 		rate = clk_get_rate(dwc->ref_clk);
-		if (!rate)
+		if (IS_ERR_VALUE(rate))
 			return;
 		period = NSEC_PER_SEC / rate;
 	} else {