Skip to content

Commit 6170d07

Browse files
yilunxu1984broonie
authored andcommitted
spi: fix the divide by 0 error when calculating xfer waiting time
The xfer waiting time is the result of xfer->len / xfer->speed_hz. This patch makes the assumption of 100khz xfer speed if the xfer->speed_hz is not assigned and stays 0. This avoids the divide by 0 issue and ensures a reasonable tolerant waiting time. Signed-off-by: Xu Yilun <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 6820e81 commit 6170d07

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

drivers/spi/spi.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,7 @@ static int spi_transfer_wait(struct spi_controller *ctlr,
11081108
{
11091109
struct spi_statistics *statm = &ctlr->statistics;
11101110
struct spi_statistics *stats = &msg->spi->statistics;
1111+
u32 speed_hz = xfer->speed_hz;
11111112
unsigned long long ms;
11121113

11131114
if (spi_controller_is_slave(ctlr)) {
@@ -1116,8 +1117,11 @@ static int spi_transfer_wait(struct spi_controller *ctlr,
11161117
return -EINTR;
11171118
}
11181119
} else {
1120+
if (!speed_hz)
1121+
speed_hz = 100000;
1122+
11191123
ms = 8LL * 1000LL * xfer->len;
1120-
do_div(ms, xfer->speed_hz);
1124+
do_div(ms, speed_hz);
11211125
ms += ms + 200; /* some tolerance */
11221126

11231127
if (ms > UINT_MAX)

0 commit comments

Comments
 (0)