Message ID | 20221130143948.426640-1-alexander.sverdlin@siemens.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | spi: spidev: mask SPI_CS_HIGH in SPI_IOC_RD_MODE | expand |
On Wed, Nov 30, 2022 at 03:39:48PM +0100, A. Sverdlin wrote: > /* read requests */ > case SPI_IOC_RD_MODE: > - retval = put_user(spi->mode & SPI_MODE_MASK, > - (__u8 __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; > + } > + > + retval = put_user(tmp & SPI_MODE_MASK, (__u8 __user *)arg); > break; > case SPI_IOC_RD_MODE32: > retval = put_user(spi->mode & SPI_MODE_MASK, What about SPI_IOC_RD_MODE_32? On the write path the code is shared...
Hello Mark, On Wed, 2022-11-30 at 14:57 +0000, Mark Brown wrote: > > /* read requests */ > > case SPI_IOC_RD_MODE: > > - retval = put_user(spi->mode & SPI_MODE_MASK, > > - (__u8 __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; > > + } > > + > > + retval = put_user(tmp & SPI_MODE_MASK, (__u8 > > __user *)arg); > > break; > > case SPI_IOC_RD_MODE32: > > retval = put_user(spi->mode & SPI_MODE_MASK, > > What about SPI_IOC_RD_MODE_32? On the write path the code is > shared... you are right, thanks for this hint! I'll re-send if there are no objections to this approach in general.
On Wed, Nov 30, 2022 at 03:43:27PM +0000, Sverdlin, Alexander wrote: > On Wed, 2022-11-30 at 14:57 +0000, Mark Brown wrote: > > What about SPI_IOC_RD_MODE_32? On the write path the code is > > shared... > you are right, thanks for this hint! > I'll re-send if there are no objections to this approach in general. Should be fine.
diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c index b2775d82d2d7b..23177a7c916c3 100644 --- a/drivers/spi/spidev.c +++ b/drivers/spi/spidev.c @@ -377,8 +377,17 @@ 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); + 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; + } + + retval = put_user(tmp & SPI_MODE_MASK, (__u8 __user *)arg); break; case SPI_IOC_RD_MODE32: retval = put_user(spi->mode & SPI_MODE_MASK,