Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tty: tty_buffer: use __tty_insert_flip_string_flags() in tty_insert_flip_char()

Use __tty_insert_flip_string_flags() for the slow path of
tty_insert_flip_char(). The former is generic enough, so there is no
reason to reimplement the injection once again.

So now we have a single function stuffing into tty buffers.

Signed-off-by: "Jiri Slaby (SUSE)" <jirislaby@kernel.org>
Link: https://lore.kernel.org/r/20230816105530.3335-8-jirislaby@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Jiri Slaby (SUSE) and committed by
Greg Kroah-Hartman
b49a0ff7 2ce2983c

+11 -30
+2 -1
Documentation/driver-api/tty/tty_buffer.rst
··· 15 15 ====================== 16 16 17 17 .. kernel-doc:: drivers/tty/tty_buffer.c 18 - :identifiers: tty_prepare_flip_string __tty_insert_flip_char 18 + :identifiers: tty_prepare_flip_string 19 19 tty_flip_buffer_push tty_ldisc_receive_buf 20 20 21 21 .. kernel-doc:: include/linux/tty_flip.h 22 22 :identifiers: tty_insert_flip_string_fixed_flag tty_insert_flip_string_flags 23 + tty_insert_flip_char 23 24 24 25 ---- 25 26
-26
drivers/tty/tty_buffer.c
··· 344 344 EXPORT_SYMBOL(__tty_insert_flip_string_flags); 345 345 346 346 /** 347 - * __tty_insert_flip_char - add one character to the tty buffer 348 - * @port: tty port 349 - * @ch: character 350 - * @flag: flag byte 351 - * 352 - * Queue a single byte @ch to the tty buffering, with an optional flag. This is 353 - * the slow path of tty_insert_flip_char(). 354 - */ 355 - int __tty_insert_flip_char(struct tty_port *port, u8 ch, u8 flag) 356 - { 357 - struct tty_buffer *tb; 358 - bool flags = flag != TTY_NORMAL; 359 - 360 - if (!__tty_buffer_request_room(port, 1, flags)) 361 - return 0; 362 - 363 - tb = port->buf.tail; 364 - if (tb->flags) 365 - *flag_buf_ptr(tb, tb->used) = flag; 366 - *char_buf_ptr(tb, tb->used++) = ch; 367 - 368 - return 1; 369 - } 370 - EXPORT_SYMBOL(__tty_insert_flip_char); 371 - 372 - /** 373 347 * tty_prepare_flip_string - make room for characters 374 348 * @port: tty port 375 349 * @chars: return pointer for character write area
+9 -3
include/linux/tty_flip.h
··· 15 15 size_t size); 16 16 size_t tty_prepare_flip_string(struct tty_port *port, u8 **chars, size_t size); 17 17 void tty_flip_buffer_push(struct tty_port *port); 18 - int __tty_insert_flip_char(struct tty_port *port, u8 ch, u8 flag); 19 18 20 19 /** 21 20 * tty_insert_flip_string_fixed_flag - add characters to the tty buffer ··· 54 55 return __tty_insert_flip_string_flags(port, chars, flags, true, size); 55 56 } 56 57 57 - 58 + /** 59 + * tty_insert_flip_char - add one character to the tty buffer 60 + * @port: tty port 61 + * @ch: character 62 + * @flag: flag byte 63 + * 64 + * Queue a single byte @ch to the tty buffering, with an optional flag. 65 + */ 58 66 static inline size_t tty_insert_flip_char(struct tty_port *port, u8 ch, u8 flag) 59 67 { 60 68 struct tty_buffer *tb = port->buf.tail; ··· 74 68 *char_buf_ptr(tb, tb->used++) = ch; 75 69 return 1; 76 70 } 77 - return __tty_insert_flip_char(port, ch, flag); 71 + return __tty_insert_flip_string_flags(port, &ch, &flag, false, 1); 78 72 } 79 73 80 74 static inline size_t tty_insert_flip_string(struct tty_port *port,