Skip to content

Commit aa1ebc9

Browse files
Jiri Slaby (SUSE)gregkh
authored andcommitted
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) <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 67e781f commit aa1ebc9

File tree

1 file changed

+36
-30
lines changed

1 file changed

+36
-30
lines changed

drivers/tty/n_tty.c

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2111,6 +2111,39 @@ static int job_control(struct tty_struct *tty, struct file *file)
21112111
return __tty_check_change(tty, SIGTTIN);
21122112
}
21132113

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+
}
21142147

21152148
/**
21162149
* n_tty_read - read function for tty
@@ -2144,36 +2177,9 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file, u8 *kbuf,
21442177
bool packet;
21452178
size_t old_tail;
21462179

2147-
/*
2148-
* Is this a continuation of a read started earler?
2149-
*
2150-
* If so, we still hold the atomic_read_lock and the
2151-
* termios_rwsem, and can just continue to copy data.
2152-
*/
2153-
if (*cookie) {
2154-
if (ldata->icanon && !L_EXTPROC(tty)) {
2155-
/*
2156-
* If we have filled the user buffer, see
2157-
* if we should skip an EOF character before
2158-
* releasing the lock and returning done.
2159-
*/
2160-
if (!nr)
2161-
canon_skip_eof(ldata);
2162-
else if (canon_copy_from_read_buf(tty, &kb, &nr))
2163-
return kb - kbuf;
2164-
} else {
2165-
if (copy_from_read_buf(tty, &kb, &nr))
2166-
return kb - kbuf;
2167-
}
2168-
2169-
/* No more data - release locks and stop retries */
2170-
n_tty_kick_worker(tty);
2171-
n_tty_check_unthrottle(tty);
2172-
up_read(&tty->termios_rwsem);
2173-
mutex_unlock(&ldata->atomic_read_lock);
2174-
*cookie = NULL;
2175-
return kb - kbuf;
2176-
}
2180+
/* Is this a continuation of a read started earlier? */
2181+
if (*cookie)
2182+
return n_tty_continue_cookie(tty, kbuf, nr, cookie);
21772183

21782184
retval = job_control(tty, file);
21792185
if (retval < 0)

0 commit comments

Comments
 (0)