Skip to content

Commit 72369f2

Browse files
Jiri Slaby (SUSE)gregkh
authored andcommitted
tty: n_tty: use min3() in copy_from_read_buf()
n is a minimum of: * available chars in the ring buffer * available chars in the ring buffer till the end of the ring buffer * requested number (*nr) We can use min3() for that instead of two min()s. Signed-off-by: "Jiri Slaby (SUSE)" <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 1e61947 commit 72369f2

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

drivers/tty/n_tty.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1965,8 +1965,7 @@ static bool copy_from_read_buf(const struct tty_struct *tty, u8 **kbp,
19651965
size_t head = smp_load_acquire(&ldata->commit_head);
19661966
size_t tail = MASK(ldata->read_tail);
19671967

1968-
n = min(head - ldata->read_tail, N_TTY_BUF_SIZE - tail);
1969-
n = min(*nr, n);
1968+
n = min3(head - ldata->read_tail, N_TTY_BUF_SIZE - tail, *nr);
19701969
if (n) {
19711970
u8 *from = read_buf_addr(ldata, tail);
19721971
memcpy(*kbp, from, n);

0 commit comments

Comments
 (0)