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).
Fixes: 9326e4f1e5dd ("spi: Limit the spi device max speed to controller's max speed")
Signed-off-by: Miquel Raynal <[email protected]>
---
drivers/spi/spi.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 51d7c004fbab..f59bf5094adb 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -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);
--
2.20.1
Hi Miquel,
On Wed, Feb 3, 2021 at 2:06 PM Miquel Raynal <[email protected]> wrote:
>
> 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:
> Hi Miquel,
>
> On Wed, Feb 3, 2021 at 2:06 PM Miquel Raynal <[email protected]> wrote:
> >
> > 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