Skip to content

Commit a84853c

Browse files
Jiri Slaby (SUSE)gregkh
authored andcommitted
tty: n_tty: deduplicate copy code in n_tty_receive_buf_real_raw()
The code is duplicated to perform the copy twice -- to handle buffer wrap-around. Instead of the duplication, roll this into the loop. (And add some blank lines around to have the code a bit more readable.) 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 2aa9185 commit a84853c

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

drivers/tty/n_tty.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,19 +1528,18 @@ n_tty_receive_buf_real_raw(const struct tty_struct *tty, const u8 *cp,
15281528
size_t count)
15291529
{
15301530
struct n_tty_data *ldata = tty->disc_data;
1531-
size_t n, head;
1532-
1533-
head = MASK(ldata->read_head);
1534-
n = min(count, N_TTY_BUF_SIZE - head);
1535-
memcpy(read_buf_addr(ldata, head), cp, n);
1536-
ldata->read_head += n;
1537-
cp += n;
1538-
count -= n;
1539-
1540-
head = MASK(ldata->read_head);
1541-
n = min(count, N_TTY_BUF_SIZE - head);
1542-
memcpy(read_buf_addr(ldata, head), cp, n);
1543-
ldata->read_head += n;
1531+
1532+
/* handle buffer wrap-around by a loop */
1533+
for (unsigned int i = 0; i < 2; i++) {
1534+
size_t head = MASK(ldata->read_head);
1535+
size_t n = min(count, N_TTY_BUF_SIZE - head);
1536+
1537+
memcpy(read_buf_addr(ldata, head), cp, n);
1538+
1539+
ldata->read_head += n;
1540+
cp += n;
1541+
count -= n;
1542+
}
15441543
}
15451544

15461545
static void

0 commit comments

Comments
 (0)