Skip to content

Commit d1913e3

Browse files
peterhurleygregkh
authored andcommitted
n_tty: Fix type mismatches in receive_buf raw copy
Signed-off-by: Peter Hurley <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 6f9b028 commit d1913e3

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

drivers/tty/n_tty.c

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,24 +1444,27 @@ static void __receive_buf(struct tty_struct *tty, const unsigned char *cp,
14441444
struct n_tty_data *ldata = tty->disc_data;
14451445
const unsigned char *p;
14461446
char *f, flags = TTY_NORMAL;
1447-
int i;
14481447
char buf[64];
14491448

14501449
if (ldata->real_raw) {
1451-
i = min(N_TTY_BUF_SIZE - read_cnt(ldata),
1452-
N_TTY_BUF_SIZE - (ldata->read_head & (N_TTY_BUF_SIZE - 1)));
1453-
i = min(count, i);
1454-
memcpy(read_buf_addr(ldata, ldata->read_head), cp, i);
1455-
ldata->read_head += i;
1456-
cp += i;
1457-
count -= i;
1458-
1459-
i = min(N_TTY_BUF_SIZE - read_cnt(ldata),
1460-
N_TTY_BUF_SIZE - (ldata->read_head & (N_TTY_BUF_SIZE - 1)));
1461-
i = min(count, i);
1462-
memcpy(read_buf_addr(ldata, ldata->read_head), cp, i);
1463-
ldata->read_head += i;
1450+
size_t n, head;
1451+
1452+
head = ldata->read_head & (N_TTY_BUF_SIZE - 1);
1453+
n = N_TTY_BUF_SIZE - max(read_cnt(ldata), head);
1454+
n = min_t(size_t, count, n);
1455+
memcpy(read_buf_addr(ldata, head), cp, n);
1456+
ldata->read_head += n;
1457+
cp += n;
1458+
count -= n;
1459+
1460+
head = ldata->read_head & (N_TTY_BUF_SIZE - 1);
1461+
n = N_TTY_BUF_SIZE - max(read_cnt(ldata), head);
1462+
n = min_t(size_t, count, n);
1463+
memcpy(read_buf_addr(ldata, head), cp, n);
1464+
ldata->read_head += n;
14641465
} else {
1466+
int i;
1467+
14651468
for (i = count, p = cp, f = fp; i; i--, p++) {
14661469
if (f)
14671470
flags = *f++;

0 commit comments

Comments
 (0)