char: xillybus: Don't return -EFAULT on user-triggered flush
authorEli Billauer <eli.billauer@gmail.com>
Fri, 27 Mar 2015 08:56:06 +0000 (11:56 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 3 Apr 2015 14:15:30 +0000 (16:15 +0200)
The API allows the application to flush a host-to-FPGA stream by calling
write() with the data count set to zero. Before this patch, copy_from_user()
was called with a non-zero byte count, which possibly made it attempt to read
from unmapped user memory. Such attempts caused the driver to return -EFAULT
instead of 0, even though the desired operation went through fine.

This patch ensures the driver returns 0 on a successful flush.

Signed-off-by: Eli Billauer <eli.billauer@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/char/xillybus/xillybus_core.c

index b827fa095f1b324231e3916bc2e22f2315ec8bbf..77d6c127e691a4a8a6417bd4cd0760fed0d513e8 100644 (file)
@@ -1237,6 +1237,8 @@ static ssize_t xillybus_write(struct file *filp, const char __user *userbuf,
                                        unsigned char *tail;
                                        int i;
 
+                                       howmany = 0;
+
                                        end_offset_plus1 = bufpos >>
                                                channel->log2_element_size;