]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
tty: n_tty: use min3() in copy_from_read_buf()
authorJiri Slaby (SUSE) <jirislaby@kernel.org>
Tue, 19 Sep 2023 08:51:44 +0000 (10:51 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 3 Oct 2023 12:31:15 +0000 (14:31 +0200)
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>
drivers/tty/n_tty.c

index e917faa0b84ce51dd31d1442fa5d85d567516f22..6a112910c05828062cc2a58393a178fe41294e31 100644 (file)
@@ -1965,8 +1965,7 @@ static bool copy_from_read_buf(const struct tty_struct *tty, u8 **kbp,
        size_t head = smp_load_acquire(&ldata->commit_head);
        size_t tail = MASK(ldata->read_tail);
 
-       n = min(head - ldata->read_tail, N_TTY_BUF_SIZE - tail);
-       n = min(*nr, n);
+       n = min3(head - ldata->read_tail, N_TTY_BUF_SIZE - tail, *nr);
        if (n) {
                u8 *from = read_buf_addr(ldata, tail);
                memcpy(*kbp, from, n);