]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
spi: fix the read path in spidev
authorSebastian Siewior <bigeasy@linutronix.de>
Fri, 4 Jul 2008 16:59:56 +0000 (09:59 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 4 Jul 2008 17:40:08 +0000 (10:40 -0700)
This got broken by the recent "fix rmmod $spi_driver while spidev-user is
active".  I tested the rmmod & write path but didn't check the read path.
I am sorry.  The read logic changed and spidev_sync_read() +
spidev_sync_write() do not return zero on success anymore but the number
of bytes that has been transfered over the bus.  This patch changes the
logic and copy_to_user() gets called again.

The write path returns the number of bytes which are written to the
underlying device what may be less than the requested size.  This patch
makes the same change to the read path or else we request a read of 20
bytes, get 10, don't call copy to user and report to the user that we read
10 bytes.

[akpm@linux-foundation.org: remove test of known-to-be-zero local]
Signed-off-by: Sebastian Siewior <bigeasy@linutronix.de>
Acked-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
drivers/spi/spidev.c

index 799337f7fde1b5a5971ff11c6378121e20cc5451..f5b60c70389b771bc752be6178ed38cfed2730f9 100644 (file)
@@ -167,14 +167,14 @@ spidev_read(struct file *filp, char __user *buf, size_t count, loff_t *f_pos)
 
        mutex_lock(&spidev->buf_lock);
        status = spidev_sync_read(spidev, count);
-       if (status == 0) {
+       if (status > 0) {
                unsigned long   missing;
 
-               missing = copy_to_user(buf, spidev->buffer, count);
-               if (count && missing == count)
+               missing = copy_to_user(buf, spidev->buffer, status);
+               if (missing == status)
                        status = -EFAULT;
                else
-                       status = count - missing;
+                       status = status - missing;
        }
        mutex_unlock(&spidev->buf_lock);
 
@@ -200,8 +200,6 @@ spidev_write(struct file *filp, const char __user *buf,
        missing = copy_from_user(spidev->buffer, buf, count);
        if (missing == 0) {
                status = spidev_sync_write(spidev, count);
-               if (status == 0)
-                       status = count;
        } else
                status = -EFAULT;
        mutex_unlock(&spidev->buf_lock);