diff options
Diffstat (limited to 'drivers/spi')
-rw-r--r-- | drivers/spi/spidev.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c index 799337f7fde1..ddbe1a5e970e 100644 --- a/drivers/spi/spidev.c +++ b/drivers/spi/spidev.c | |||
@@ -30,6 +30,7 @@ | |||
30 | #include <linux/errno.h> | 30 | #include <linux/errno.h> |
31 | #include <linux/mutex.h> | 31 | #include <linux/mutex.h> |
32 | #include <linux/slab.h> | 32 | #include <linux/slab.h> |
33 | #include <linux/smp_lock.h> | ||
33 | 34 | ||
34 | #include <linux/spi/spi.h> | 35 | #include <linux/spi/spi.h> |
35 | #include <linux/spi/spidev.h> | 36 | #include <linux/spi/spidev.h> |
@@ -167,14 +168,14 @@ spidev_read(struct file *filp, char __user *buf, size_t count, loff_t *f_pos) | |||
167 | 168 | ||
168 | mutex_lock(&spidev->buf_lock); | 169 | mutex_lock(&spidev->buf_lock); |
169 | status = spidev_sync_read(spidev, count); | 170 | status = spidev_sync_read(spidev, count); |
170 | if (status == 0) { | 171 | if (status > 0) { |
171 | unsigned long missing; | 172 | unsigned long missing; |
172 | 173 | ||
173 | missing = copy_to_user(buf, spidev->buffer, count); | 174 | missing = copy_to_user(buf, spidev->buffer, status); |
174 | if (count && missing == count) | 175 | if (missing == status) |
175 | status = -EFAULT; | 176 | status = -EFAULT; |
176 | else | 177 | else |
177 | status = count - missing; | 178 | status = status - missing; |
178 | } | 179 | } |
179 | mutex_unlock(&spidev->buf_lock); | 180 | mutex_unlock(&spidev->buf_lock); |
180 | 181 | ||
@@ -200,8 +201,6 @@ spidev_write(struct file *filp, const char __user *buf, | |||
200 | missing = copy_from_user(spidev->buffer, buf, count); | 201 | missing = copy_from_user(spidev->buffer, buf, count); |
201 | if (missing == 0) { | 202 | if (missing == 0) { |
202 | status = spidev_sync_write(spidev, count); | 203 | status = spidev_sync_write(spidev, count); |
203 | if (status == 0) | ||
204 | status = count; | ||
205 | } else | 204 | } else |
206 | status = -EFAULT; | 205 | status = -EFAULT; |
207 | mutex_unlock(&spidev->buf_lock); | 206 | mutex_unlock(&spidev->buf_lock); |
@@ -466,6 +465,7 @@ static int spidev_open(struct inode *inode, struct file *filp) | |||
466 | struct spidev_data *spidev; | 465 | struct spidev_data *spidev; |
467 | int status = -ENXIO; | 466 | int status = -ENXIO; |
468 | 467 | ||
468 | lock_kernel(); | ||
469 | mutex_lock(&device_list_lock); | 469 | mutex_lock(&device_list_lock); |
470 | 470 | ||
471 | list_for_each_entry(spidev, &device_list, device_entry) { | 471 | list_for_each_entry(spidev, &device_list, device_entry) { |
@@ -491,6 +491,7 @@ static int spidev_open(struct inode *inode, struct file *filp) | |||
491 | pr_debug("spidev: nothing for minor %d\n", iminor(inode)); | 491 | pr_debug("spidev: nothing for minor %d\n", iminor(inode)); |
492 | 492 | ||
493 | mutex_unlock(&device_list_lock); | 493 | mutex_unlock(&device_list_lock); |
494 | unlock_kernel(); | ||
494 | return status; | 495 | return status; |
495 | } | 496 | } |
496 | 497 | ||