All of lore.kernel.org
 help / color / mirror / Atom feed
From: Miquel Raynal <miquel.raynal@bootlin.com>
To: Mark Brown <broonie@kernel.org>
Cc: <linux-spi@vger.kernel.org>,
	Tudor Ambarus <Tudor.Ambarus@microchip.com>,
	linux-kernel@vger.kernel.org, zhengxunli@mxic.com.tw,
	juliensu@mxic.com.tw, ycllin@mxic.com.tw,
	Miquel Raynal <miquel.raynal@bootlin.com>
Subject: [PATCH] spi: Fix the logic around the maximum speed
Date: Wed,  3 Feb 2021 18:02:45 +0100	[thread overview]
Message-ID: <20210203170245.31236-1-miquel.raynal@bootlin.com> (raw)

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


             reply	other threads:[~2021-02-03 17:05 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-03 17:02 Miquel Raynal [this message]
2021-02-03 17:10 ` [PATCH] spi: Fix the logic around the maximum speed Fabio Estevam
2021-02-03 17:14   ` Miquel Raynal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210203170245.31236-1-miquel.raynal@bootlin.com \
    --to=miquel.raynal@bootlin.com \
    --cc=Tudor.Ambarus@microchip.com \
    --cc=broonie@kernel.org \
    --cc=juliensu@mxic.com.tw \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=ycllin@mxic.com.tw \
    --cc=zhengxunli@mxic.com.tw \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.