[PATCH 23/36] tty: use min() in iterate_tty_write()

From
Jiri Slaby (SUSE) <jirislaby@kernel.org>
Date
2023-08-10 09:17:32
Also in
lkml
Reply to
Jiri Slaby (SUSE), 2023-08-10
It simplifies the code. The "price" is we have to unify 'chunk' to be
size_t the same as 'count' is. But that change is actually correct.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/tty_io.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 846460c02c58..0cf1277e260b 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -964,9 +964,8 @@ int tty_write_lock(struct tty_struct *tty, bool ndelay)
 static ssize_t iterate_tty_write(struct tty_ldisc *ld, struct tty_struct *tty,
 				 struct file *file, struct iov_iter *from)
 {
-	size_t count = iov_iter_count(from);
+	size_t chunk, count = iov_iter_count(from);
 	ssize_t ret, written = 0;
-	unsigned int chunk;
 
 	ret = tty_write_lock(tty, file->f_flags & O_NDELAY);
 	if (ret < 0)
@@ -1010,10 +1009,7 @@ static ssize_t iterate_tty_write(struct tty_ldisc *ld, struct tty_struct *tty,
 
 	/* Do the write .. */
 	for (;;) {
-		size_t size = count;
-
-		if (size > chunk)
-			size = chunk;
+		size_t size = min(chunk, count);
 
 		ret = -EFAULT;
 		if (copy_from_iter(tty->write_buf, size, from) != size)
-- 
2.41.0
Thread (68 messages) 68 messages, 11 authors, last reply 2023-08-31
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help