cavium/bdk: Fix possible divide by zero

Fix Coverity CID1393970

Change-Id: I5db6866b8e51eaea201a4c03e59d7d00f4f826e7
Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
Reviewed-on: https://review.coreboot.org/27453
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Philipp Deppenwiese <zaolin.daisuki@gmail.com>
This commit is contained in:
Patrick Rudolph 2018-07-12 13:13:24 +02:00 committed by Patrick Rudolph
parent 4461613119
commit 239e435739
1 changed files with 3 additions and 1 deletions

View File

@ -369,7 +369,9 @@ int bdk_usb_initialize(bdk_node_t node, int usb_port, bdk_usb_clock_t clock_type
uint64_t fr_div; uint64_t fr_div;
if (divider < 5) fr_div = divider * 2; if (divider < 5) fr_div = divider * 2;
else fr_div = 8 * (divider - 3); else fr_div = 8 * (divider - 3);
uint64_t freq = (typeof(freq)) (sclk_rate / fr_div); uint64_t freq = 0;
if (fr_div > 0)
freq = (typeof(freq)) (sclk_rate / fr_div);
const char *token; const char *token;
if (freq < 62500000ULL) token = "???Low"; if (freq < 62500000ULL) token = "???Low";
else if (freq < 90000000ULL) token = "USB2"; else if (freq < 90000000ULL) token = "USB2";