* branch 'tty-fixes': tty: use the new 'flush_delayed_work()' helper to do ldisc flush workqueue: add 'flush_delayed_work()' to run and wait for delayed work Make flush_to_ldisc properly handle parallel calls
···402402 container_of(work, struct tty_struct, buf.work.work);403403 unsigned long flags;404404 struct tty_ldisc *disc;405405- struct tty_buffer *tbuf, *head;406406- char *char_buf;407407- unsigned char *flag_buf;408405409406 disc = tty_ldisc_ref(tty);410407 if (disc == NULL) /* !TTY_LDISC */411408 return;412409413410 spin_lock_irqsave(&tty->buf.lock, flags);414414- /* So we know a flush is running */415415- set_bit(TTY_FLUSHING, &tty->flags);416416- head = tty->buf.head;417417- if (head != NULL) {418418- tty->buf.head = NULL;419419- for (;;) {420420- int count = head->commit - head->read;411411+412412+ if (!test_and_set_bit(TTY_FLUSHING, &tty->flags)) {413413+ struct tty_buffer *head;414414+ while ((head = tty->buf.head) != NULL) {415415+ int count;416416+ char *char_buf;417417+ unsigned char *flag_buf;418418+419419+ count = head->commit - head->read;421420 if (!count) {422421 if (head->next == NULL)423422 break;424424- tbuf = head;425425- head = head->next;426426- tty_buffer_free(tty, tbuf);423423+ tty->buf.head = head->next;424424+ tty_buffer_free(tty, head);427425 continue;428426 }429427 /* Ldisc or user is trying to flush the buffers···443445 flag_buf, count);444446 spin_lock_irqsave(&tty->buf.lock, flags);445447 }446446- /* Restore the queue head */447447- tty->buf.head = head;448448+ clear_bit(TTY_FLUSHING, &tty->flags);448449 }450450+449451 /* We may have a deferred request to flush the input buffer,450452 if so pull the chain under the lock and empty the queue */451453 if (test_bit(TTY_FLUSHPENDING, &tty->flags)) {···453455 clear_bit(TTY_FLUSHPENDING, &tty->flags);454456 wake_up(&tty->read_wait);455457 }456456- clear_bit(TTY_FLUSHING, &tty->flags);457458 spin_unlock_irqrestore(&tty->buf.lock, flags);458459459460 tty_ldisc_deref(disc);···468471 */469472void tty_flush_to_ldisc(struct tty_struct *tty)470473{471471- flush_to_ldisc(&tty->buf.work.work);474474+ flush_delayed_work(&tty->buf.work);472475}473476474477/**
···640640EXPORT_SYMBOL(schedule_delayed_work);641641642642/**643643+ * flush_delayed_work - block until a dwork_struct's callback has terminated644644+ * @dwork: the delayed work which is to be flushed645645+ *646646+ * Any timeout is cancelled, and any pending work is run immediately.647647+ */648648+void flush_delayed_work(struct delayed_work *dwork)649649+{650650+ if (del_timer(&dwork->timer)) {651651+ struct cpu_workqueue_struct *cwq;652652+ cwq = wq_per_cpu(keventd_wq, get_cpu());653653+ __queue_work(cwq, &dwork->work);654654+ put_cpu();655655+ }656656+ flush_work(&dwork->work);657657+}658658+EXPORT_SYMBOL(flush_delayed_work);659659+660660+/**643661 * schedule_delayed_work_on - queue work in global workqueue on CPU after delay644662 * @cpu: cpu to use645663 * @dwork: job to be done