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

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>

authored by

Jiri Slaby (SUSE) and committed by
Greg Kroah-Hartman
f812af36 40315ce5

+14 -15
+14 -15
drivers/tty/n_tty.c
··· 2281 2281 nr--; 2282 2282 } 2283 2283 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; 2299 2286 } 2300 2287 2301 2288 n_tty_check_unthrottle(tty); ··· 2309 2322 retval = kb - kbuf; 2310 2323 2311 2324 return retval; 2325 + more_to_be_read: 2326 + /* 2327 + * There is more to be had and we have nothing more to wait for, so 2328 + * let's mark us for retries. 2329 + * 2330 + * NOTE! We return here with both the termios_sem and atomic_read_lock 2331 + * still held, the retries will release them when done. 2332 + */ 2333 + remove_wait_queue(&tty->read_wait, &wait); 2334 + *cookie = cookie; 2335 + 2336 + return kb - kbuf; 2312 2337 } 2313 2338 2314 2339 /**