Re: [PATCH 5/5] spi: atmel: fix division by zero when transfer speed is zero

From: Mark Brown

Date: Mon Nov 09 2026 - 15:29:12 EST


> atmel_spi_one_transfer() calls atmel_spi_set_xfer_speed() for every
> transfer. A device whose max_speed_hz is zero (no spi-max-frequency
> property, or created through the spidev sysfs new_device interface
> without a speed) leaves the transfer speed at zero, and the divider
> calculation divides by it. spi_setup() would only clamp the speed if
> host->max_speed_hz was set, which this driver does not do.

...

> Clamp the divisor to 1 Hz so the zero never reaches the division.

> - scbr = DIV_ROUND_UP(bus_hz, xfer->speed_hz);
> + scbr = DIV_ROUND_UP(bus_hz, max_t(u32, xfer->speed_hz, 1));

This has a similar issue with limiting, in this case even worse as we
generate an invalid SCBR value and then validate it later in the
function. We should just set the maximum instead of bothering with the
division if we're subsituting a default here.

--
Mark Brown <broonie@xxxxxxxxxx>