Commit ebee41c8 authored by Jiri Slaby (SUSE)'s avatar Jiri Slaby (SUSE) Committed by Greg Kroah-Hartman
Browse files

tty: tty_buffer: invert conditions in __tty_buffer_request_room()



We are used to handle "bad" states in the 'if's in the kernel. Refactor
(invert the two conditions in) __tty_buffer_request_room(), so that the
code returns from the fast paths immediately instead of postponing to
the heavy end of the function.

Signed-off-by: default avatar"Jiri Slaby (SUSE)" <jirislaby@kernel.org>
Link: https://lore.kernel.org/r/20230816105530.3335-11-jirislaby@kernel.org


Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 035197c9
Loading
Loading
Loading
Loading
+22 −22
Original line number Diff line number Diff line
@@ -266,10 +266,14 @@ static int __tty_buffer_request_room(struct tty_port *port, size_t size,
	size_t left = (b->flags ? 1 : 2) * b->size - b->used;
	bool change = !b->flags && flags;

	if (change || left < size) {
	if (!change && left >= size)
		return size;

	/* This is the slow path - looking for new buffers to use */
	n = tty_buffer_alloc(port, size);
		if (n != NULL) {
	if (n == NULL)
		return change ? 0 : left;

	n->flags = flags;
	buf->tail = n;
	/*
@@ -283,11 +287,7 @@ static int __tty_buffer_request_room(struct tty_port *port, size_t size,
	 * is advanced to the next buffer.
	 */
	smp_store_release(&b->next, n);
		} else if (change)
			size = 0;
		else
			size = left;
	}

	return size;
}