]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/char/n_tty.c
firewire: cdev: simplify a schedule_delayed_work wrapper
[karo-tx-linux.git] / drivers / char / n_tty.c
index a223823544bfe33c2f325cb7b8d0fbb3629626fa..f6f0e4ec2b510dde6ca5079f6def074e34f6fdce 100644 (file)
@@ -351,10 +351,12 @@ static int do_output_char(unsigned char c, struct tty_struct *tty, int space)
                        tty->column--;
                break;
        default:
-               if (O_OLCUC(tty))
-                       c = toupper(c);
-               if (!iscntrl(c) && !is_continuation(c, tty))
-                       tty->column++;
+               if (!iscntrl(c)) {
+                       if (O_OLCUC(tty))
+                               c = toupper(c);
+                       if (!is_continuation(c, tty))
+                               tty->column++;
+               }
                break;
        }
 
@@ -425,7 +427,9 @@ static ssize_t process_output_block(struct tty_struct *tty,
                nr = space;
 
        for (i = 0, cp = buf; i < nr; i++, cp++) {
-               switch (*cp) {
+               unsigned char c = *cp;
+
+               switch (c) {
                case '\n':
                        if (O_ONLRET(tty))
                                tty->column = 0;
@@ -447,10 +451,12 @@ static ssize_t process_output_block(struct tty_struct *tty,
                                tty->column--;
                        break;
                default:
-                       if (O_OLCUC(tty))
-                               goto break_out;
-                       if (!iscntrl(*cp))
-                               tty->column++;
+                       if (!iscntrl(c)) {
+                               if (O_OLCUC(tty))
+                                       goto break_out;
+                               if (!is_continuation(c, tty))
+                                       tty->column++;
+                       }
                        break;
                }
        }
@@ -866,7 +872,7 @@ static void eraser(unsigned char c, struct tty_struct *tty)
 
        /* FIXME: locking needed ? */
        if (tty->read_head == tty->canon_head) {
-               /* echo_char_raw('\a', tty); */ /* what do you think? */
+               /* process_output('\a', tty); */ /* what do you think? */
                return;
        }
        if (c == ERASE_CHAR(tty))
@@ -1101,6 +1107,7 @@ static inline void n_tty_receive_parity_error(struct tty_struct *tty,
 static inline void n_tty_receive_char(struct tty_struct *tty, unsigned char c)
 {
        unsigned long flags;
+       int parmrk;
 
        if (tty->raw) {
                put_tty_queue(c, tty);
@@ -1138,21 +1145,22 @@ static inline void n_tty_receive_char(struct tty_struct *tty, unsigned char c)
         */
        if (!test_bit(c, tty->process_char_map) || tty->lnext) {
                tty->lnext = 0;
+               parmrk = (c == (unsigned char) '\377' && I_PARMRK(tty)) ? 1 : 0;
+               if (tty->read_cnt >= (N_TTY_BUF_SIZE - parmrk - 1)) {
+                       /* beep if no space */
+                       if (L_ECHO(tty))
+                               process_output('\a', tty);
+                       return;
+               }
                if (L_ECHO(tty)) {
                        finish_erasing(tty);
-                       if (tty->read_cnt >= N_TTY_BUF_SIZE-1) {
-                               /* beep if no space */
-                               echo_char_raw('\a', tty);
-                               process_echoes(tty);
-                               return;
-                       }
                        /* Record the column of first canon char. */
                        if (tty->canon_head == tty->read_head)
                                echo_set_canon_col(tty);
                        echo_char(c, tty);
                        process_echoes(tty);
                }
-               if (I_PARMRK(tty) && c == (unsigned char) '\377')
+               if (parmrk)
                        put_tty_queue(c, tty);
                put_tty_queue(c, tty);
                return;
@@ -1244,15 +1252,20 @@ send_signal:
                        return;
                }
                if (c == '\n') {
+                       if (tty->read_cnt >= N_TTY_BUF_SIZE) {
+                               if (L_ECHO(tty))
+                                       process_output('\a', tty);
+                               return;
+                       }
                        if (L_ECHO(tty) || L_ECHONL(tty)) {
-                               if (tty->read_cnt >= N_TTY_BUF_SIZE-1)
-                                       echo_char_raw('\a', tty);
                                echo_char_raw('\n', tty);
                                process_echoes(tty);
                        }
                        goto handle_newline;
                }
                if (c == EOF_CHAR(tty)) {
+                       if (tty->read_cnt >= N_TTY_BUF_SIZE)
+                               return;
                        if (tty->canon_head != tty->read_head)
                                set_bit(TTY_PUSH, &tty->flags);
                        c = __DISABLED_CHAR;
@@ -1260,12 +1273,17 @@ send_signal:
                }
                if ((c == EOL_CHAR(tty)) ||
                    (c == EOL2_CHAR(tty) && L_IEXTEN(tty))) {
+                       parmrk = (c == (unsigned char) '\377' && I_PARMRK(tty))
+                                ? 1 : 0;
+                       if (tty->read_cnt >= (N_TTY_BUF_SIZE - parmrk)) {
+                               if (L_ECHO(tty))
+                                       process_output('\a', tty);
+                               return;
+                       }
                        /*
                         * XXX are EOL_CHAR and EOL2_CHAR echoed?!?
                         */
                        if (L_ECHO(tty)) {
-                               if (tty->read_cnt >= N_TTY_BUF_SIZE-1)
-                                       echo_char_raw('\a', tty);
                                /* Record the column of first canon char. */
                                if (tty->canon_head == tty->read_head)
                                        echo_set_canon_col(tty);
@@ -1276,7 +1294,7 @@ send_signal:
                         * XXX does PARMRK doubling happen for
                         * EOL_CHAR and EOL2_CHAR?
                         */
-                       if (I_PARMRK(tty) && c == (unsigned char) '\377')
+                       if (parmrk)
                                put_tty_queue(c, tty);
 
 handle_newline:
@@ -1293,14 +1311,15 @@ handle_newline:
                }
        }
 
+       parmrk = (c == (unsigned char) '\377' && I_PARMRK(tty)) ? 1 : 0;
+       if (tty->read_cnt >= (N_TTY_BUF_SIZE - parmrk - 1)) {
+               /* beep if no space */
+               if (L_ECHO(tty))
+                       process_output('\a', tty);
+               return;
+       }
        if (L_ECHO(tty)) {
                finish_erasing(tty);
-               if (tty->read_cnt >= N_TTY_BUF_SIZE-1) {
-                       /* beep if no space */
-                       echo_char_raw('\a', tty);
-                       process_echoes(tty);
-                       return;
-               }
                if (c == '\n')
                        echo_char_raw('\n', tty);
                else {
@@ -1312,7 +1331,7 @@ handle_newline:
                process_echoes(tty);
        }
 
-       if (I_PARMRK(tty) && c == (unsigned char) '\377')
+       if (parmrk)
                put_tty_queue(c, tty);
 
        put_tty_queue(c, tty);
@@ -1333,10 +1352,8 @@ static void n_tty_write_wakeup(struct tty_struct *tty)
        /* Write out any echoed characters that are still pending */
        process_echoes(tty);
 
-       if (tty->fasync) {
-               set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
+       if (tty->fasync && test_and_clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags))
                kill_fasync(&tty->fasync, SIGIO, POLL_OUT);
-       }
 }
 
 /**
@@ -1995,6 +2012,8 @@ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file,
 break_out:
        __set_current_state(TASK_RUNNING);
        remove_wait_queue(&tty->write_wait, &wait);
+       if (b - buf != nr && tty->fasync)
+               set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
        return (b - buf) ? b - buf : retval;
 }