diff --git a/drivers/tty/tty_buffer.c b/drivers/tty/tty_buffer.c index 4706df20191b..8917b6f87b04 100644 --- a/drivers/tty/tty_buffer.c +++ b/drivers/tty/tty_buffer.c @@ -71,7 +71,7 @@ void tty_buffer_unlock_exclusive(struct tty_port *port) atomic_dec(&buf->priority); mutex_unlock(&buf->lock); if (restart) - queue_work(system_unbound_wq, &buf->work); + queue_kthread_work(&port->worker, &buf->work); } EXPORT_SYMBOL_GPL(tty_buffer_unlock_exclusive); @@ -132,6 +132,7 @@ void tty_buffer_free_all(struct tty_port *port) buf->tail = &buf->sentinel; atomic_set(&buf->mem_used, 0); + kthread_stop(port->worker_thread); } /** @@ -404,7 +405,7 @@ void tty_schedule_flip(struct tty_port *port) * flush_to_ldisc() sees buffer data. */ smp_store_release(&buf->tail->commit, buf->tail->used); - queue_work(system_unbound_wq, &buf->work); + queue_kthread_work(&port->worker, &buf->work); } EXPORT_SYMBOL(tty_schedule_flip); @@ -472,7 +473,7 @@ receive_buf(struct tty_struct *tty, struct tty_buffer *head, int count) * 'consumer' */ -static void flush_to_ldisc(struct work_struct *work) +static void flush_to_ldisc(struct kthread_work *work) { struct tty_port *port = container_of(work, struct tty_port, buf.work); struct tty_bufhead *buf = &port->buf; @@ -562,8 +563,20 @@ void tty_buffer_init(struct tty_port *port) init_llist_head(&buf->free); atomic_set(&buf->mem_used, 0); atomic_set(&buf->priority, 0); - INIT_WORK(&buf->work, flush_to_ldisc); buf->mem_limit = TTYB_DEFAULT_MEM_LIMIT; + init_kthread_work(&buf->work, flush_to_ldisc); + init_kthread_worker(&port->worker); + port->worker_thread = kthread_run(kthread_worker_fn, &port->worker, + "tty_worker_thread"); + if (IS_ERR(port->worker_thread)) { + /* + * Not good, we can't unwind, this tty is going to be really + * sad... + */ + pr_err("Unable to start tty_worker_thread\n"); + } + + } /** @@ -591,15 +604,15 @@ void tty_buffer_set_lock_subclass(struct tty_port *port) bool tty_buffer_restart_work(struct tty_port *port) { - return queue_work(system_unbound_wq, &port->buf.work); + return queue_kthread_work(&port->worker, &port->buf.work); } bool tty_buffer_cancel_work(struct tty_port *port) { - return cancel_work_sync(&port->buf.work); + return kthread_cancel_work_sync(&port->buf.work); } void tty_buffer_flush_work(struct tty_port *port) { - flush_work(&port->buf.work); + flush_kthread_work(&port->buf.work); } diff --git a/include/linux/tty.h b/include/linux/tty.h index 812cdd8cff22..67e46308ca99 100644 --- a/include/linux/tty.h +++ b/include/linux/tty.h @@ -12,7 +12,7 @@ #include #include #include - +#include /* * Lock subclasses for tty locks @@ -82,7 +82,7 @@ static inline char *flag_buf_ptr(struct tty_buffer *b, int ofs) struct tty_bufhead { struct tty_buffer *head; /* Queue head */ - struct work_struct work; + struct kthread_work work; struct mutex lock; atomic_t priority; struct tty_buffer sentinel; @@ -240,6 +240,8 @@ struct tty_port { based drain is needed else set to size of fifo */ struct kref kref; /* Ref counter */ + struct kthread_worker worker; /* worker thread */ + struct task_struct *worker_thread; /* worker thread */ }; /*