[U-Boot] [PATCH v2] spi: kirkwood: avoid divide by zero crash
Baruch Siach
baruch at tkos.co.il
Sun Nov 12 15:30:57 UTC 2017
Calling .set_speed with zero speed is definitely a bug. Instead of crashing,
set hz to 1 so that we get the lowest possible frequency rate.
Signed-off-by: Baruch Siach <baruch at tkos.co.il>
---
v2: Don't fail; set lowest rate (Jagan)
---
drivers/spi/kirkwood_spi.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/spi/kirkwood_spi.c b/drivers/spi/kirkwood_spi.c
index 0c6bd295cde9..5744849a5ad9 100644
--- a/drivers/spi/kirkwood_spi.c
+++ b/drivers/spi/kirkwood_spi.c
@@ -257,6 +257,9 @@ static int mvebu_spi_set_speed(struct udevice *bus, uint hz)
struct kwspi_registers *reg = plat->spireg;
u32 data;
+ /* Avoid divide by zero; instead, set the lowest possible speed */
+ if (hz == 0)
+ hz = 1;
/* calculate spi clock prescaller using max_hz */
data = ((CONFIG_SYS_TCLK / 2) / hz) + 0x10;
data = data < KWSPI_CLKPRESCL_MIN ? KWSPI_CLKPRESCL_MIN : data;
--
2.15.0
More information about the U-Boot
mailing list