Skip to content

Commit fb57f82

Browse files
3x380Vgregkh
authored andcommitted
usb: dwc3: dwc3-octeon: Verify clock divider
Although valid USB clock divider will be calculated for all valid Octeon core frequencies, make code formally correct limiting divider not to be greater that 7 so it fits into H_CLKDIV_SEL field. Signed-off-by: Ladislav Michl <[email protected]> Reported-by: Linux Kernel Functional Testing <[email protected]> Closes: https://qa-reports.linaro.org/lkft/linux-next-master/build/next-20230808/testrun/18882876/suite/build/test/gcc-8-cavium_octeon_defconfig/log Acked-by: Thinh Nguyen <[email protected]> Link: https://lore.kernel.org/r/ZNIM7tlBNdHFzXZG@lenoch Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent ff33299 commit fb57f82

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

drivers/usb/dwc3/dwc3-octeon.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,11 @@ static int dwc3_octeon_get_divider(void)
251251
while (div < ARRAY_SIZE(clk_div)) {
252252
uint64_t rate = octeon_get_io_clock_rate() / clk_div[div];
253253
if (rate <= 300000000 && rate >= 150000000)
254-
break;
254+
return div;
255255
div++;
256256
}
257257

258-
return div;
258+
return -EINVAL;
259259
}
260260

261261
static int dwc3_octeon_setup(struct dwc3_octeon *octeon,
@@ -289,6 +289,10 @@ static int dwc3_octeon_setup(struct dwc3_octeon *octeon,
289289

290290
/* Step 4b: Select controller clock frequency. */
291291
div = dwc3_octeon_get_divider();
292+
if (div < 0) {
293+
dev_err(dev, "clock divider invalid\n");
294+
return div;
295+
}
292296
val = dwc3_octeon_readq(uctl_ctl_reg);
293297
val &= ~USBDRD_UCTL_CTL_H_CLKDIV_SEL;
294298
val |= FIELD_PREP(USBDRD_UCTL_CTL_H_CLKDIV_SEL, div);

0 commit comments

Comments
 (0)