tty: use min() for size computation in iterate_tty_read()
authorJiri Slaby (SUSE) <jirislaby@kernel.org>
Thu, 10 Aug 2023 09:15:00 +0000 (11:15 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 11 Aug 2023 19:12:46 +0000 (21:12 +0200)
The computation is more obvious with min().

Signed-off-by: "Jiri Slaby (SUSE)" <jirislaby@kernel.org>
Link: https://lore.kernel.org/r/20230810091510.13006-27-jirislaby@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/tty_io.c

index 7cfa99fbbb62f5b9773c19a1974fac7c852a7e39..4f21a21a1fd598202390086f425c99e7d95db770 100644 (file)
@@ -853,9 +853,8 @@ static ssize_t iterate_tty_read(struct tty_ldisc *ld, struct tty_struct *tty,
        size_t copied, count = iov_iter_count(to);
 
        do {
-               ssize_t size;
+               ssize_t size = min(count, sizeof(kernel_buf));
 
-               size = count > sizeof(kernel_buf) ? sizeof(kernel_buf) : count;
                size = ld->ops->read(tty, file, kernel_buf, size, &cookie, offset);
                if (!size)
                        break;