Skip to content

Commit

Permalink
spidev: A few cleanups
Browse files Browse the repository at this point in the history
Merge series from Andy Shevchenko <andriy.shevchenko@linux.intel.com>:

A few cleanups to the spidev.c to utilize existing APIs and make it
use less amount of Lines of Code. No functional change intended.
  • Loading branch information
Mark Brown committed Sep 11, 2023
2 parents 0578a6d + 764246c commit 7a4feff
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions drivers/spi/spidev.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
int retval = 0;
struct spidev_data *spidev;
struct spi_device *spi;
struct spi_controller *ctlr;
u32 tmp;
unsigned n_ioc;
struct spi_ioc_transfer *ioc;
Expand All @@ -376,6 +377,8 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
return -ESHUTDOWN;
}

ctlr = spi->controller;

/* use the buffer lock here for triple duty:
* - prevent I/O (from us) so calling spi_setup() is safe;
* - prevent concurrent SPI_IOC_WR_* from morphing
Expand All @@ -388,22 +391,15 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
/* read requests */
case SPI_IOC_RD_MODE:
case SPI_IOC_RD_MODE32:
tmp = spi->mode;

{
struct spi_controller *ctlr = spi->controller;
tmp = spi->mode & SPI_MODE_MASK;

if (ctlr->use_gpio_descriptors && ctlr->cs_gpiods &&
ctlr->cs_gpiods[spi_get_chipselect(spi, 0)])
tmp &= ~SPI_CS_HIGH;
}
if (ctlr->use_gpio_descriptors && spi_get_csgpiod(spi, 0))
tmp &= ~SPI_CS_HIGH;

if (cmd == SPI_IOC_RD_MODE)
retval = put_user(tmp & SPI_MODE_MASK,
(__u8 __user *)arg);
retval = put_user(tmp, (__u8 __user *)arg);
else
retval = put_user(tmp & SPI_MODE_MASK,
(__u32 __user *)arg);
retval = put_user(tmp, (__u32 __user *)arg);
break;
case SPI_IOC_RD_LSB_FIRST:
retval = put_user((spi->mode & SPI_LSB_FIRST) ? 1 : 0,
Expand All @@ -424,16 +420,14 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
else
retval = get_user(tmp, (u32 __user *)arg);
if (retval == 0) {
struct spi_controller *ctlr = spi->controller;
u32 save = spi->mode;

if (tmp & ~SPI_MODE_MASK) {
retval = -EINVAL;
break;
}

if (ctlr->use_gpio_descriptors && ctlr->cs_gpiods &&
ctlr->cs_gpiods[spi_get_chipselect(spi, 0)])
if (ctlr->use_gpio_descriptors && spi_get_csgpiod(spi, 0))
tmp |= SPI_CS_HIGH;

tmp |= spi->mode & ~SPI_MODE_MASK;
Expand Down

0 comments on commit 7a4feff

Please sign in to comment.