VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[linux-2.6.git] / drivers / char / epca.c
index 8b838c1..854d16a 100644 (file)
@@ -48,8 +48,8 @@
 #define ENABLE_PCI
 #endif /* CONFIG_PCI */
 
-#define putUser(arg1, arg2) put_user(arg1, (unsigned long *)arg2)
-#define getUser(arg1, arg2) get_user(arg1, (unsigned int *)arg2)
+#define putUser(arg1, arg2) put_user(arg1, (unsigned long __user *)arg2)
+#define getUser(arg1, arg2) get_user(arg1, (unsigned __user *)arg2)
 
 #ifdef ENABLE_PCI
 #include <linux/pci.h>
@@ -218,7 +218,7 @@ static void setup_empty_event(struct tty_struct *tty, struct channel *ch);
 void epca_setup(char *, int *);
 void console_print(const char *);
 
-static int get_termio(struct tty_struct *, struct termio *);
+static int get_termio(struct tty_struct *, struct termio __user *);
 static int pc_write(struct tty_struct *, int, const unsigned char *, int);
 int pc_init(void);
 
@@ -835,38 +835,29 @@ static int pc_write(struct tty_struct * tty, int from_user,
 
                if (bytesAvailable) 
                { /* Begin bytesAvailable */
+                       /* ---------------------------------------------------------------
+                               The below function reads data from user memory.  This routine
+                               can not be used in an interrupt routine. (Because it may 
+                               generate a page fault)  It can only be called while we can the
+                               user context is accessible. 
+
+                               The prototype is :
+                               inline void copy_from_user(void * to, const void * from,
+                                                         unsigned long count);
+
+                               I also think (Check hackers guide) that optimization must
+                               be turned ON.  (Which sounds strange to me...)
+
+                               Remember copy_from_user WILL generate a page fault if the
+                               user memory being accessed has been swapped out.  This can
+                               cause this routine to temporarily sleep while this page
+                               fault is occurring.
+                       
+                       ----------------------------------------------------------------- */
 
-                       /* Can the user buffer be accessed at the moment ? */
-                       if (verify_area(VERIFY_READ, (char*)buf, bytesAvailable))
-                               bytesAvailable = 0; /* Can't do; try again later */
-                       else  /* Evidently it can, began transmission */
-                       { /* Begin if area verified */
-                               /* ---------------------------------------------------------------
-                                       The below function reads data from user memory.  This routine
-                                       can not be used in an interrupt routine. (Because it may 
-                                       generate a page fault)  It can only be called while we can the
-                                       user context is accessible. 
-
-                                       The prototype is :
-                                       inline void copy_from_user(void * to, const void * from,
-                                                                 unsigned long count);
-
-                                       I also think (Check hackers guide) that optimization must
-                                       be turned ON.  (Which sounds strange to me...)
-       
-                                       Remember copy_from_user WILL generate a page fault if the
-                                       user memory being accessed has been swapped out.  This can
-                                       cause this routine to temporarily sleep while this page
-                                       fault is occurring.
-                               
-                               ----------------------------------------------------------------- */
-
-                               if (copy_from_user(ch->tmp_buf, buf,
-                                                  bytesAvailable))
-                                       return -EFAULT;
-
-                       } /* End if area verified */
-
+                       if (copy_from_user(ch->tmp_buf, buf,
+                                          bytesAvailable))
+                               return -EFAULT;
                } /* End bytesAvailable */
 
                /* ------------------------------------------------------------------ 
@@ -1984,7 +1975,7 @@ static void post_fep_init(unsigned int crd)
                ch->boardnum   = crd;
                ch->channelnum = i;
                ch->magic      = EPCA_MAGIC;
-               ch->tty        = 0;
+               ch->tty        = NULL;
 
                if (shrinkmem) 
                {
@@ -2728,7 +2719,7 @@ static void receive_data(struct channel *ch)
 { /* Begin receive_data */
 
        unchar *rptr;
-       struct termios *ts = 0;
+       struct termios *ts = NULL;
        struct tty_struct *tty;
        volatile struct board_chan *bc;
        register int dataToRead, wrapgap, bytesAvailable;
@@ -2851,8 +2842,6 @@ static void receive_data(struct channel *ch)
 static int info_ioctl(struct tty_struct *tty, struct file * file,
                    unsigned int cmd, unsigned long arg)
 {
-       int error;
-       
        switch (cmd) 
        { /* Begin switch cmd */
 
@@ -2862,13 +2851,7 @@ static int info_ioctl(struct tty_struct *tty, struct file * file,
                        struct digi_info di ;
                        int brd;
 
-                       getUser(brd, (unsigned int *)arg);
-
-                       if ((error = verify_area(VERIFY_WRITE, (char*)arg, sizeof(di))))
-                       {
-                               printk(KERN_ERR "DIGI_GETINFO : verify area size 0x%x failed\n",sizeof(di));
-                               return(error);
-                       }
+                       getUser(brd, (unsigned int __user *)arg);
 
                        if ((brd < 0) || (brd >= num_cards) || (num_cards == 0))
                                return (-ENODEV);
@@ -2882,7 +2865,7 @@ static int info_ioctl(struct tty_struct *tty, struct file * file,
                        di.port = boards[brd].port ;
                        di.membase = boards[brd].membase ;
 
-                       if (copy_to_user((char *)arg, &di, sizeof (di)))
+                       if (copy_to_user((void __user *)arg, &di, sizeof (di)))
                                return -EFAULT;
                        break;
 
@@ -3020,6 +3003,7 @@ static int pc_tiocmset(struct tty_struct *tty, struct file *file,
        epcaparam(tty,ch);
        memoff(ch);
        restore_flags(flags);
+       return 0;
 }
 
 static int pc_ioctl(struct tty_struct *tty, struct file * file,
@@ -3027,12 +3011,13 @@ static int pc_ioctl(struct tty_struct *tty, struct file * file,
 { /* Begin pc_ioctl */
 
        digiflow_t dflow;
-       int retval, error;
+       int retval;
        unsigned long flags;
        unsigned int mflag, mstat;
        unsigned char startc, stopc;
        volatile struct board_chan *bc;
        struct channel *ch = (struct channel *) tty->driver_data;
+       void __user *argp = (void __user *)arg;
        
        if (ch)
                bc = ch->brdchan;
@@ -3054,13 +3039,13 @@ static int pc_ioctl(struct tty_struct *tty, struct file * file,
        { /* Begin switch cmd */
 
                case TCGETS:
-                       if (copy_to_user((struct termios *)arg
+                       if (copy_to_user(argp
                                         tty->termios, sizeof(struct termios)))
                                return -EFAULT;
                        return(0);
 
                case TCGETA:
-                       return get_termio(tty, (struct termio *)arg);
+                       return get_termio(tty, argp);
 
                case TCSBRK:    /* SVID version: non-zero arg --> no break */
 
@@ -3090,21 +3075,16 @@ static int pc_ioctl(struct tty_struct *tty, struct file * file,
                        return 0;
 
                case TIOCGSOFTCAR:
-
-                       error = verify_area(VERIFY_WRITE, (void *) arg,sizeof(long));
-                       if (error)
-                               return error;
-
-                       putUser(C_CLOCAL(tty) ? 1 : 0,
-                                   (unsigned long *) arg);
+                       if (put_user(C_CLOCAL(tty)?1:0, (unsigned long __user *)arg))
+                               return -EFAULT;
                        return 0;
 
                case TIOCSSOFTCAR:
-                       /*RONNIE PUT VERIFY_READ (See above) check here */
                {
                        unsigned int value;
 
-                       getUser(value, (unsigned int *)arg);
+                       if (get_user(value, (unsigned __user *)argp))
+                               return -EFAULT;
                        tty->termios->c_cflag =
                                ((tty->termios->c_cflag & ~CLOCAL) |
                                 (value ? CLOCAL : 0));
@@ -3113,12 +3093,12 @@ static int pc_ioctl(struct tty_struct *tty, struct file * file,
 
                case TIOCMODG:
                        mflag = pc_tiocmget(tty, file);
-                       if (putUser(mflag, (unsigned int *) arg))
+                       if (put_user(mflag, (unsigned long __user *)argp))
                                return -EFAULT;
                        break;
 
                case TIOCMODS:
-                       if (getUser(mstat, (unsigned int *)arg))
+                       if (get_user(mstat, (unsigned __user *)argp))
                                return -EFAULT;
                        return pc_tiocmset(tty, file, mstat, ~mstat);
 
@@ -3141,8 +3121,7 @@ static int pc_ioctl(struct tty_struct *tty, struct file * file,
                        break;
 
                case DIGI_GETA:
-                       if (copy_to_user((char*)arg, &ch->digiext,
-                                        sizeof(digi_t)))
+                       if (copy_to_user(argp, &ch->digiext, sizeof(digi_t)))
                                return -EFAULT;
                        break;
 
@@ -3164,8 +3143,7 @@ static int pc_ioctl(struct tty_struct *tty, struct file * file,
                        /* Fall Thru */
 
                case DIGI_SETA:
-                       if (copy_from_user(&ch->digiext, (char*)arg,
-                                          sizeof(digi_t)))
+                       if (copy_from_user(&ch->digiext, argp, sizeof(digi_t)))
                                return -EFAULT;
                        
                        if (ch->digiext.digi_flags & DIGI_ALTPIN) 
@@ -3209,7 +3187,7 @@ static int pc_ioctl(struct tty_struct *tty, struct file * file,
                        memoff(ch);
                        restore_flags(flags);
 
-                       if (copy_to_user((char*)arg, &dflow, sizeof(dflow)))
+                       if (copy_to_user(argp, &dflow, sizeof(dflow)))
                                return -EFAULT;
                        break;
 
@@ -3226,7 +3204,7 @@ static int pc_ioctl(struct tty_struct *tty, struct file * file,
                                stopc = ch->stopca;
                        }
 
-                       if (copy_from_user(&dflow, (char*)arg, sizeof(dflow)))
+                       if (copy_from_user(&dflow, argp, sizeof(dflow)))
                                return -EFAULT;
 
                        if (dflow.startc != startc || dflow.stopc != stopc) 
@@ -3555,17 +3533,9 @@ static void setup_empty_event(struct tty_struct *tty, struct channel *ch)
 
 /* --------------------- Begin get_termio ----------------------- */
 
-static int get_termio(struct tty_struct * tty, struct termio * termio)
+static int get_termio(struct tty_struct * tty, struct termio __user * termio)
 { /* Begin get_termio */
-       int error;
-
-       error = verify_area(VERIFY_WRITE, termio, sizeof (struct termio));
-       if (error)
-               return error;
-
-       kernel_termios_to_user_termio(termio, tty->termios);
-
-       return 0;
+       return kernel_termios_to_user_termio(termio, tty->termios);
 } /* End get_termio */
 /* ---------------------- Begin epca_setup  -------------------------- */
 void epca_setup(char *str, int *ints)