mirror of
https://github.com/lkl/linux.git
synced 2025-12-19 16:13:19 +09:00
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)" <jirislaby@kernel.org> Link: https://lore.kernel.org/r/20230827074147.2287-15-jirislaby@kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
2aa91851ff
commit
a84853c595
@@ -1528,19 +1528,18 @@ n_tty_receive_buf_real_raw(const struct tty_struct *tty, const u8 *cp,
|
|||||||
size_t count)
|
size_t count)
|
||||||
{
|
{
|
||||||
struct n_tty_data *ldata = tty->disc_data;
|
struct n_tty_data *ldata = tty->disc_data;
|
||||||
size_t n, head;
|
|
||||||
|
|
||||||
head = MASK(ldata->read_head);
|
/* handle buffer wrap-around by a loop */
|
||||||
n = min(count, N_TTY_BUF_SIZE - head);
|
for (unsigned int i = 0; i < 2; i++) {
|
||||||
|
size_t head = MASK(ldata->read_head);
|
||||||
|
size_t n = min(count, N_TTY_BUF_SIZE - head);
|
||||||
|
|
||||||
memcpy(read_buf_addr(ldata, head), cp, n);
|
memcpy(read_buf_addr(ldata, head), cp, n);
|
||||||
|
|
||||||
ldata->read_head += n;
|
ldata->read_head += n;
|
||||||
cp += n;
|
cp += n;
|
||||||
count -= n;
|
count -= n;
|
||||||
|
}
|
||||||
head = MASK(ldata->read_head);
|
|
||||||
n = min(count, N_TTY_BUF_SIZE - head);
|
|
||||||
memcpy(read_buf_addr(ldata, head), cp, n);
|
|
||||||
ldata->read_head += n;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
Reference in New Issue
Block a user