]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
spi: spidev: Restore all SPI mode flags on ioctl failure
authorGeert Uytterhoeven <geert+renesas@linux-m68k.org>
Tue, 25 Feb 2014 10:40:16 +0000 (11:40 +0100)
committerMark Brown <broonie@linaro.org>
Thu, 27 Feb 2014 04:50:33 +0000 (13:50 +0900)
In commit f477b7fb13df2b843997559ff34e87d054ba6538 ("spi: DUAL and QUAD
support"), spi_device.mode was enlarged from 8 to 16 bits.

However, the spidev code still only saved 8 bits of data. If a spidev
SPI_IOC_WR_MODE or SPI_IOC_WR_LSB_FIRST request failed, only the lower 8
bits of the SPI mode were restored, inadvertently clearing the upper 8
bits, possibly disabling Quad or Dual SPI transfers for the device.

Save up to 32 bits to fix this.

For SPI_IOC_WR_MODE this is probably not so important, as it doesn't allow
setting Quad or Dual mode anyway, but SPI_IOC_WR_LSB_FIRST is used to just
set or clear a single bit.

Signed-off-by: Geert Uytterhoeven <geert+renesas@linux-m68k.org>
Signed-off-by: Mark Brown <broonie@linaro.org>
drivers/spi/spidev.c

index d7c6e36021e884727f9bd0a7fc858d83824d441a..2abc0f5a82beb3ddea77b8557fc8fa242125d1d2 100644 (file)
@@ -374,7 +374,7 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
        case SPI_IOC_WR_MODE:
                retval = __get_user(tmp, (u8 __user *)arg);
                if (retval == 0) {
-                       u     save = spi->mode;
+                       u32     save = spi->mode;
 
                        if (tmp & ~SPI_MODE_MASK) {
                                retval = -EINVAL;
@@ -393,7 +393,7 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
        case SPI_IOC_WR_LSB_FIRST:
                retval = __get_user(tmp, (__u8 __user *)arg);
                if (retval == 0) {
-                       u     save = spi->mode;
+                       u32     save = spi->mode;
 
                        if (tmp)
                                spi->mode |= SPI_LSB_FIRST;