diff mbox

SPI_IOC_WR_MAX_SPEED_HZ was overwitten?

Message ID 9BA84827B30CBE4996725F98F7DC91236563EEE4@SMExchange01.siebmeyer.org (mailing list archive)
State New, archived
Headers show

Commit Message

Hänel-Baas, Alexander Aug. 29, 2017, 2:13 p.m. UTC
Hi

> Is it possible that the ioctl SPI_IOC_WR_MODE call can 
> overwrite the previous ioctl SPI_IOC_WR_MAX_SPEED_HZ speed setting?

Yes it is. Please take a look in spidev.c Line 488. 
In the spidev_ioctl() function at the SPI_IOC_WR_MAX_SPEED_HZ case the
spi->max_speed_hz value was always overwritten with the old "save" value
regardless if the spi_setup call was successful or not.

--Snip--  
else
	dev_dbg(&spi->dev, "%d Hz (max)\n", tmp);
spi->max_speed_hz = save;
}
break;
--snip--

Every following ioctl call will restore the wrong speed value.
 
Here is my patch to correct this:
Can anybody review this please?

With this patch  my program works fine with the spidev and the tool flashrom also.

Best regards,
Alexander

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

--- a/drivers/spi/spidev.c
+++ b/drivers/spi/spidev.c
@@ -480,11 +480,10 @@ 
 
 			spi->max_speed_hz = tmp;
 			retval = spi_setup(spi);
-			if (retval >= 0)
-				spidev->speed_hz = tmp;
+			if (retval < 0)
+				spidev->speed_hz = save;
 			else
 				dev_dbg(&spi->dev, "%d Hz (max)\n", tmp);
-			spi->max_speed_hz = save;
 		}
 		break;