Skip to content

Commit ce74117

Browse files
peterhurleygregkh
authored andcommitted
n_tty: Get read_cnt through accessor
Prepare for replacing read_cnt field with computed value. Signed-off-by: Peter Hurley <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 4753408 commit ce74117

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

drivers/tty/n_tty.c

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ struct n_tty_data {
115115
raw_spinlock_t read_lock;
116116
};
117117

118+
static inline size_t read_cnt(struct n_tty_data *ldata)
119+
{
120+
return ldata->read_cnt;
121+
}
122+
118123
static inline int tty_put_user(struct tty_struct *tty, unsigned char x,
119124
unsigned char __user *ptr)
120125
{
@@ -133,9 +138,9 @@ static int receive_room(struct tty_struct *tty)
133138
/* Multiply read_cnt by 3, since each byte might take up to
134139
* three times as many spaces when PARMRK is set (depending on
135140
* its flags, e.g. parity error). */
136-
left = N_TTY_BUF_SIZE - ldata->read_cnt * 3 - 1;
141+
left = N_TTY_BUF_SIZE - read_cnt(ldata) * 3 - 1;
137142
} else
138-
left = N_TTY_BUF_SIZE - ldata->read_cnt - 1;
143+
left = N_TTY_BUF_SIZE - read_cnt(ldata) - 1;
139144

140145
/*
141146
* If we are doing input canonicalization, and there are no
@@ -180,7 +185,7 @@ static void n_tty_set_room(struct tty_struct *tty)
180185

181186
static void put_tty_queue_nolock(unsigned char c, struct n_tty_data *ldata)
182187
{
183-
if (ldata->read_cnt < N_TTY_BUF_SIZE) {
188+
if (read_cnt(ldata) < N_TTY_BUF_SIZE) {
184189
ldata->read_buf[ldata->read_head] = c;
185190
ldata->read_head = (ldata->read_head + 1) & (N_TTY_BUF_SIZE-1);
186191
ldata->read_cnt++;
@@ -285,7 +290,7 @@ static ssize_t chars_in_buffer(struct tty_struct *tty)
285290

286291
raw_spin_lock_irqsave(&ldata->read_lock, flags);
287292
if (!ldata->icanon) {
288-
n = ldata->read_cnt;
293+
n = read_cnt(ldata);
289294
} else if (ldata->canon_data) {
290295
n = (ldata->canon_head > ldata->read_tail) ?
291296
ldata->canon_head - ldata->read_tail :
@@ -1204,7 +1209,7 @@ static inline void n_tty_receive_char(struct tty_struct *tty, unsigned char c)
12041209
if (!test_bit(c, ldata->process_char_map) || ldata->lnext) {
12051210
ldata->lnext = 0;
12061211
parmrk = (c == (unsigned char) '\377' && I_PARMRK(tty)) ? 1 : 0;
1207-
if (ldata->read_cnt >= (N_TTY_BUF_SIZE - parmrk - 1)) {
1212+
if (read_cnt(ldata) >= (N_TTY_BUF_SIZE - parmrk - 1)) {
12081213
/* beep if no space */
12091214
if (L_ECHO(tty))
12101215
process_output('\a', tty);
@@ -1304,7 +1309,7 @@ static inline void n_tty_receive_char(struct tty_struct *tty, unsigned char c)
13041309
return;
13051310
}
13061311
if (c == '\n') {
1307-
if (ldata->read_cnt >= N_TTY_BUF_SIZE) {
1312+
if (read_cnt(ldata) >= N_TTY_BUF_SIZE) {
13081313
if (L_ECHO(tty))
13091314
process_output('\a', tty);
13101315
return;
@@ -1316,7 +1321,7 @@ static inline void n_tty_receive_char(struct tty_struct *tty, unsigned char c)
13161321
goto handle_newline;
13171322
}
13181323
if (c == EOF_CHAR(tty)) {
1319-
if (ldata->read_cnt >= N_TTY_BUF_SIZE)
1324+
if (read_cnt(ldata) >= N_TTY_BUF_SIZE)
13201325
return;
13211326
if (ldata->canon_head != ldata->read_head)
13221327
set_bit(TTY_PUSH, &tty->flags);
@@ -1327,7 +1332,7 @@ static inline void n_tty_receive_char(struct tty_struct *tty, unsigned char c)
13271332
(c == EOL2_CHAR(tty) && L_IEXTEN(tty))) {
13281333
parmrk = (c == (unsigned char) '\377' && I_PARMRK(tty))
13291334
? 1 : 0;
1330-
if (ldata->read_cnt >= (N_TTY_BUF_SIZE - parmrk)) {
1335+
if (read_cnt(ldata) >= (N_TTY_BUF_SIZE - parmrk)) {
13311336
if (L_ECHO(tty))
13321337
process_output('\a', tty);
13331338
return;
@@ -1364,7 +1369,7 @@ static inline void n_tty_receive_char(struct tty_struct *tty, unsigned char c)
13641369
}
13651370

13661371
parmrk = (c == (unsigned char) '\377' && I_PARMRK(tty)) ? 1 : 0;
1367-
if (ldata->read_cnt >= (N_TTY_BUF_SIZE - parmrk - 1)) {
1372+
if (read_cnt(ldata) >= (N_TTY_BUF_SIZE - parmrk - 1)) {
13681373
/* beep if no space */
13691374
if (L_ECHO(tty))
13701375
process_output('\a', tty);
@@ -1430,7 +1435,7 @@ static void __receive_buf(struct tty_struct *tty, const unsigned char *cp,
14301435

14311436
if (ldata->real_raw) {
14321437
raw_spin_lock_irqsave(&ldata->read_lock, cpuflags);
1433-
i = min(N_TTY_BUF_SIZE - ldata->read_cnt,
1438+
i = min(N_TTY_BUF_SIZE - read_cnt(ldata),
14341439
N_TTY_BUF_SIZE - ldata->read_head);
14351440
i = min(count, i);
14361441
memcpy(ldata->read_buf + ldata->read_head, cp, i);
@@ -1439,7 +1444,7 @@ static void __receive_buf(struct tty_struct *tty, const unsigned char *cp,
14391444
cp += i;
14401445
count -= i;
14411446

1442-
i = min(N_TTY_BUF_SIZE - ldata->read_cnt,
1447+
i = min(N_TTY_BUF_SIZE - read_cnt(ldata),
14431448
N_TTY_BUF_SIZE - ldata->read_head);
14441449
i = min(count, i);
14451450
memcpy(ldata->read_buf + ldata->read_head, cp, i);
@@ -1474,7 +1479,7 @@ static void __receive_buf(struct tty_struct *tty, const unsigned char *cp,
14741479
tty->ops->flush_chars(tty);
14751480
}
14761481

1477-
if ((!ldata->icanon && (ldata->read_cnt >= ldata->minimum_to_wake)) ||
1482+
if ((!ldata->icanon && (read_cnt(ldata) >= ldata->minimum_to_wake)) ||
14781483
L_EXTPROC(tty)) {
14791484
kill_fasync(&tty->fasync, SIGIO, POLL_IN);
14801485
if (waitqueue_active(&tty->read_wait))
@@ -1552,7 +1557,7 @@ static void n_tty_set_termios(struct tty_struct *tty, struct ktermios *old)
15521557
ldata->erasing = 0;
15531558
}
15541559

1555-
if (canon_change && !L_ICANON(tty) && ldata->read_cnt)
1560+
if (canon_change && !L_ICANON(tty) && read_cnt(ldata))
15561561
wake_up_interruptible(&tty->read_wait);
15571562

15581563
ldata->icanon = (L_ICANON(tty) != 0);
@@ -1701,7 +1706,7 @@ static inline int input_available_p(struct tty_struct *tty, int amt)
17011706
if (ldata->icanon && !L_EXTPROC(tty)) {
17021707
if (ldata->canon_data)
17031708
return 1;
1704-
} else if (ldata->read_cnt >= (amt ? amt : 1))
1709+
} else if (read_cnt(ldata) >= (amt ? amt : 1))
17051710
return 1;
17061711

17071712
return 0;
@@ -1737,7 +1742,7 @@ static int copy_from_read_buf(struct tty_struct *tty,
17371742

17381743
retval = 0;
17391744
raw_spin_lock_irqsave(&ldata->read_lock, flags);
1740-
n = min(ldata->read_cnt, N_TTY_BUF_SIZE - ldata->read_tail);
1745+
n = min(read_cnt(ldata), N_TTY_BUF_SIZE - ldata->read_tail);
17411746
n = min(*nr, n);
17421747
raw_spin_unlock_irqrestore(&ldata->read_lock, flags);
17431748
if (n) {
@@ -1751,7 +1756,7 @@ static int copy_from_read_buf(struct tty_struct *tty,
17511756
ldata->read_tail = (ldata->read_tail + n) & (N_TTY_BUF_SIZE-1);
17521757
ldata->read_cnt -= n;
17531758
/* Turn single EOF into zero-length read */
1754-
if (L_EXTPROC(tty) && ldata->icanon && is_eof && !ldata->read_cnt)
1759+
if (L_EXTPROC(tty) && ldata->icanon && is_eof && !read_cnt(ldata))
17551760
n = 0;
17561761
raw_spin_unlock_irqrestore(&ldata->read_lock, flags);
17571762
*b += n;
@@ -1787,7 +1792,7 @@ static int canon_copy_from_read_buf(struct tty_struct *tty,
17871792

17881793
raw_spin_lock_irqsave(&ldata->read_lock, flags);
17891794

1790-
n = min_t(size_t, *nr, ldata->read_cnt);
1795+
n = min(*nr, read_cnt(ldata));
17911796
if (!n) {
17921797
raw_spin_unlock_irqrestore(&ldata->read_lock, flags);
17931798
return 0;
@@ -2253,7 +2258,7 @@ static int n_tty_ioctl(struct tty_struct *tty, struct file *file,
22532258
return put_user(tty_chars_in_buffer(tty), (int __user *) arg);
22542259
case TIOCINQ:
22552260
/* FIXME: Locking */
2256-
retval = ldata->read_cnt;
2261+
retval = read_cnt(ldata);
22572262
if (L_ICANON(tty))
22582263
retval = inq_canon(ldata);
22592264
return put_user(retval, (unsigned int __user *) arg);

0 commit comments

Comments
 (0)