Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * Tty buffer allocation management
0004  */
0005 
0006 #include <linux/types.h>
0007 #include <linux/errno.h>
0008 #include <linux/minmax.h>
0009 #include <linux/tty.h>
0010 #include <linux/tty_driver.h>
0011 #include <linux/tty_flip.h>
0012 #include <linux/timer.h>
0013 #include <linux/string.h>
0014 #include <linux/slab.h>
0015 #include <linux/sched.h>
0016 #include <linux/wait.h>
0017 #include <linux/bitops.h>
0018 #include <linux/delay.h>
0019 #include <linux/module.h>
0020 #include <linux/ratelimit.h>
0021 #include "tty.h"
0022 
0023 #define MIN_TTYB_SIZE   256
0024 #define TTYB_ALIGN_MASK 255
0025 
0026 /*
0027  * Byte threshold to limit memory consumption for flip buffers.
0028  * The actual memory limit is > 2x this amount.
0029  */
0030 #define TTYB_DEFAULT_MEM_LIMIT  (640 * 1024UL)
0031 
0032 /*
0033  * We default to dicing tty buffer allocations to this many characters
0034  * in order to avoid multiple page allocations. We know the size of
0035  * tty_buffer itself but it must also be taken into account that the
0036  * buffer is 256 byte aligned. See tty_buffer_find for the allocation
0037  * logic this must match.
0038  */
0039 
0040 #define TTY_BUFFER_PAGE (((PAGE_SIZE - sizeof(struct tty_buffer)) / 2) & ~0xFF)
0041 
0042 /**
0043  * tty_buffer_lock_exclusive    -   gain exclusive access to buffer
0044  * @port: tty port owning the flip buffer
0045  *
0046  * Guarantees safe use of the &tty_ldisc_ops.receive_buf() method by excluding
0047  * the buffer work and any pending flush from using the flip buffer. Data can
0048  * continue to be added concurrently to the flip buffer from the driver side.
0049  *
0050  * See also tty_buffer_unlock_exclusive().
0051  */
0052 void tty_buffer_lock_exclusive(struct tty_port *port)
0053 {
0054     struct tty_bufhead *buf = &port->buf;
0055 
0056     atomic_inc(&buf->priority);
0057     mutex_lock(&buf->lock);
0058 }
0059 EXPORT_SYMBOL_GPL(tty_buffer_lock_exclusive);
0060 
0061 /**
0062  * tty_buffer_unlock_exclusive  -   release exclusive access
0063  * @port: tty port owning the flip buffer
0064  *
0065  * The buffer work is restarted if there is data in the flip buffer.
0066  *
0067  * See also tty_buffer_lock_exclusive().
0068  */
0069 void tty_buffer_unlock_exclusive(struct tty_port *port)
0070 {
0071     struct tty_bufhead *buf = &port->buf;
0072     int restart;
0073 
0074     restart = buf->head->commit != buf->head->read;
0075 
0076     atomic_dec(&buf->priority);
0077     mutex_unlock(&buf->lock);
0078     if (restart)
0079         queue_work(system_unbound_wq, &buf->work);
0080 }
0081 EXPORT_SYMBOL_GPL(tty_buffer_unlock_exclusive);
0082 
0083 /**
0084  * tty_buffer_space_avail   -   return unused buffer space
0085  * @port: tty port owning the flip buffer
0086  *
0087  * Returns: the # of bytes which can be written by the driver without reaching
0088  * the buffer limit.
0089  *
0090  * Note: this does not guarantee that memory is available to write the returned
0091  * # of bytes (use tty_prepare_flip_string() to pre-allocate if memory
0092  * guarantee is required).
0093  */
0094 unsigned int tty_buffer_space_avail(struct tty_port *port)
0095 {
0096     int space = port->buf.mem_limit - atomic_read(&port->buf.mem_used);
0097 
0098     return max(space, 0);
0099 }
0100 EXPORT_SYMBOL_GPL(tty_buffer_space_avail);
0101 
0102 static void tty_buffer_reset(struct tty_buffer *p, size_t size)
0103 {
0104     p->used = 0;
0105     p->size = size;
0106     p->next = NULL;
0107     p->commit = 0;
0108     p->lookahead = 0;
0109     p->read = 0;
0110     p->flags = 0;
0111 }
0112 
0113 /**
0114  * tty_buffer_free_all      -   free buffers used by a tty
0115  * @port: tty port to free from
0116  *
0117  * Remove all the buffers pending on a tty whether queued with data or in the
0118  * free ring. Must be called when the tty is no longer in use.
0119  */
0120 void tty_buffer_free_all(struct tty_port *port)
0121 {
0122     struct tty_bufhead *buf = &port->buf;
0123     struct tty_buffer *p, *next;
0124     struct llist_node *llist;
0125     unsigned int freed = 0;
0126     int still_used;
0127 
0128     while ((p = buf->head) != NULL) {
0129         buf->head = p->next;
0130         freed += p->size;
0131         if (p->size > 0)
0132             kfree(p);
0133     }
0134     llist = llist_del_all(&buf->free);
0135     llist_for_each_entry_safe(p, next, llist, free)
0136         kfree(p);
0137 
0138     tty_buffer_reset(&buf->sentinel, 0);
0139     buf->head = &buf->sentinel;
0140     buf->tail = &buf->sentinel;
0141 
0142     still_used = atomic_xchg(&buf->mem_used, 0);
0143     WARN(still_used != freed, "we still have not freed %d bytes!",
0144             still_used - freed);
0145 }
0146 
0147 /**
0148  * tty_buffer_alloc -   allocate a tty buffer
0149  * @port: tty port
0150  * @size: desired size (characters)
0151  *
0152  * Allocate a new tty buffer to hold the desired number of characters. We
0153  * round our buffers off in 256 character chunks to get better allocation
0154  * behaviour.
0155  *
0156  * Returns: %NULL if out of memory or the allocation would exceed the per
0157  * device queue.
0158  */
0159 static struct tty_buffer *tty_buffer_alloc(struct tty_port *port, size_t size)
0160 {
0161     struct llist_node *free;
0162     struct tty_buffer *p;
0163 
0164     /* Round the buffer size out */
0165     size = __ALIGN_MASK(size, TTYB_ALIGN_MASK);
0166 
0167     if (size <= MIN_TTYB_SIZE) {
0168         free = llist_del_first(&port->buf.free);
0169         if (free) {
0170             p = llist_entry(free, struct tty_buffer, free);
0171             goto found;
0172         }
0173     }
0174 
0175     /* Should possibly check if this fails for the largest buffer we
0176      * have queued and recycle that ?
0177      */
0178     if (atomic_read(&port->buf.mem_used) > port->buf.mem_limit)
0179         return NULL;
0180     p = kmalloc(sizeof(struct tty_buffer) + 2 * size,
0181             GFP_ATOMIC | __GFP_NOWARN);
0182     if (p == NULL)
0183         return NULL;
0184 
0185 found:
0186     tty_buffer_reset(p, size);
0187     atomic_add(size, &port->buf.mem_used);
0188     return p;
0189 }
0190 
0191 /**
0192  * tty_buffer_free      -   free a tty buffer
0193  * @port: tty port owning the buffer
0194  * @b: the buffer to free
0195  *
0196  * Free a tty buffer, or add it to the free list according to our internal
0197  * strategy.
0198  */
0199 static void tty_buffer_free(struct tty_port *port, struct tty_buffer *b)
0200 {
0201     struct tty_bufhead *buf = &port->buf;
0202 
0203     /* Dumb strategy for now - should keep some stats */
0204     WARN_ON(atomic_sub_return(b->size, &buf->mem_used) < 0);
0205 
0206     if (b->size > MIN_TTYB_SIZE)
0207         kfree(b);
0208     else if (b->size > 0)
0209         llist_add(&b->free, &buf->free);
0210 }
0211 
0212 /**
0213  * tty_buffer_flush     -   flush full tty buffers
0214  * @tty: tty to flush
0215  * @ld: optional ldisc ptr (must be referenced)
0216  *
0217  * Flush all the buffers containing receive data. If @ld != %NULL, flush the
0218  * ldisc input buffer.
0219  *
0220  * Locking: takes buffer lock to ensure single-threaded flip buffer 'consumer'.
0221  */
0222 void tty_buffer_flush(struct tty_struct *tty, struct tty_ldisc *ld)
0223 {
0224     struct tty_port *port = tty->port;
0225     struct tty_bufhead *buf = &port->buf;
0226     struct tty_buffer *next;
0227 
0228     atomic_inc(&buf->priority);
0229 
0230     mutex_lock(&buf->lock);
0231     /* paired w/ release in __tty_buffer_request_room; ensures there are
0232      * no pending memory accesses to the freed buffer
0233      */
0234     while ((next = smp_load_acquire(&buf->head->next)) != NULL) {
0235         tty_buffer_free(port, buf->head);
0236         buf->head = next;
0237     }
0238     buf->head->read = buf->head->commit;
0239     buf->head->lookahead = buf->head->read;
0240 
0241     if (ld && ld->ops->flush_buffer)
0242         ld->ops->flush_buffer(tty);
0243 
0244     atomic_dec(&buf->priority);
0245     mutex_unlock(&buf->lock);
0246 }
0247 
0248 /**
0249  * __tty_buffer_request_room    -   grow tty buffer if needed
0250  * @port: tty port
0251  * @size: size desired
0252  * @flags: buffer flags if new buffer allocated (default = 0)
0253  *
0254  * Make at least @size bytes of linear space available for the tty buffer.
0255  *
0256  * Will change over to a new buffer if the current buffer is encoded as
0257  * %TTY_NORMAL (so has no flags buffer) and the new buffer requires a flags
0258  * buffer.
0259  *
0260  * Returns: the size we managed to find.
0261  */
0262 static int __tty_buffer_request_room(struct tty_port *port, size_t size,
0263                      int flags)
0264 {
0265     struct tty_bufhead *buf = &port->buf;
0266     struct tty_buffer *b, *n;
0267     int left, change;
0268 
0269     b = buf->tail;
0270     if (b->flags & TTYB_NORMAL)
0271         left = 2 * b->size - b->used;
0272     else
0273         left = b->size - b->used;
0274 
0275     change = (b->flags & TTYB_NORMAL) && (~flags & TTYB_NORMAL);
0276     if (change || left < size) {
0277         /* This is the slow path - looking for new buffers to use */
0278         n = tty_buffer_alloc(port, size);
0279         if (n != NULL) {
0280             n->flags = flags;
0281             buf->tail = n;
0282             /*
0283              * Paired w/ acquire in flush_to_ldisc() and lookahead_bufs()
0284              * ensures they see all buffer data.
0285              */
0286             smp_store_release(&b->commit, b->used);
0287             /*
0288              * Paired w/ acquire in flush_to_ldisc() and lookahead_bufs()
0289              * ensures the latest commit value can be read before the head
0290              * is advanced to the next buffer.
0291              */
0292             smp_store_release(&b->next, n);
0293         } else if (change)
0294             size = 0;
0295         else
0296             size = left;
0297     }
0298     return size;
0299 }
0300 
0301 int tty_buffer_request_room(struct tty_port *port, size_t size)
0302 {
0303     return __tty_buffer_request_room(port, size, 0);
0304 }
0305 EXPORT_SYMBOL_GPL(tty_buffer_request_room);
0306 
0307 /**
0308  * tty_insert_flip_string_fixed_flag - add characters to the tty buffer
0309  * @port: tty port
0310  * @chars: characters
0311  * @flag: flag value for each character
0312  * @size: size
0313  *
0314  * Queue a series of bytes to the tty buffering. All the characters passed are
0315  * marked with the supplied flag.
0316  *
0317  * Returns: the number added.
0318  */
0319 int tty_insert_flip_string_fixed_flag(struct tty_port *port,
0320         const unsigned char *chars, char flag, size_t size)
0321 {
0322     int copied = 0;
0323 
0324     do {
0325         int goal = min_t(size_t, size - copied, TTY_BUFFER_PAGE);
0326         int flags = (flag == TTY_NORMAL) ? TTYB_NORMAL : 0;
0327         int space = __tty_buffer_request_room(port, goal, flags);
0328         struct tty_buffer *tb = port->buf.tail;
0329 
0330         if (unlikely(space == 0))
0331             break;
0332         memcpy(char_buf_ptr(tb, tb->used), chars, space);
0333         if (~tb->flags & TTYB_NORMAL)
0334             memset(flag_buf_ptr(tb, tb->used), flag, space);
0335         tb->used += space;
0336         copied += space;
0337         chars += space;
0338         /* There is a small chance that we need to split the data over
0339          * several buffers. If this is the case we must loop.
0340          */
0341     } while (unlikely(size > copied));
0342     return copied;
0343 }
0344 EXPORT_SYMBOL(tty_insert_flip_string_fixed_flag);
0345 
0346 /**
0347  * tty_insert_flip_string_flags -   add characters to the tty buffer
0348  * @port: tty port
0349  * @chars: characters
0350  * @flags: flag bytes
0351  * @size: size
0352  *
0353  * Queue a series of bytes to the tty buffering. For each character the flags
0354  * array indicates the status of the character.
0355  *
0356  * Returns: the number added.
0357  */
0358 int tty_insert_flip_string_flags(struct tty_port *port,
0359         const unsigned char *chars, const char *flags, size_t size)
0360 {
0361     int copied = 0;
0362 
0363     do {
0364         int goal = min_t(size_t, size - copied, TTY_BUFFER_PAGE);
0365         int space = tty_buffer_request_room(port, goal);
0366         struct tty_buffer *tb = port->buf.tail;
0367 
0368         if (unlikely(space == 0))
0369             break;
0370         memcpy(char_buf_ptr(tb, tb->used), chars, space);
0371         memcpy(flag_buf_ptr(tb, tb->used), flags, space);
0372         tb->used += space;
0373         copied += space;
0374         chars += space;
0375         flags += space;
0376         /* There is a small chance that we need to split the data over
0377          * several buffers. If this is the case we must loop.
0378          */
0379     } while (unlikely(size > copied));
0380     return copied;
0381 }
0382 EXPORT_SYMBOL(tty_insert_flip_string_flags);
0383 
0384 /**
0385  * __tty_insert_flip_char   -   add one character to the tty buffer
0386  * @port: tty port
0387  * @ch: character
0388  * @flag: flag byte
0389  *
0390  * Queue a single byte @ch to the tty buffering, with an optional flag. This is
0391  * the slow path of tty_insert_flip_char().
0392  */
0393 int __tty_insert_flip_char(struct tty_port *port, unsigned char ch, char flag)
0394 {
0395     struct tty_buffer *tb;
0396     int flags = (flag == TTY_NORMAL) ? TTYB_NORMAL : 0;
0397 
0398     if (!__tty_buffer_request_room(port, 1, flags))
0399         return 0;
0400 
0401     tb = port->buf.tail;
0402     if (~tb->flags & TTYB_NORMAL)
0403         *flag_buf_ptr(tb, tb->used) = flag;
0404     *char_buf_ptr(tb, tb->used++) = ch;
0405 
0406     return 1;
0407 }
0408 EXPORT_SYMBOL(__tty_insert_flip_char);
0409 
0410 /**
0411  * tty_prepare_flip_string  -   make room for characters
0412  * @port: tty port
0413  * @chars: return pointer for character write area
0414  * @size: desired size
0415  *
0416  * Prepare a block of space in the buffer for data.
0417  *
0418  * This is used for drivers that need their own block copy routines into the
0419  * buffer. There is no guarantee the buffer is a DMA target!
0420  *
0421  * Returns: the length available and buffer pointer (@chars) to the space which
0422  * is now allocated and accounted for as ready for normal characters.
0423  */
0424 int tty_prepare_flip_string(struct tty_port *port, unsigned char **chars,
0425         size_t size)
0426 {
0427     int space = __tty_buffer_request_room(port, size, TTYB_NORMAL);
0428 
0429     if (likely(space)) {
0430         struct tty_buffer *tb = port->buf.tail;
0431 
0432         *chars = char_buf_ptr(tb, tb->used);
0433         if (~tb->flags & TTYB_NORMAL)
0434             memset(flag_buf_ptr(tb, tb->used), TTY_NORMAL, space);
0435         tb->used += space;
0436     }
0437     return space;
0438 }
0439 EXPORT_SYMBOL_GPL(tty_prepare_flip_string);
0440 
0441 /**
0442  * tty_ldisc_receive_buf    -   forward data to line discipline
0443  * @ld: line discipline to process input
0444  * @p: char buffer
0445  * @f: %TTY_NORMAL, %TTY_BREAK, etc. flags buffer
0446  * @count: number of bytes to process
0447  *
0448  * Callers other than flush_to_ldisc() need to exclude the kworker from
0449  * concurrent use of the line discipline, see paste_selection().
0450  *
0451  * Returns: the number of bytes processed.
0452  */
0453 int tty_ldisc_receive_buf(struct tty_ldisc *ld, const unsigned char *p,
0454               const char *f, int count)
0455 {
0456     if (ld->ops->receive_buf2)
0457         count = ld->ops->receive_buf2(ld->tty, p, f, count);
0458     else {
0459         count = min_t(int, count, ld->tty->receive_room);
0460         if (count && ld->ops->receive_buf)
0461             ld->ops->receive_buf(ld->tty, p, f, count);
0462     }
0463     return count;
0464 }
0465 EXPORT_SYMBOL_GPL(tty_ldisc_receive_buf);
0466 
0467 static void lookahead_bufs(struct tty_port *port, struct tty_buffer *head)
0468 {
0469     head->lookahead = max(head->lookahead, head->read);
0470 
0471     while (head) {
0472         struct tty_buffer *next;
0473         unsigned int count;
0474 
0475         /*
0476          * Paired w/ release in __tty_buffer_request_room();
0477          * ensures commit value read is not stale if the head
0478          * is advancing to the next buffer.
0479          */
0480         next = smp_load_acquire(&head->next);
0481         /*
0482          * Paired w/ release in __tty_buffer_request_room() or in
0483          * tty_buffer_flush(); ensures we see the committed buffer data.
0484          */
0485         count = smp_load_acquire(&head->commit) - head->lookahead;
0486         if (!count) {
0487             head = next;
0488             continue;
0489         }
0490 
0491         if (port->client_ops->lookahead_buf) {
0492             unsigned char *p, *f = NULL;
0493 
0494             p = char_buf_ptr(head, head->lookahead);
0495             if (~head->flags & TTYB_NORMAL)
0496                 f = flag_buf_ptr(head, head->lookahead);
0497 
0498             port->client_ops->lookahead_buf(port, p, f, count);
0499         }
0500 
0501         head->lookahead += count;
0502     }
0503 }
0504 
0505 static int
0506 receive_buf(struct tty_port *port, struct tty_buffer *head, int count)
0507 {
0508     unsigned char *p = char_buf_ptr(head, head->read);
0509     const char *f = NULL;
0510     int n;
0511 
0512     if (~head->flags & TTYB_NORMAL)
0513         f = flag_buf_ptr(head, head->read);
0514 
0515     n = port->client_ops->receive_buf(port, p, f, count);
0516     if (n > 0)
0517         memset(p, 0, n);
0518     return n;
0519 }
0520 
0521 /**
0522  * flush_to_ldisc       -   flush data from buffer to ldisc
0523  * @work: tty structure passed from work queue.
0524  *
0525  * This routine is called out of the software interrupt to flush data from the
0526  * buffer chain to the line discipline.
0527  *
0528  * The receive_buf() method is single threaded for each tty instance.
0529  *
0530  * Locking: takes buffer lock to ensure single-threaded flip buffer 'consumer'.
0531  */
0532 static void flush_to_ldisc(struct work_struct *work)
0533 {
0534     struct tty_port *port = container_of(work, struct tty_port, buf.work);
0535     struct tty_bufhead *buf = &port->buf;
0536 
0537     mutex_lock(&buf->lock);
0538 
0539     while (1) {
0540         struct tty_buffer *head = buf->head;
0541         struct tty_buffer *next;
0542         int count, rcvd;
0543 
0544         /* Ldisc or user is trying to gain exclusive access */
0545         if (atomic_read(&buf->priority))
0546             break;
0547 
0548         /* paired w/ release in __tty_buffer_request_room();
0549          * ensures commit value read is not stale if the head
0550          * is advancing to the next buffer
0551          */
0552         next = smp_load_acquire(&head->next);
0553         /* paired w/ release in __tty_buffer_request_room() or in
0554          * tty_buffer_flush(); ensures we see the committed buffer data
0555          */
0556         count = smp_load_acquire(&head->commit) - head->read;
0557         if (!count) {
0558             if (next == NULL)
0559                 break;
0560             buf->head = next;
0561             tty_buffer_free(port, head);
0562             continue;
0563         }
0564 
0565         rcvd = receive_buf(port, head, count);
0566         head->read += rcvd;
0567         if (rcvd < count)
0568             lookahead_bufs(port, head);
0569         if (!rcvd)
0570             break;
0571 
0572         if (need_resched())
0573             cond_resched();
0574     }
0575 
0576     mutex_unlock(&buf->lock);
0577 
0578 }
0579 
0580 static inline void tty_flip_buffer_commit(struct tty_buffer *tail)
0581 {
0582     /*
0583      * Paired w/ acquire in flush_to_ldisc(); ensures flush_to_ldisc() sees
0584      * buffer data.
0585      */
0586     smp_store_release(&tail->commit, tail->used);
0587 }
0588 
0589 /**
0590  * tty_flip_buffer_push     -   push terminal buffers
0591  * @port: tty port to push
0592  *
0593  * Queue a push of the terminal flip buffers to the line discipline. Can be
0594  * called from IRQ/atomic context.
0595  *
0596  * In the event of the queue being busy for flipping the work will be held off
0597  * and retried later.
0598  */
0599 void tty_flip_buffer_push(struct tty_port *port)
0600 {
0601     struct tty_bufhead *buf = &port->buf;
0602 
0603     tty_flip_buffer_commit(buf->tail);
0604     queue_work(system_unbound_wq, &buf->work);
0605 }
0606 EXPORT_SYMBOL(tty_flip_buffer_push);
0607 
0608 /**
0609  * tty_insert_flip_string_and_push_buffer - add characters to the tty buffer and
0610  *  push
0611  * @port: tty port
0612  * @chars: characters
0613  * @size: size
0614  *
0615  * The function combines tty_insert_flip_string() and tty_flip_buffer_push()
0616  * with the exception of properly holding the @port->lock.
0617  *
0618  * To be used only internally (by pty currently).
0619  *
0620  * Returns: the number added.
0621  */
0622 int tty_insert_flip_string_and_push_buffer(struct tty_port *port,
0623         const unsigned char *chars, size_t size)
0624 {
0625     struct tty_bufhead *buf = &port->buf;
0626     unsigned long flags;
0627 
0628     spin_lock_irqsave(&port->lock, flags);
0629     size = tty_insert_flip_string(port, chars, size);
0630     if (size)
0631         tty_flip_buffer_commit(buf->tail);
0632     spin_unlock_irqrestore(&port->lock, flags);
0633 
0634     queue_work(system_unbound_wq, &buf->work);
0635 
0636     return size;
0637 }
0638 
0639 /**
0640  * tty_buffer_init      -   prepare a tty buffer structure
0641  * @port: tty port to initialise
0642  *
0643  * Set up the initial state of the buffer management for a tty device. Must be
0644  * called before the other tty buffer functions are used.
0645  */
0646 void tty_buffer_init(struct tty_port *port)
0647 {
0648     struct tty_bufhead *buf = &port->buf;
0649 
0650     mutex_init(&buf->lock);
0651     tty_buffer_reset(&buf->sentinel, 0);
0652     buf->head = &buf->sentinel;
0653     buf->tail = &buf->sentinel;
0654     init_llist_head(&buf->free);
0655     atomic_set(&buf->mem_used, 0);
0656     atomic_set(&buf->priority, 0);
0657     INIT_WORK(&buf->work, flush_to_ldisc);
0658     buf->mem_limit = TTYB_DEFAULT_MEM_LIMIT;
0659 }
0660 
0661 /**
0662  * tty_buffer_set_limit     -   change the tty buffer memory limit
0663  * @port: tty port to change
0664  * @limit: memory limit to set
0665  *
0666  * Change the tty buffer memory limit.
0667  *
0668  * Must be called before the other tty buffer functions are used.
0669  */
0670 int tty_buffer_set_limit(struct tty_port *port, int limit)
0671 {
0672     if (limit < MIN_TTYB_SIZE)
0673         return -EINVAL;
0674     port->buf.mem_limit = limit;
0675     return 0;
0676 }
0677 EXPORT_SYMBOL_GPL(tty_buffer_set_limit);
0678 
0679 /* slave ptys can claim nested buffer lock when handling BRK and INTR */
0680 void tty_buffer_set_lock_subclass(struct tty_port *port)
0681 {
0682     lockdep_set_subclass(&port->buf.lock, TTY_LOCK_SLAVE);
0683 }
0684 
0685 bool tty_buffer_restart_work(struct tty_port *port)
0686 {
0687     return queue_work(system_unbound_wq, &port->buf.work);
0688 }
0689 
0690 bool tty_buffer_cancel_work(struct tty_port *port)
0691 {
0692     return cancel_work_sync(&port->buf.work);
0693 }
0694 
0695 void tty_buffer_flush_work(struct tty_port *port)
0696 {
0697     flush_work(&port->buf.work);
0698 }