Commit 45242006 authored by Linus Torvalds's avatar Linus Torvalds

Make flush_to_ldisc properly handle parallel calls

parent 80f50691
...@@ -402,28 +402,26 @@ static void flush_to_ldisc(struct work_struct *work) ...@@ -402,28 +402,26 @@ static void flush_to_ldisc(struct work_struct *work)
container_of(work, struct tty_struct, buf.work.work); container_of(work, struct tty_struct, buf.work.work);
unsigned long flags; unsigned long flags;
struct tty_ldisc *disc; struct tty_ldisc *disc;
struct tty_buffer *tbuf, *head;
char *char_buf;
unsigned char *flag_buf;
disc = tty_ldisc_ref(tty); disc = tty_ldisc_ref(tty);
if (disc == NULL) /* !TTY_LDISC */ if (disc == NULL) /* !TTY_LDISC */
return; return;
spin_lock_irqsave(&tty->buf.lock, flags); spin_lock_irqsave(&tty->buf.lock, flags);
/* So we know a flush is running */
set_bit(TTY_FLUSHING, &tty->flags); if (!test_and_set_bit(TTY_FLUSHING, &tty->flags)) {
head = tty->buf.head; struct tty_buffer *head;
if (head != NULL) { while ((head = tty->buf.head) != NULL) {
tty->buf.head = NULL; int count;
for (;;) { char *char_buf;
int count = head->commit - head->read; unsigned char *flag_buf;
count = head->commit - head->read;
if (!count) { if (!count) {
if (head->next == NULL) if (head->next == NULL)
break; break;
tbuf = head; tty->buf.head = head->next;
head = head->next; tty_buffer_free(tty, head);
tty_buffer_free(tty, tbuf);
continue; continue;
} }
/* Ldisc or user is trying to flush the buffers /* Ldisc or user is trying to flush the buffers
...@@ -445,9 +443,9 @@ static void flush_to_ldisc(struct work_struct *work) ...@@ -445,9 +443,9 @@ static void flush_to_ldisc(struct work_struct *work)
flag_buf, count); flag_buf, count);
spin_lock_irqsave(&tty->buf.lock, flags); spin_lock_irqsave(&tty->buf.lock, flags);
} }
/* Restore the queue head */ clear_bit(TTY_FLUSHING, &tty->flags);
tty->buf.head = head;
} }
/* We may have a deferred request to flush the input buffer, /* We may have a deferred request to flush the input buffer,
if so pull the chain under the lock and empty the queue */ if so pull the chain under the lock and empty the queue */
if (test_bit(TTY_FLUSHPENDING, &tty->flags)) { if (test_bit(TTY_FLUSHPENDING, &tty->flags)) {
...@@ -455,7 +453,6 @@ static void flush_to_ldisc(struct work_struct *work) ...@@ -455,7 +453,6 @@ static void flush_to_ldisc(struct work_struct *work)
clear_bit(TTY_FLUSHPENDING, &tty->flags); clear_bit(TTY_FLUSHPENDING, &tty->flags);
wake_up(&tty->read_wait); wake_up(&tty->read_wait);
} }
clear_bit(TTY_FLUSHING, &tty->flags);
spin_unlock_irqrestore(&tty->buf.lock, flags); spin_unlock_irqrestore(&tty->buf.lock, flags);
tty_ldisc_deref(disc); tty_ldisc_deref(disc);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment