Skip to content

Commit c2b0fb9

Browse files
Jiri Slaby (SUSE)gregkh
authored andcommitted
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)" <[email protected]> Reviewed-by: Ilpo Järvinen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 72369f2 commit c2b0fb9

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

drivers/tty/n_tty.c

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1966,24 +1966,26 @@ static bool copy_from_read_buf(const struct tty_struct *tty, u8 **kbp,
19661966
size_t tail = MASK(ldata->read_tail);
19671967

19681968
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;
1982-
1983-
/* If we have more to copy, let the caller know */
1984-
return head != ldata->read_tail;
1985-
}
1986-
return false;
1969+
if (!n)
1970+
return false;
1971+
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;
19871989
}
19881990

19891991
/**

0 commit comments

Comments
 (0)