linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] spi: Fix the logic around the maximum speed
@ 2021-02-03 17:02 Miquel Raynal
  2021-02-03 17:10 ` Fabio Estevam
  0 siblings, 1 reply; 3+ messages in thread
From: Miquel Raynal @ 2021-02-03 17:02 UTC (permalink / raw)
  To: Mark Brown
  Cc: linux-spi, Tudor Ambarus, linux-kernel, zhengxunli, juliensu,
	ycllin, 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.

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 <miquel.raynal@bootlin.com>
---
 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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] spi: Fix the logic around the maximum speed
  2021-02-03 17:02 [PATCH] spi: Fix the logic around the maximum speed Miquel Raynal
@ 2021-02-03 17:10 ` Fabio Estevam
  2021-02-03 17:14   ` Miquel Raynal
  0 siblings, 1 reply; 3+ messages in thread
From: Fabio Estevam @ 2021-02-03 17:10 UTC (permalink / raw)
  To: Miquel Raynal
  Cc: Mark Brown, linux-spi, Tudor Ambarus, linux-kernel, zhengxunli,
	juliensu, ycllin

Hi Miquel,

On Wed, Feb 3, 2021 at 2:06 PM Miquel Raynal <miquel.raynal@bootlin.com> 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] spi: Fix the logic around the maximum speed
  2021-02-03 17:10 ` Fabio Estevam
@ 2021-02-03 17:14   ` Miquel Raynal
  0 siblings, 0 replies; 3+ messages in thread
From: Miquel Raynal @ 2021-02-03 17:14 UTC (permalink / raw)
  To: Fabio Estevam
  Cc: Mark Brown, linux-spi, Tudor Ambarus, linux-kernel, zhengxunli,
	juliensu, ycllin

Hi Fabio,

Fabio Estevam <festevam@gmail.com> wrote on Wed, 3 Feb 2021 14:10:15
-0300:

> Hi Miquel,
> 
> On Wed, Feb 3, 2021 at 2:06 PM Miquel Raynal <miquel.raynal@bootlin.com> 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-02-03 17:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-03 17:02 [PATCH] spi: Fix the logic around the maximum speed Miquel Raynal
2021-02-03 17:10 ` Fabio Estevam
2021-02-03 17:14   ` Miquel Raynal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).