[U-Boot] [PATCH] spi: kirkwood: avoid divide by zero crash

Baruch Siach baruch at tkos.co.il
Thu Nov 9 11:39:03 UTC 2017


Calling .set_speed with zero speed is definitely a bug. Return an error value
to handle that gracefully instead of crashing.

Signed-off-by: Baruch Siach <baruch at tkos.co.il>
---
 drivers/spi/kirkwood_spi.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/spi/kirkwood_spi.c b/drivers/spi/kirkwood_spi.c
index 0c6bd295cde9..9a27ac36822e 100644
--- a/drivers/spi/kirkwood_spi.c
+++ b/drivers/spi/kirkwood_spi.c
@@ -257,6 +257,8 @@ static int mvebu_spi_set_speed(struct udevice *bus, uint hz)
 	struct kwspi_registers *reg = plat->spireg;
 	u32 data;
 
+	if (hz == 0)
+		return -EINVAL;
 	/* calculate spi clock prescaller using max_hz */
 	data = ((CONFIG_SYS_TCLK / 2) / hz) + 0x10;
 	data = data < KWSPI_CLKPRESCL_MIN ? KWSPI_CLKPRESCL_MIN : data;
-- 
2.14.2



More information about the U-Boot mailing list