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

Configure Feed

Select the types of activity you want to include in your feed.

tty: n_tty: extract n_tty_wait_for_input()

n_tty_read() is a very long function doing too much of different stuff.
Extract the "wait for input" to a separate function:
n_tty_wait_for_input(). It returns an error (< 0), no input (0), or has
potential input (1).

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
Link: https://lore.kernel.org/r/20250317070046.24386-11-jirislaby@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

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

+31 -26
+31 -26
drivers/tty/n_tty.c
··· 2145 2145 return kb - kbuf; 2146 2146 } 2147 2147 2148 + static int n_tty_wait_for_input(struct tty_struct *tty, struct file *file, 2149 + struct wait_queue_entry *wait, long *timeout) 2150 + { 2151 + if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) 2152 + return -EIO; 2153 + if (tty_hung_up_p(file)) 2154 + return 0; 2155 + /* 2156 + * Abort readers for ttys which never actually get hung up. 2157 + * See __tty_hangup(). 2158 + */ 2159 + if (test_bit(TTY_HUPPING, &tty->flags)) 2160 + return 0; 2161 + if (!*timeout) 2162 + return 0; 2163 + if (tty_io_nonblock(tty, file)) 2164 + return -EAGAIN; 2165 + if (signal_pending(current)) 2166 + return -ERESTARTSYS; 2167 + 2168 + up_read(&tty->termios_rwsem); 2169 + *timeout = wait_woken(wait, TASK_INTERRUPTIBLE, *timeout); 2170 + down_read(&tty->termios_rwsem); 2171 + 2172 + return 1; 2173 + } 2174 + 2148 2175 /** 2149 2176 * n_tty_read - read function for tty 2150 2177 * @tty: tty device ··· 2261 2234 tty_buffer_flush_work(tty->port); 2262 2235 down_read(&tty->termios_rwsem); 2263 2236 if (!input_available_p(tty, 0)) { 2264 - if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) { 2265 - retval = -EIO; 2237 + int ret = n_tty_wait_for_input(tty, file, &wait, 2238 + &timeout); 2239 + if (ret <= 0) { 2240 + retval = ret; 2266 2241 break; 2267 2242 } 2268 - if (tty_hung_up_p(file)) 2269 - break; 2270 - /* 2271 - * Abort readers for ttys which never actually 2272 - * get hung up. See __tty_hangup(). 2273 - */ 2274 - if (test_bit(TTY_HUPPING, &tty->flags)) 2275 - break; 2276 - if (!timeout) 2277 - break; 2278 - if (tty_io_nonblock(tty, file)) { 2279 - retval = -EAGAIN; 2280 - break; 2281 - } 2282 - if (signal_pending(current)) { 2283 - retval = -ERESTARTSYS; 2284 - break; 2285 - } 2286 - up_read(&tty->termios_rwsem); 2287 - 2288 - timeout = wait_woken(&wait, TASK_INTERRUPTIBLE, 2289 - timeout); 2290 - 2291 - down_read(&tty->termios_rwsem); 2292 2243 continue; 2293 2244 } 2294 2245 }