Skip to content

Commit 501e187

Browse files
yilunxu1984gregkh
authored andcommitted
spi: fix the divide by 0 error when calculating xfer waiting time
[ Upstream commit 6170d07 ] 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 <yilun.xu@intel.com> Link: https://lore.kernel.org/r/1609723749-3557-1-git-send-email-yilun.xu@intel.com Signed-off-by: Mark Brown <broonie@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 17a0868 commit 501e187

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

‎drivers/spi/spi.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1100,6 +1100,7 @@ static int spi_transfer_wait(struct spi_controller *ctlr,
11001100
{
11011101
struct spi_statistics *statm = &ctlr->statistics;
11021102
struct spi_statistics *stats = &msg->spi->statistics;
1103+
u32 speed_hz = xfer->speed_hz;
11031104
unsigned long long ms;
11041105

11051106
if (spi_controller_is_slave(ctlr)) {
@@ -1108,8 +1109,11 @@ static int spi_transfer_wait(struct spi_controller *ctlr,
11081109
return -EINTR;
11091110
}
11101111
} else {
1112+
if (!speed_hz)
1113+
speed_hz = 100000;
1114+
11111115
ms = 8LL * 1000LL * xfer->len;
1112-
do_div(ms, xfer->speed_hz);
1116+
do_div(ms, speed_hz);
11131117
ms += ms + 200; /* some tolerance */
11141118

11151119
if (ms > UINT_MAX)

0 commit comments

Comments
 (0)