Skip to content

Commit 16eeaec

Browse files
Boris BREZILLONMike Turquette
authored andcommitted
clk: at91: fix div by zero in USB clock driver
Test rate value before calculating the div value to avoid div by zero. Signed-off-by: Boris BREZILLON <boris.brezillon@free-electrons.com> Reported-by: Gaël PORTAY <gael.portay@gmail.com> Tested-by: Gaël PORTAY <gael.portay@gmail.com> Signed-off-by: Mike Turquette <mturquette@linaro.org>
1 parent 13a6073 commit 16eeaec

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

‎drivers/clk/at91/clk-usb.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,13 @@ static int at91rm9200_clk_usb_set_rate(struct clk_hw *hw, unsigned long rate,
279279
int i;
280280
struct at91rm9200_clk_usb *usb = to_at91rm9200_clk_usb(hw);
281281
struct at91_pmc *pmc = usb->pmc;
282-
unsigned long div = parent_rate / rate;
282+
unsigned long div;
283283

284-
if (parent_rate % rate)
284+
if (!rate || parent_rate % rate)
285285
return -EINVAL;
286+
287+
div = parent_rate / rate;
288+
286289
for (i = 0; i < RM9200_USB_DIV_TAB_SIZE; i++) {
287290
if (usb->divisors[i] == div) {
288291
tmp = pmc_read(pmc, AT91_CKGR_PLLBR) &

0 commit comments

Comments
 (0)