Hi Linus,

Here is a patch that fixes some missing copy_to/from_user things, as
well as fixing the pp_write logic.

Tim.
*/

Index: linux/drivers/char/ppdev.c
diff -u linux/drivers/char/ppdev.c:1.1.1.23 linux/drivers/char/ppdev.c:1.29
--- linux/drivers/char/ppdev.c:1.1.1.23 Fri Jul 14 11:05:38 2000
+++ linux/drivers/char/ppdev.c  Wed Aug 30 12:09:00 2000
@@ -39,7 +39,13 @@
  * read/write  read or write in current IEEE 1284 protocol
  * select      wait for interrupt (in readfds)
  *
+ * Changes:
  * Added SETTIME/GETTIME ioctl, Fred Barnes 1999.
+ *
+ * Arnaldo Carvalho de Melo <[EMAIL PROTECTED]> 2000/08/25
+ * - On error, copy_from_user and copy_to_user do not return -EFAULT,
+ *   They return the positive number of bytes *not* copied due to address
+ *   space errors.
  */
 
 #include <linux/module.h>
@@ -179,7 +185,7 @@
 
                wrote = parport_write (pp->pdev->port, kbuffer, n);
 
-               if (wrote < 0) {
+               if (wrote <= 0) {
                        if (!bytes_written)
                                bytes_written = wrote;
                        break;
@@ -369,19 +375,19 @@
 
        case PPRSTATUS:
                reg = parport_read_status (port);
-               return copy_to_user ((unsigned char *) arg, &reg,
-                                    sizeof (reg));
-
+               if (copy_to_user ((unsigned char *) arg, &reg, sizeof (reg)))
+                       return -EFAULT;
+               return 0;
        case PPRDATA:
                reg = parport_read_data (port);
-               return copy_to_user ((unsigned char *) arg, &reg,
-                                    sizeof (reg));
-
+               if (copy_to_user ((unsigned char *) arg, &reg, sizeof (reg)))
+                       return -EFAULT;
+               return 0;
        case PPRCONTROL:
                reg = parport_read_control (port);
-               return copy_to_user ((unsigned char *) arg, &reg,
-                                    sizeof (reg));
-
+               if (copy_to_user ((unsigned char *) arg, &reg, sizeof (reg)))
+                       return -EFAULT;
+               return 0;
        case PPYIELD:
                parport_yield_blocking (pp->pdev);
                return 0;
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
Please read the FAQ at http://www.tux.org/lkml/

Reply via email to