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_continue_cookie() from n_tty_read()

n_tty_read() is a very long function doing too much of different stuff.
Extract the "cookie" (continuation read) handling to a separate
function: n_tty_continue_cookie().

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

authored by

Jiri Slaby (SUSE) and committed by
Greg Kroah-Hartman
aa1ebc9c 67e781f5

+36 -30
+36 -30
drivers/tty/n_tty.c
··· 2111 2111 return __tty_check_change(tty, SIGTTIN); 2112 2112 } 2113 2113 2114 + /* 2115 + * We still hold the atomic_read_lock and the termios_rwsem, and can just 2116 + * continue to copy data. 2117 + */ 2118 + static ssize_t n_tty_continue_cookie(struct tty_struct *tty, u8 *kbuf, 2119 + size_t nr, void **cookie) 2120 + { 2121 + struct n_tty_data *ldata = tty->disc_data; 2122 + u8 *kb = kbuf; 2123 + 2124 + if (ldata->icanon && !L_EXTPROC(tty)) { 2125 + /* 2126 + * If we have filled the user buffer, see if we should skip an 2127 + * EOF character before releasing the lock and returning done. 2128 + */ 2129 + if (!nr) 2130 + canon_skip_eof(ldata); 2131 + else if (canon_copy_from_read_buf(tty, &kb, &nr)) 2132 + return kb - kbuf; 2133 + } else { 2134 + if (copy_from_read_buf(tty, &kb, &nr)) 2135 + return kb - kbuf; 2136 + } 2137 + 2138 + /* No more data - release locks and stop retries */ 2139 + n_tty_kick_worker(tty); 2140 + n_tty_check_unthrottle(tty); 2141 + up_read(&tty->termios_rwsem); 2142 + mutex_unlock(&ldata->atomic_read_lock); 2143 + *cookie = NULL; 2144 + 2145 + return kb - kbuf; 2146 + } 2114 2147 2115 2148 /** 2116 2149 * n_tty_read - read function for tty ··· 2177 2144 bool packet; 2178 2145 size_t old_tail; 2179 2146 2180 - /* 2181 - * Is this a continuation of a read started earler? 2182 - * 2183 - * If so, we still hold the atomic_read_lock and the 2184 - * termios_rwsem, and can just continue to copy data. 2185 - */ 2186 - if (*cookie) { 2187 - if (ldata->icanon && !L_EXTPROC(tty)) { 2188 - /* 2189 - * If we have filled the user buffer, see 2190 - * if we should skip an EOF character before 2191 - * releasing the lock and returning done. 2192 - */ 2193 - if (!nr) 2194 - canon_skip_eof(ldata); 2195 - else if (canon_copy_from_read_buf(tty, &kb, &nr)) 2196 - return kb - kbuf; 2197 - } else { 2198 - if (copy_from_read_buf(tty, &kb, &nr)) 2199 - return kb - kbuf; 2200 - } 2201 - 2202 - /* No more data - release locks and stop retries */ 2203 - n_tty_kick_worker(tty); 2204 - n_tty_check_unthrottle(tty); 2205 - up_read(&tty->termios_rwsem); 2206 - mutex_unlock(&ldata->atomic_read_lock); 2207 - *cookie = NULL; 2208 - return kb - kbuf; 2209 - } 2147 + /* Is this a continuation of a read started earlier? */ 2148 + if (*cookie) 2149 + return n_tty_continue_cookie(tty, kbuf, nr, cookie); 2210 2150 2211 2151 retval = job_control(tty, file); 2212 2152 if (retval < 0)