]> git.baikalelectronics.ru Git - kernel.git/commit
spi: spidev: mask SPI_CS_HIGH in SPI_IOC_RD_MODE
authorAlexander Sverdlin <alexander.sverdlin@siemens.com>
Wed, 30 Nov 2022 16:29:27 +0000 (17:29 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 18 Jan 2023 10:41:08 +0000 (11:41 +0100)
commitb5c63fd815516e1da61491ea7389516d99e184d6
tree0e5ca7b93df7f892c3c4778f9d8ce41463678d59
parent4168c9851c607934dc5ffa66eacedaacac1c585e
spi: spidev: mask SPI_CS_HIGH in SPI_IOC_RD_MODE

[ Upstream commit 7dbfa445ff7393d1c4c066c1727c9e0af1251958 ]

Commit 9bc982f86df7 ("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 ae4abee1686d
("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: 9bc982f86df7 ("spi: Optionally use GPIO descriptors for CS GPIOs")
Signed-off-by: Alexander Sverdlin <alexander.sverdlin@siemens.com>
Link: https://lore.kernel.org/r/20221130162927.539512-1-alexander.sverdlin@siemens.com
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/spi/spidev.c