Skip to content

Commit 819287f

Browse files
Jiri Slaby (SUSE)gregkh
authored andcommitted
tty: n_tty: use MASK() for masking out size bits
In n_tty, there is already a macro to mask out top bits from ring buffer counters. It is MASK() added some time ago. So use it more in the code to make it 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 c3b2b26 commit 819287f

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

drivers/tty/n_tty.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -138,23 +138,23 @@ static inline size_t read_cnt(struct n_tty_data *ldata)
138138

139139
static inline unsigned char read_buf(struct n_tty_data *ldata, size_t i)
140140
{
141-
return ldata->read_buf[i & (N_TTY_BUF_SIZE - 1)];
141+
return ldata->read_buf[MASK(i)];
142142
}
143143

144144
static inline unsigned char *read_buf_addr(struct n_tty_data *ldata, size_t i)
145145
{
146-
return &ldata->read_buf[i & (N_TTY_BUF_SIZE - 1)];
146+
return &ldata->read_buf[MASK(i)];
147147
}
148148

149149
static inline unsigned char echo_buf(struct n_tty_data *ldata, size_t i)
150150
{
151151
smp_rmb(); /* Matches smp_wmb() in add_echo_byte(). */
152-
return ldata->echo_buf[i & (N_TTY_BUF_SIZE - 1)];
152+
return ldata->echo_buf[MASK(i)];
153153
}
154154

155155
static inline unsigned char *echo_buf_addr(struct n_tty_data *ldata, size_t i)
156156
{
157-
return &ldata->echo_buf[i & (N_TTY_BUF_SIZE - 1)];
157+
return &ldata->echo_buf[MASK(i)];
158158
}
159159

160160
/* If we are not echoing the data, perhaps this is a secret so erase it */
@@ -1359,7 +1359,7 @@ static void n_tty_receive_char_special(struct tty_struct *tty, unsigned char c,
13591359
put_tty_queue(c, ldata);
13601360

13611361
handle_newline:
1362-
set_bit(ldata->read_head & (N_TTY_BUF_SIZE - 1), ldata->read_flags);
1362+
set_bit(MASK(ldata->read_head), ldata->read_flags);
13631363
put_tty_queue(c, ldata);
13641364
smp_store_release(&ldata->canon_head, ldata->read_head);
13651365
kill_fasync(&tty->fasync, SIGIO, POLL_IN);
@@ -1505,14 +1505,14 @@ n_tty_receive_buf_real_raw(const struct tty_struct *tty, const u8 *cp,
15051505
struct n_tty_data *ldata = tty->disc_data;
15061506
size_t n, head;
15071507

1508-
head = ldata->read_head & (N_TTY_BUF_SIZE - 1);
1508+
head = MASK(ldata->read_head);
15091509
n = min_t(size_t, count, N_TTY_BUF_SIZE - head);
15101510
memcpy(read_buf_addr(ldata, head), cp, n);
15111511
ldata->read_head += n;
15121512
cp += n;
15131513
count -= n;
15141514

1515-
head = ldata->read_head & (N_TTY_BUF_SIZE - 1);
1515+
head = MASK(ldata->read_head);
15161516
n = min_t(size_t, count, N_TTY_BUF_SIZE - head);
15171517
memcpy(read_buf_addr(ldata, head), cp, n);
15181518
ldata->read_head += n;
@@ -1779,8 +1779,7 @@ static void n_tty_set_termios(struct tty_struct *tty, const struct ktermios *old
17791779
ldata->canon_head = ldata->read_tail;
17801780
ldata->push = 0;
17811781
} else {
1782-
set_bit((ldata->read_head - 1) & (N_TTY_BUF_SIZE - 1),
1783-
ldata->read_flags);
1782+
set_bit(MASK(ldata->read_head - 1), ldata->read_flags);
17841783
ldata->canon_head = ldata->read_head;
17851784
ldata->push = 1;
17861785
}
@@ -1941,7 +1940,7 @@ static bool copy_from_read_buf(const struct tty_struct *tty,
19411940
size_t n;
19421941
bool is_eof;
19431942
size_t head = smp_load_acquire(&ldata->commit_head);
1944-
size_t tail = ldata->read_tail & (N_TTY_BUF_SIZE - 1);
1943+
size_t tail = MASK(ldata->read_tail);
19451944

19461945
n = min(head - ldata->read_tail, N_TTY_BUF_SIZE - tail);
19471946
n = min(*nr, n);
@@ -2004,7 +2003,7 @@ static bool canon_copy_from_read_buf(const struct tty_struct *tty,
20042003
canon_head = smp_load_acquire(&ldata->canon_head);
20052004
n = min(*nr, canon_head - ldata->read_tail);
20062005

2007-
tail = ldata->read_tail & (N_TTY_BUF_SIZE - 1);
2006+
tail = MASK(ldata->read_tail);
20082007
size = min_t(size_t, tail + n, N_TTY_BUF_SIZE);
20092008

20102009
n_tty_trace("%s: nr:%zu tail:%zu n:%zu size:%zu\n",
@@ -2466,7 +2465,7 @@ static unsigned long inq_canon(struct n_tty_data *ldata)
24662465
nr = head - tail;
24672466
/* Skip EOF-chars.. */
24682467
while (MASK(head) != MASK(tail)) {
2469-
if (test_bit(tail & (N_TTY_BUF_SIZE - 1), ldata->read_flags) &&
2468+
if (test_bit(MASK(tail), ldata->read_flags) &&
24702469
read_buf(ldata, tail) == __DISABLED_CHAR)
24712470
nr--;
24722471
tail++;

0 commit comments

Comments
 (0)