diff options
author | Peter Hurley <peter@hurleysoftware.com> | 2013-06-15 10:21:22 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-07-23 20:10:17 -0400 |
commit | 4a23a4df500f29603ee25995f9c1d3af79f7a994 (patch) | |
tree | e76ff6ddbfa85712336c471758d53c795e245d3d /drivers/tty/n_tty.c | |
parent | 781ad1c79379c723138945b633121a78e9e5485f (diff) |
n_tty: Factor 'real raw' receive_buf into standalone fn
Convert to modal receive_buf() processing; factor real_raw
receive_buf() into n_tty_receive_buf_real_raw().
Signed-off-by: Peter Hurley <peter@hurleysoftware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/tty/n_tty.c')
-rw-r--r-- | drivers/tty/n_tty.c | 51 |
1 files changed, 30 insertions, 21 deletions
diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c index 4f20bec011fb..f763f75b672b 100644 --- a/drivers/tty/n_tty.c +++ b/drivers/tty/n_tty.c | |||
@@ -242,7 +242,7 @@ static void n_tty_write_wakeup(struct tty_struct *tty) | |||
242 | kill_fasync(&tty->fasync, SIGIO, POLL_OUT); | 242 | kill_fasync(&tty->fasync, SIGIO, POLL_OUT); |
243 | } | 243 | } |
244 | 244 | ||
245 | static inline void n_tty_check_throttle(struct tty_struct *tty) | 245 | static void n_tty_check_throttle(struct tty_struct *tty) |
246 | { | 246 | { |
247 | if (tty->driver->type == TTY_DRIVER_TYPE_PTY) | 247 | if (tty->driver->type == TTY_DRIVER_TYPE_PTY) |
248 | return; | 248 | return; |
@@ -1481,6 +1481,28 @@ handle_newline: | |||
1481 | * publishes read_head and canon_head | 1481 | * publishes read_head and canon_head |
1482 | */ | 1482 | */ |
1483 | 1483 | ||
1484 | static void | ||
1485 | n_tty_receive_buf_real_raw(struct tty_struct *tty, const unsigned char *cp, | ||
1486 | char *fp, int count) | ||
1487 | { | ||
1488 | struct n_tty_data *ldata = tty->disc_data; | ||
1489 | size_t n, head; | ||
1490 | |||
1491 | head = ldata->read_head & (N_TTY_BUF_SIZE - 1); | ||
1492 | n = N_TTY_BUF_SIZE - max(read_cnt(ldata), head); | ||
1493 | n = min_t(size_t, count, n); | ||
1494 | memcpy(read_buf_addr(ldata, head), cp, n); | ||
1495 | ldata->read_head += n; | ||
1496 | cp += n; | ||
1497 | count -= n; | ||
1498 | |||
1499 | head = ldata->read_head & (N_TTY_BUF_SIZE - 1); | ||
1500 | n = N_TTY_BUF_SIZE - max(read_cnt(ldata), head); | ||
1501 | n = min_t(size_t, count, n); | ||
1502 | memcpy(read_buf_addr(ldata, head), cp, n); | ||
1503 | ldata->read_head += n; | ||
1504 | } | ||
1505 | |||
1484 | static void __receive_buf(struct tty_struct *tty, const unsigned char *cp, | 1506 | static void __receive_buf(struct tty_struct *tty, const unsigned char *cp, |
1485 | char *fp, int count) | 1507 | char *fp, int count) |
1486 | { | 1508 | { |
@@ -1488,23 +1510,9 @@ static void __receive_buf(struct tty_struct *tty, const unsigned char *cp, | |||
1488 | char flags = TTY_NORMAL; | 1510 | char flags = TTY_NORMAL; |
1489 | char buf[64]; | 1511 | char buf[64]; |
1490 | 1512 | ||
1491 | if (ldata->real_raw) { | 1513 | if (ldata->real_raw) |
1492 | size_t n, head; | 1514 | n_tty_receive_buf_real_raw(tty, cp, fp, count); |
1493 | 1515 | else { | |
1494 | head = ldata->read_head & (N_TTY_BUF_SIZE - 1); | ||
1495 | n = N_TTY_BUF_SIZE - max(read_cnt(ldata), head); | ||
1496 | n = min_t(size_t, count, n); | ||
1497 | memcpy(read_buf_addr(ldata, head), cp, n); | ||
1498 | ldata->read_head += n; | ||
1499 | cp += n; | ||
1500 | count -= n; | ||
1501 | |||
1502 | head = ldata->read_head & (N_TTY_BUF_SIZE - 1); | ||
1503 | n = N_TTY_BUF_SIZE - max(read_cnt(ldata), head); | ||
1504 | n = min_t(size_t, count, n); | ||
1505 | memcpy(read_buf_addr(ldata, head), cp, n); | ||
1506 | ldata->read_head += n; | ||
1507 | } else { | ||
1508 | while (count--) { | 1516 | while (count--) { |
1509 | if (fp) | 1517 | if (fp) |
1510 | flags = *fp++; | 1518 | flags = *fp++; |
@@ -1540,8 +1548,6 @@ static void __receive_buf(struct tty_struct *tty, const unsigned char *cp, | |||
1540 | if (waitqueue_active(&tty->read_wait)) | 1548 | if (waitqueue_active(&tty->read_wait)) |
1541 | wake_up_interruptible(&tty->read_wait); | 1549 | wake_up_interruptible(&tty->read_wait); |
1542 | } | 1550 | } |
1543 | |||
1544 | n_tty_check_throttle(tty); | ||
1545 | } | 1551 | } |
1546 | 1552 | ||
1547 | static void n_tty_receive_buf(struct tty_struct *tty, const unsigned char *cp, | 1553 | static void n_tty_receive_buf(struct tty_struct *tty, const unsigned char *cp, |
@@ -1549,6 +1555,7 @@ static void n_tty_receive_buf(struct tty_struct *tty, const unsigned char *cp, | |||
1549 | { | 1555 | { |
1550 | down_read(&tty->termios_rwsem); | 1556 | down_read(&tty->termios_rwsem); |
1551 | __receive_buf(tty, cp, fp, count); | 1557 | __receive_buf(tty, cp, fp, count); |
1558 | n_tty_check_throttle(tty); | ||
1552 | up_read(&tty->termios_rwsem); | 1559 | up_read(&tty->termios_rwsem); |
1553 | } | 1560 | } |
1554 | 1561 | ||
@@ -1564,8 +1571,10 @@ static int n_tty_receive_buf2(struct tty_struct *tty, const unsigned char *cp, | |||
1564 | if (!room) | 1571 | if (!room) |
1565 | ldata->no_room = 1; | 1572 | ldata->no_room = 1; |
1566 | count = min(count, room); | 1573 | count = min(count, room); |
1567 | if (count) | 1574 | if (count) { |
1568 | __receive_buf(tty, cp, fp, count); | 1575 | __receive_buf(tty, cp, fp, count); |
1576 | n_tty_check_throttle(tty); | ||
1577 | } | ||
1569 | 1578 | ||
1570 | up_read(&tty->termios_rwsem); | 1579 | up_read(&tty->termios_rwsem); |
1571 | 1580 | ||