spi: Fix the logic around the maximum speed
PATCH 1/1 spi: Fix the logic around the maximum speed
Commit 9326e4f1e5dd ("spi: Limit the spi device max speed to controller's max speed") rationaly introduced a new condition on which the device's maximum speed would be set to the controller's one: if the device advertizes a higher speed than the one supported by the controller.
However, it seems that the SPI core does not enforce controllers to always advertize a maximum speed value. Other similar conditions in the SPI core always check that the controller->max_speed_hz was set before doing anything else.
Not doing this check here breaks SPI controller drivers which do not advertize a maximum speed:
- the controller maximum speed is 0
- the child device max speed is set to an apparently coeherent value
- in this case the child device maximum speed is set to 0
Either (1) all controller drivers should set max_speed_hz or (2) the child device maximum speed should not be updated in this particular situation. Perhaps there is a rationale for not enforcing (1), but in any case as a fix it is safer to use solution (2).
--- drivers/spi/spi.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/spi/spi.c +3 -2
@@ -3378,8 +3378,9 @@ int spi_setup(struct spi_device *spi)if (status)return status; -if (!spi->max_speed_hz || - spi->max_speed_hz > spi->controller->max_speed_hz) +if (spi->controller->max_speed_hz && + (!spi->max_speed_hz || + spi->max_speed_hz > spi->controller->max_speed_hz)) spi->max_speed_hz = spi->controller->max_speed_hz;mutex_lock (&spi->controller->io_mutex);
Signature · 1 line
2.20.1
Hi Miquel,
Quoted 5 lines · Miquel Raynal
Commit
9326e4f1e5dd("spi: Limit the spi device max speed to controller's max speed") rationaly introduced a new condition on which the device's maximum speed would be set to the controller's one: if the device advertizes a higher speed than the one supported by the controller.
Already fixed:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=6820e812dafb4258bc14692f686eec5bde6fba86
Hi Fabio,
Fabio Estevam <[email protected]> wrote on Wed, 3 Feb 2021 14:10:15 -0300:
Quoted 11 lines
Hi Miquel,
Quoted 5 lines · Miquel Raynal
Commit
9326e4f1e5dd("spi: Limit the spi device max speed to controller's max speed") rationaly introduced a new condition on which the device's maximum speed would be set to the controller's one: if the device advertizes a higher speed than the one supported by the controller.Already fixed:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=6820e812dafb4258bc14692f686eec5bde6fba86
Oh crap :') Indeed I wasn't based on the right -rc to get the fix.
Thanks for the heads up!
Miquèl