SPI_IOC_WR_MAX_SPEED_HZ command always sets spi->max_speed_hz to the initial value come from DT. It leads to set a wrong max speed with IOCTL call. Fix the logic of a max speed assignment. Signed-off-by: Oleksandr Suvorov <oleksandr.suvorov@xxxxxxxxxxx> --- drivers/spi/spidev.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c index 1e217e3e9486..b9b3ac70eb18 100644 --- a/drivers/spi/spidev.c +++ b/drivers/spi/spidev.c @@ -449,11 +449,13 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) spi->max_speed_hz = tmp; retval = spi_setup(spi); - if (retval >= 0) + if (retval) { + spi->max_speed_hz = save; + } else { spidev->speed_hz = tmp; - else - dev_dbg(&spi->dev, "%d Hz (max)\n", tmp); - spi->max_speed_hz = save; + dev_dbg(&spi->dev, "%d Hz (max)\n", + spidev->speed_hz); + } } break; -- 2.24.1