Merge branches 'slab/cleanups', 'slab/failslab', 'slab/fixes' and 'slub/percpu' into...
[deliverable/linux.git] / drivers / char / tty_buffer.c
index 3108991c5c8b60f312742ca4eaeb37e4c812ad4c..af8d97715728b4829ec152dcd22b5fa4516e9bbc 100644 (file)
@@ -231,9 +231,10 @@ int tty_buffer_request_room(struct tty_struct *tty, size_t size)
 EXPORT_SYMBOL_GPL(tty_buffer_request_room);
 
 /**
- *     tty_insert_flip_string  -       Add characters to the tty buffer
+ *     tty_insert_flip_string_fixed_flag - Add characters to the tty buffer
  *     @tty: tty structure
  *     @chars: characters
+ *     @flag: flag value for each character
  *     @size: size
  *
  *     Queue a series of bytes to the tty buffering. All the characters
@@ -242,18 +243,19 @@ EXPORT_SYMBOL_GPL(tty_buffer_request_room);
  *     Locking: Called functions may take tty->buf.lock
  */
 
-int tty_insert_flip_string(struct tty_struct *tty, const unsigned char *chars,
-                               size_t size)
+int tty_insert_flip_string_fixed_flag(struct tty_struct *tty,
+               const unsigned char *chars, char flag, size_t size)
 {
        int copied = 0;
        do {
-               int space = tty_buffer_request_room(tty, size - copied);
+               int goal = min(size - copied, TTY_BUFFER_PAGE);
+               int space = tty_buffer_request_room(tty, goal);
                struct tty_buffer *tb = tty->buf.tail;
                /* If there is no space then tb may be NULL */
                if (unlikely(space == 0))
                        break;
                memcpy(tb->char_buf_ptr + tb->used, chars, space);
-               memset(tb->flag_buf_ptr + tb->used, TTY_NORMAL, space);
+               memset(tb->flag_buf_ptr + tb->used, flag, space);
                tb->used += space;
                copied += space;
                chars += space;
@@ -262,7 +264,7 @@ int tty_insert_flip_string(struct tty_struct *tty, const unsigned char *chars,
        } while (unlikely(size > copied));
        return copied;
 }
-EXPORT_SYMBOL(tty_insert_flip_string);
+EXPORT_SYMBOL(tty_insert_flip_string_fixed_flag);
 
 /**
  *     tty_insert_flip_string_flags    -       Add characters to the tty buffer
@@ -283,7 +285,8 @@ int tty_insert_flip_string_flags(struct tty_struct *tty,
 {
        int copied = 0;
        do {
-               int space = tty_buffer_request_room(tty, size - copied);
+               int goal = min(size - copied, TTY_BUFFER_PAGE);
+               int space = tty_buffer_request_room(tty, goal);
                struct tty_buffer *tb = tty->buf.tail;
                /* If there is no space then tb may be NULL */
                if (unlikely(space == 0))
@@ -402,28 +405,26 @@ static void flush_to_ldisc(struct work_struct *work)
                container_of(work, struct tty_struct, buf.work.work);
        unsigned long   flags;
        struct tty_ldisc *disc;
-       struct tty_buffer *tbuf, *head;
-       char *char_buf;
-       unsigned char *flag_buf;
 
        disc = tty_ldisc_ref(tty);
        if (disc == NULL)       /*  !TTY_LDISC */
                return;
 
        spin_lock_irqsave(&tty->buf.lock, flags);
-       /* So we know a flush is running */
-       set_bit(TTY_FLUSHING, &tty->flags);
-       head = tty->buf.head;
-       if (head != NULL) {
-               tty->buf.head = NULL;
-               for (;;) {
-                       int count = head->commit - head->read;
+
+       if (!test_and_set_bit(TTY_FLUSHING, &tty->flags)) {
+               struct tty_buffer *head;
+               while ((head = tty->buf.head) != NULL) {
+                       int count;
+                       char *char_buf;
+                       unsigned char *flag_buf;
+
+                       count = head->commit - head->read;
                        if (!count) {
                                if (head->next == NULL)
                                        break;
-                               tbuf = head;
-                               head = head->next;
-                               tty_buffer_free(tty, tbuf);
+                               tty->buf.head = head->next;
+                               tty_buffer_free(tty, head);
                                continue;
                        }
                        /* Ldisc or user is trying to flush the buffers
@@ -445,9 +446,9 @@ static void flush_to_ldisc(struct work_struct *work)
                                                        flag_buf, count);
                        spin_lock_irqsave(&tty->buf.lock, flags);
                }
-               /* Restore the queue head */
-               tty->buf.head = head;
+               clear_bit(TTY_FLUSHING, &tty->flags);
        }
+
        /* We may have a deferred request to flush the input buffer,
           if so pull the chain under the lock and empty the queue */
        if (test_bit(TTY_FLUSHPENDING, &tty->flags)) {
@@ -455,7 +456,6 @@ static void flush_to_ldisc(struct work_struct *work)
                clear_bit(TTY_FLUSHPENDING, &tty->flags);
                wake_up(&tty->read_wait);
        }
-       clear_bit(TTY_FLUSHING, &tty->flags);
        spin_unlock_irqrestore(&tty->buf.lock, flags);
 
        tty_ldisc_deref(disc);
@@ -471,7 +471,7 @@ static void flush_to_ldisc(struct work_struct *work)
  */
 void tty_flush_to_ldisc(struct tty_struct *tty)
 {
-       flush_to_ldisc(&tty->buf.work.work);
+       flush_delayed_work(&tty->buf.work);
 }
 
 /**
This page took 0.026849 seconds and 5 git commands to generate.