Patch "spi: spidev: mask SPI_CS_HIGH in SPI_IOC_RD_MODE" has been added to the 5.10-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    spi: spidev: mask SPI_CS_HIGH in SPI_IOC_RD_MODE

to the 5.10-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     spi-spidev-mask-spi_cs_high-in-spi_ioc_rd_mode.patch
and it can be found in the queue-5.10 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 9fc51aa2fc3b39cdd64d1aef21c9f5fa1bdfc91b
Author: Alexander Sverdlin <alexander.sverdlin@xxxxxxxxxxx>
Date:   Wed Nov 30 17:29:27 2022 +0100

    spi: spidev: mask SPI_CS_HIGH in SPI_IOC_RD_MODE
    
    [ Upstream commit 7dbfa445ff7393d1c4c066c1727c9e0af1251958 ]
    
    Commit f3186dd87669 ("spi: Optionally use GPIO descriptors for CS GPIOs")
    has changed the user-space interface so that bogus SPI_CS_HIGH started
    to appear in the mask returned by SPI_IOC_RD_MODE even for active-low CS
    pins. Commit 138c9c32f090
    ("spi: spidev: Fix CS polarity if GPIO descriptors are used") fixed only
    SPI_IOC_WR_MODE part of the problem. Let's fix SPI_IOC_RD_MODE
    symmetrically.
    
    Test case:
    
            #include <sys/ioctl.h>
            #include <fcntl.h>
            #include <linux/spi/spidev.h>
    
            int main(int argc, char **argv)
            {
                    char modew = SPI_CPHA;
                    char moder;
                    int f = open("/dev/spidev0.0", O_RDWR);
    
                    if (f < 0)
                            return 1;
    
                    ioctl(f, SPI_IOC_WR_MODE, &modew);
                    ioctl(f, SPI_IOC_RD_MODE, &moder);
    
                    return moder == modew ? 0 : 2;
            }
    
    Fixes: f3186dd87669 ("spi: Optionally use GPIO descriptors for CS GPIOs")
    Signed-off-by: Alexander Sverdlin <alexander.sverdlin@xxxxxxxxxxx>
    Link: https://lore.kernel.org/r/20221130162927.539512-1-alexander.sverdlin@xxxxxxxxxxx
    Signed-off-by: Mark Brown <broonie@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c
index 859910ec8d9f..9c5ec99431d2 100644
--- a/drivers/spi/spidev.c
+++ b/drivers/spi/spidev.c
@@ -376,12 +376,23 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 	switch (cmd) {
 	/* read requests */
 	case SPI_IOC_RD_MODE:
-		retval = put_user(spi->mode & SPI_MODE_MASK,
-					(__u8 __user *)arg);
-		break;
 	case SPI_IOC_RD_MODE32:
-		retval = put_user(spi->mode & SPI_MODE_MASK,
-					(__u32 __user *)arg);
+		tmp = spi->mode;
+
+		{
+			struct spi_controller *ctlr = spi->controller;
+
+			if (ctlr->use_gpio_descriptors && ctlr->cs_gpiods &&
+			    ctlr->cs_gpiods[spi->chip_select])
+				tmp &= ~SPI_CS_HIGH;
+		}
+
+		if (cmd == SPI_IOC_RD_MODE)
+			retval = put_user(tmp & SPI_MODE_MASK,
+					  (__u8 __user *)arg);
+		else
+			retval = put_user(tmp & SPI_MODE_MASK,
+					  (__u32 __user *)arg);
 		break;
 	case SPI_IOC_RD_LSB_FIRST:
 		retval = put_user((spi->mode & SPI_LSB_FIRST) ?  1 : 0,



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux