Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 105441
b: refs/heads/master
c: 4ef754b
h: refs/heads/master
i:
  105439: ddfdb8e
v: v3
  • Loading branch information
Alan Cox authored and Linus Torvalds committed Jul 24, 2008
1 parent 76d2403 commit 7f97ed3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 102eb97564c73ea73645b38599c5cbe6f54b030c
refs/heads/master: 4ef754b7d7971a704d5b1b4608839da1bae37e5e
19 changes: 13 additions & 6 deletions trunk/drivers/spi/spidev.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ static int spidev_message(struct spidev_data *spidev,
* We walk the array of user-provided transfers, using each one
* to initialize a kernel version of the same transfer.
*/
mutex_lock(&spidev->buf_lock);
buf = spidev->buffer;
total = 0;
for (n = n_xfers, k_tmp = k_xfers, u_tmp = u_xfers;
Expand Down Expand Up @@ -296,14 +295,12 @@ static int spidev_message(struct spidev_data *spidev,
status = total;

done:
mutex_unlock(&spidev->buf_lock);
kfree(k_xfers);
return status;
}

static int
spidev_ioctl(struct inode *inode, struct file *filp,
unsigned int cmd, unsigned long arg)
static long
spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{
int err = 0;
int retval = 0;
Expand Down Expand Up @@ -341,6 +338,14 @@ spidev_ioctl(struct inode *inode, struct file *filp,
if (spi == NULL)
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) {
/* read requests */
case SPI_IOC_RD_MODE:
Expand Down Expand Up @@ -456,6 +461,8 @@ spidev_ioctl(struct inode *inode, struct file *filp,
kfree(ioc);
break;
}

mutex_unlock(&spidev->buf_lock);
spi_dev_put(spi);
return retval;
}
Expand Down Expand Up @@ -533,7 +540,7 @@ static struct file_operations spidev_fops = {
*/
.write = spidev_write,
.read = spidev_read,
.ioctl = spidev_ioctl,
.unlocked_ioctl = spidev_ioctl,
.open = spidev_open,
.release = spidev_release,
};
Expand Down

0 comments on commit 7f97ed3

Please sign in to comment.