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

tty: tty_buffer: let tty_prepare_flip_string() return size_t

The same as in the previous patch, tty_prepare_flip_string() accepts
size_t as an size argument. It returns the same size (or less). It is
unexpected that it returns a signed value and can confuse users to check
for negative values.

Instead, return the same size_t as accepted to make clear we return
values >= 0, where zero in fact means failure.

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

authored by

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

+4 -3
+3 -2
drivers/tty/tty_buffer.c
··· 383 383 * Returns: the length available and buffer pointer (@chars) to the space which 384 384 * is now allocated and accounted for as ready for normal characters. 385 385 */ 386 - int tty_prepare_flip_string(struct tty_port *port, u8 **chars, size_t size) 386 + size_t tty_prepare_flip_string(struct tty_port *port, u8 **chars, size_t size) 387 387 { 388 - int space = __tty_buffer_request_room(port, size, false); 388 + size_t space = __tty_buffer_request_room(port, size, false); 389 389 390 390 if (likely(space)) { 391 391 struct tty_buffer *tb = port->buf.tail; ··· 395 395 memset(flag_buf_ptr(tb, tb->used), TTY_NORMAL, space); 396 396 tb->used += space; 397 397 } 398 + 398 399 return space; 399 400 } 400 401 EXPORT_SYMBOL_GPL(tty_prepare_flip_string);
+1 -1
include/linux/tty_flip.h
··· 13 13 size_t __tty_insert_flip_string_flags(struct tty_port *port, const u8 *chars, 14 14 const u8 *flags, bool mutable_flags, 15 15 size_t size); 16 - int tty_prepare_flip_string(struct tty_port *port, u8 **chars, size_t size); 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 18 int __tty_insert_flip_char(struct tty_port *port, u8 ch, u8 flag); 19 19