Skip to content

Commit 7a4feff

Browse files
committed
spidev: A few cleanups
Merge series from Andy Shevchenko <[email protected]>: 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.
2 parents 0578a6d + 764246c commit 7a4feff

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

drivers/spi/spidev.c

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
357357
int retval = 0;
358358
struct spidev_data *spidev;
359359
struct spi_device *spi;
360+
struct spi_controller *ctlr;
360361
u32 tmp;
361362
unsigned n_ioc;
362363
struct spi_ioc_transfer *ioc;
@@ -376,6 +377,8 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
376377
return -ESHUTDOWN;
377378
}
378379

380+
ctlr = spi->controller;
381+
379382
/* use the buffer lock here for triple duty:
380383
* - prevent I/O (from us) so calling spi_setup() is safe;
381384
* - prevent concurrent SPI_IOC_WR_* from morphing
@@ -388,22 +391,15 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
388391
/* read requests */
389392
case SPI_IOC_RD_MODE:
390393
case SPI_IOC_RD_MODE32:
391-
tmp = spi->mode;
392-
393-
{
394-
struct spi_controller *ctlr = spi->controller;
394+
tmp = spi->mode & SPI_MODE_MASK;
395395

396-
if (ctlr->use_gpio_descriptors && ctlr->cs_gpiods &&
397-
ctlr->cs_gpiods[spi_get_chipselect(spi, 0)])
398-
tmp &= ~SPI_CS_HIGH;
399-
}
396+
if (ctlr->use_gpio_descriptors && spi_get_csgpiod(spi, 0))
397+
tmp &= ~SPI_CS_HIGH;
400398

401399
if (cmd == SPI_IOC_RD_MODE)
402-
retval = put_user(tmp & SPI_MODE_MASK,
403-
(__u8 __user *)arg);
400+
retval = put_user(tmp, (__u8 __user *)arg);
404401
else
405-
retval = put_user(tmp & SPI_MODE_MASK,
406-
(__u32 __user *)arg);
402+
retval = put_user(tmp, (__u32 __user *)arg);
407403
break;
408404
case SPI_IOC_RD_LSB_FIRST:
409405
retval = put_user((spi->mode & SPI_LSB_FIRST) ? 1 : 0,
@@ -424,16 +420,14 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
424420
else
425421
retval = get_user(tmp, (u32 __user *)arg);
426422
if (retval == 0) {
427-
struct spi_controller *ctlr = spi->controller;
428423
u32 save = spi->mode;
429424

430425
if (tmp & ~SPI_MODE_MASK) {
431426
retval = -EINVAL;
432427
break;
433428
}
434429

435-
if (ctlr->use_gpio_descriptors && ctlr->cs_gpiods &&
436-
ctlr->cs_gpiods[spi_get_chipselect(spi, 0)])
430+
if (ctlr->use_gpio_descriptors && spi_get_csgpiod(spi, 0))
437431
tmp |= SPI_CS_HIGH;
438432

439433
tmp |= spi->mode & ~SPI_MODE_MASK;

0 commit comments

Comments
 (0)