[PATCH] spi: Limit the spi device max speed to controller's max speed

From: Tudor Ambarus
Date: Wed Dec 09 2020 - 12:36:57 EST


Make sure the max_speed_hz of spi_device does not override
the max_speed_hz of controller.

Signed-off-by: Tudor Ambarus <tudor.ambarus@xxxxxxxxxxxxx>
---
drivers/spi/spi.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index cd3c395b4e90..51d7c004fbab 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -3378,7 +3378,8 @@ int spi_setup(struct spi_device *spi)
if (status)
return status;

- if (!spi->max_speed_hz)
+ if (!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.25.1