Skip to content

Commit f812af3

Browse files
Jiri Slaby (SUSE)gregkh
authored andcommitted
tty: n_tty: move more_to_be_read to the end of n_tty_read()
n_tty_read() contains "we need more data" handling deep in that function. And there is also a label (more_to_be_read) as we handle this situation from two places. It makes more sense to have all "return"s accumulated at the end of functions. And "goto" from multiple places there. Therefore, do this with the "more_to_be_read" label in n_tty_read(). After this and the previous changes, n_tty_read() is now much more easier to follow. Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org> Link: https://lore.kernel.org/r/20250317070046.24386-12-jirislaby@kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 40315ce commit f812af3

1 file changed

Lines changed: 14 additions & 15 deletions

File tree

drivers/tty/n_tty.c

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2281,21 +2281,8 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file, u8 *kbuf,
22812281
nr--;
22822282
}
22832283

2284-
/*
2285-
* Copy data, and if there is more to be had
2286-
* and we have nothing more to wait for, then
2287-
* let's mark us for retries.
2288-
*
2289-
* NOTE! We return here with both the termios_sem
2290-
* and atomic_read_lock still held, the retries
2291-
* will release them when done.
2292-
*/
2293-
if (copy_from_read_buf(tty, &kb, &nr) && kb - kbuf >= minimum) {
2294-
more_to_be_read:
2295-
remove_wait_queue(&tty->read_wait, &wait);
2296-
*cookie = cookie;
2297-
return kb - kbuf;
2298-
}
2284+
if (copy_from_read_buf(tty, &kb, &nr) && kb - kbuf >= minimum)
2285+
goto more_to_be_read;
22992286
}
23002287

23012288
n_tty_check_unthrottle(tty);
@@ -2322,6 +2309,18 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file, u8 *kbuf,
23222309
retval = kb - kbuf;
23232310

23242311
return retval;
2312+
more_to_be_read:
2313+
/*
2314+
* There is more to be had and we have nothing more to wait for, so
2315+
* let's mark us for retries.
2316+
*
2317+
* NOTE! We return here with both the termios_sem and atomic_read_lock
2318+
* still held, the retries will release them when done.
2319+
*/
2320+
remove_wait_queue(&tty->read_wait, &wait);
2321+
*cookie = cookie;
2322+
2323+
return kb - kbuf;
23252324
}
23262325

23272326
/**

0 commit comments

Comments
 (0)