Commit 4ef754b7 authored by Alan Cox's avatar Alan Cox Committed by Linus Torvalds

spidev: BKL removal

Another step to removing ->ioctl and to removing the BKL

[dbrownell@users.sourceforge.net: take final step; BKL not needed]
Signed-off-by: default avatarAlan Cox <alan@redhat.com>
Signed-off-by: default avatarDavid Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 102eb975
...@@ -228,7 +228,6 @@ static int spidev_message(struct spidev_data *spidev, ...@@ -228,7 +228,6 @@ static int spidev_message(struct spidev_data *spidev,
* We walk the array of user-provided transfers, using each one * We walk the array of user-provided transfers, using each one
* to initialize a kernel version of the same transfer. * to initialize a kernel version of the same transfer.
*/ */
mutex_lock(&spidev->buf_lock);
buf = spidev->buffer; buf = spidev->buffer;
total = 0; total = 0;
for (n = n_xfers, k_tmp = k_xfers, u_tmp = u_xfers; for (n = n_xfers, k_tmp = k_xfers, u_tmp = u_xfers;
...@@ -296,14 +295,12 @@ static int spidev_message(struct spidev_data *spidev, ...@@ -296,14 +295,12 @@ static int spidev_message(struct spidev_data *spidev,
status = total; status = total;
done: done:
mutex_unlock(&spidev->buf_lock);
kfree(k_xfers); kfree(k_xfers);
return status; return status;
} }
static int static long
spidev_ioctl(struct inode *inode, struct file *filp, spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
unsigned int cmd, unsigned long arg)
{ {
int err = 0; int err = 0;
int retval = 0; int retval = 0;
...@@ -341,6 +338,14 @@ spidev_ioctl(struct inode *inode, struct file *filp, ...@@ -341,6 +338,14 @@ spidev_ioctl(struct inode *inode, struct file *filp,
if (spi == NULL) if (spi == NULL)
return -ESHUTDOWN; return -ESHUTDOWN;
/* 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
* data fields while SPI_IOC_RD_* reads them;
* - SPI_IOC_MESSAGE needs the buffer locked "normally".
*/
mutex_lock(&spidev->buf_lock);
switch (cmd) { switch (cmd) {
/* read requests */ /* read requests */
case SPI_IOC_RD_MODE: case SPI_IOC_RD_MODE:
...@@ -456,6 +461,8 @@ spidev_ioctl(struct inode *inode, struct file *filp, ...@@ -456,6 +461,8 @@ spidev_ioctl(struct inode *inode, struct file *filp,
kfree(ioc); kfree(ioc);
break; break;
} }
mutex_unlock(&spidev->buf_lock);
spi_dev_put(spi); spi_dev_put(spi);
return retval; return retval;
} }
...@@ -533,7 +540,7 @@ static struct file_operations spidev_fops = { ...@@ -533,7 +540,7 @@ static struct file_operations spidev_fops = {
*/ */
.write = spidev_write, .write = spidev_write,
.read = spidev_read, .read = spidev_read,
.ioctl = spidev_ioctl, .unlocked_ioctl = spidev_ioctl,
.open = spidev_open, .open = spidev_open,
.release = spidev_release, .release = spidev_release,
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment