tty: BKL pushdown
[pandora-kernel.git] / drivers / char / n_hdlc.c
index 337a87f..a07c0af 100644 (file)
@@ -229,7 +229,7 @@ static void n_hdlc_release(struct n_hdlc *n_hdlc)
        wake_up_interruptible (&tty->read_wait);
        wake_up_interruptible (&tty->write_wait);
 
-       if (tty != NULL && tty->disc_data == n_hdlc)
+       if (tty->disc_data == n_hdlc)
                tty->disc_data = NULL;  /* Break the tty->n_hdlc link */
 
        /* Release transmit and receive buffers */
@@ -400,7 +400,12 @@ static void n_hdlc_send_frames(struct n_hdlc *n_hdlc, struct tty_struct *tty)
                /* Send the next block of data to device */
                tty->flags |= (1 << TTY_DO_WRITE_WAKEUP);
                actual = tty->driver->write(tty, tbuf->buf, tbuf->count);
-                   
+
+               /* rollback was possible and has been done */
+               if (actual == -ERESTARTSYS) {
+                       n_hdlc->tbuf = tbuf;
+                       break;
+               }
                /* if transmit error, throw frame away by */
                /* pretending it was accepted by driver */
                if (actual < 0)
@@ -496,7 +501,7 @@ static void n_hdlc_tty_receive(struct tty_struct *tty, const __u8 *data,
                        __FILE__,__LINE__, count);
                
        /* This can happen if stuff comes in on the backup tty */
-       if (n_hdlc == 0 || tty != n_hdlc->tty)
+       if (!n_hdlc || tty != n_hdlc->tty)
                return;
                
        /* verify line is using HDLC discipline */
@@ -573,26 +578,36 @@ static ssize_t n_hdlc_tty_read(struct tty_struct *tty, struct file *file,
                return -EFAULT;
        }
 
+       lock_kernel();
+
        for (;;) {
-               if (test_bit(TTY_OTHER_CLOSED, &tty->flags))
+               if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) {
+                       unlock_kernel();
                        return -EIO;
+               }
 
                n_hdlc = tty2n_hdlc (tty);
                if (!n_hdlc || n_hdlc->magic != HDLC_MAGIC ||
-                        tty != n_hdlc->tty)
+                        tty != n_hdlc->tty) {
+                       unlock_kernel();
                        return 0;
+               }
 
                rbuf = n_hdlc_buf_get(&n_hdlc->rx_buf_list);
                if (rbuf)
                        break;
                        
                /* no data */
-               if (file->f_flags & O_NONBLOCK)
+               if (file->f_flags & O_NONBLOCK) {
+                       unlock_kernel();
                        return -EAGAIN;
+               }
                        
                interruptible_sleep_on (&tty->read_wait);
-               if (signal_pending(current))
+               if (signal_pending(current)) {
+                       unlock_kernel();
                        return -EINTR;
+               }
        }
                
        if (rbuf->count > nr)
@@ -613,7 +628,7 @@ static ssize_t n_hdlc_tty_read(struct tty_struct *tty, struct file *file,
                kfree(rbuf);
        else    
                n_hdlc_buf_put(&n_hdlc->rx_free_buf_list,rbuf);
-       
+       unlock_kernel();
        return ret;
        
 }      /* end of n_hdlc_tty_read() */
@@ -656,6 +671,8 @@ static ssize_t n_hdlc_tty_write(struct tty_struct *tty, struct file *file,
                count = maxframe;
        }
        
+       lock_kernel();
+
        add_wait_queue(&tty->write_wait, &wait);
        set_current_state(TASK_INTERRUPTIBLE);
        
@@ -690,7 +707,7 @@ static ssize_t n_hdlc_tty_write(struct tty_struct *tty, struct file *file,
                n_hdlc_buf_put(&n_hdlc->tx_buf_list,tbuf);
                n_hdlc_send_frames(n_hdlc,tty);
        }
-
+       unlock_kernel();
        return error;
        
 }      /* end of n_hdlc_tty_write() */
@@ -780,13 +797,14 @@ static unsigned int n_hdlc_tty_poll(struct tty_struct *tty, struct file *filp,
                poll_wait(filp, &tty->write_wait, wait);
 
                /* set bits for operations that won't block */
-               if(n_hdlc->rx_buf_list.head)
+               if (n_hdlc->rx_buf_list.head)
                        mask |= POLLIN | POLLRDNORM;    /* readable */
                if (test_bit(TTY_OTHER_CLOSED, &tty->flags))
                        mask |= POLLHUP;
-               if(tty_hung_up_p(filp))
+               if (tty_hung_up_p(filp))
                        mask |= POLLHUP;
-               if(n_hdlc->tx_free_buf_list.head)
+               if (!tty_is_writelocked(tty) &&
+                               n_hdlc->tx_free_buf_list.head)
                        mask |= POLLOUT | POLLWRNORM;   /* writable */
        }
        return mask;
@@ -861,7 +879,7 @@ static void n_hdlc_buf_put(struct n_hdlc_buf_list *list,
        spin_lock_irqsave(&list->spinlock,flags);
        
        buf->link=NULL;
-       if(list->tail)
+       if (list->tail)
                list->tail->link = buf;
        else
                list->head = buf;