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

Configure Feed

Select the types of activity you want to include in your feed.

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)" <jirislaby@kernel.org>
Link: https://lore.kernel.org/r/20230919085156.1578-4-jirislaby@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Jiri Slaby (SUSE) and committed by
Greg Kroah-Hartman
72369f2d 1e619477

+1 -2
+1 -2
drivers/tty/n_tty.c
··· 1965 1965 size_t head = smp_load_acquire(&ldata->commit_head); 1966 1966 size_t tail = MASK(ldata->read_tail); 1967 1967 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); 1970 1969 if (n) { 1971 1970 u8 *from = read_buf_addr(ldata, tail); 1972 1971 memcpy(*kbp, from, n);