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: invert the condition in copy_from_read_buf()

Make "no numbers available" a fast quit from the function. And do the
heavy work outside the 'if'. This makes the code more understandable and
conforming to the common kernel coding style.

Signed-off-by: "Jiri Slaby (SUSE)" <jirislaby@kernel.org>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Link: https://lore.kernel.org/r/20230919085156.1578-5-jirislaby@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Jiri Slaby (SUSE) and committed by
Greg Kroah-Hartman
c2b0fb9f 72369f2d

+19 -17
+19 -17
drivers/tty/n_tty.c
··· 1966 1966 size_t tail = MASK(ldata->read_tail); 1967 1967 1968 1968 n = min3(head - ldata->read_tail, N_TTY_BUF_SIZE - tail, *nr); 1969 - if (n) { 1970 - u8 *from = read_buf_addr(ldata, tail); 1971 - memcpy(*kbp, from, n); 1972 - is_eof = n == 1 && *from == EOF_CHAR(tty); 1973 - tty_audit_add_data(tty, from, n); 1974 - zero_buffer(tty, from, n); 1975 - smp_store_release(&ldata->read_tail, ldata->read_tail + n); 1976 - /* Turn single EOF into zero-length read */ 1977 - if (L_EXTPROC(tty) && ldata->icanon && is_eof && 1978 - (head == ldata->read_tail)) 1979 - return false; 1980 - *kbp += n; 1981 - *nr -= n; 1969 + if (!n) 1970 + return false; 1982 1971 1983 - /* If we have more to copy, let the caller know */ 1984 - return head != ldata->read_tail; 1985 - } 1986 - return false; 1972 + u8 *from = read_buf_addr(ldata, tail); 1973 + memcpy(*kbp, from, n); 1974 + is_eof = n == 1 && *from == EOF_CHAR(tty); 1975 + tty_audit_add_data(tty, from, n); 1976 + zero_buffer(tty, from, n); 1977 + smp_store_release(&ldata->read_tail, ldata->read_tail + n); 1978 + 1979 + /* Turn single EOF into zero-length read */ 1980 + if (L_EXTPROC(tty) && ldata->icanon && is_eof && 1981 + head == ldata->read_tail) 1982 + return false; 1983 + 1984 + *kbp += n; 1985 + *nr -= n; 1986 + 1987 + /* If we have more to copy, let the caller know */ 1988 + return head != ldata->read_tail; 1987 1989 } 1988 1990 1989 1991 /**