All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] spi: fix the read path in spidev
@ 2008-07-01 15:45 Sebastian Siewior
       [not found] ` <20080701154504.GA26219-Hfxr4Dq0UpYb1SvskN2V4Q@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Sebastian Siewior @ 2008-07-01 15:45 UTC (permalink / raw)
  To: David Brownell
  Cc: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, Andrew Morton

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.

Signed-off-by: Sebastian Siewior <bigeasy-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
Cc:  David Brownell <dbrownell-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
---
 drivers/spi/spidev.c |   10 ++++------
 1 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c
index 72282cd..60ec6f7 100644
--- a/drivers/spi/spidev.c
+++ b/drivers/spi/spidev.c
@@ -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 (status && 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);
-- 
1.5.5.2


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-07-02  7:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-01 15:45 [PATCH] spi: fix the read path in spidev Sebastian Siewior
     [not found] ` <20080701154504.GA26219-Hfxr4Dq0UpYb1SvskN2V4Q@public.gmane.org>
2008-07-01 20:07   ` Andrew Morton
2008-07-02  2:59   ` David Brownell
     [not found]     ` <200807011959.50695.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
2008-07-02  7:02       ` Sebastian Siewior

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.