@@ -138,23 +138,23 @@ static inline size_t read_cnt(struct n_tty_data *ldata)
138
138
139
139
static inline unsigned char read_buf (struct n_tty_data * ldata , size_t i )
140
140
{
141
- return ldata -> read_buf [i & ( N_TTY_BUF_SIZE - 1 )];
141
+ return ldata -> read_buf [MASK ( i )];
142
142
}
143
143
144
144
static inline unsigned char * read_buf_addr (struct n_tty_data * ldata , size_t i )
145
145
{
146
- return & ldata -> read_buf [i & ( N_TTY_BUF_SIZE - 1 )];
146
+ return & ldata -> read_buf [MASK ( i )];
147
147
}
148
148
149
149
static inline unsigned char echo_buf (struct n_tty_data * ldata , size_t i )
150
150
{
151
151
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 )];
153
153
}
154
154
155
155
static inline unsigned char * echo_buf_addr (struct n_tty_data * ldata , size_t i )
156
156
{
157
- return & ldata -> echo_buf [i & ( N_TTY_BUF_SIZE - 1 )];
157
+ return & ldata -> echo_buf [MASK ( i )];
158
158
}
159
159
160
160
/* 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,
1359
1359
put_tty_queue (c , ldata );
1360
1360
1361
1361
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 );
1363
1363
put_tty_queue (c , ldata );
1364
1364
smp_store_release (& ldata -> canon_head , ldata -> read_head );
1365
1365
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,
1505
1505
struct n_tty_data * ldata = tty -> disc_data ;
1506
1506
size_t n , head ;
1507
1507
1508
- head = ldata -> read_head & ( N_TTY_BUF_SIZE - 1 );
1508
+ head = MASK ( ldata -> read_head );
1509
1509
n = min_t (size_t , count , N_TTY_BUF_SIZE - head );
1510
1510
memcpy (read_buf_addr (ldata , head ), cp , n );
1511
1511
ldata -> read_head += n ;
1512
1512
cp += n ;
1513
1513
count -= n ;
1514
1514
1515
- head = ldata -> read_head & ( N_TTY_BUF_SIZE - 1 );
1515
+ head = MASK ( ldata -> read_head );
1516
1516
n = min_t (size_t , count , N_TTY_BUF_SIZE - head );
1517
1517
memcpy (read_buf_addr (ldata , head ), cp , n );
1518
1518
ldata -> read_head += n ;
@@ -1779,8 +1779,7 @@ static void n_tty_set_termios(struct tty_struct *tty, const struct ktermios *old
1779
1779
ldata -> canon_head = ldata -> read_tail ;
1780
1780
ldata -> push = 0 ;
1781
1781
} 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 );
1784
1783
ldata -> canon_head = ldata -> read_head ;
1785
1784
ldata -> push = 1 ;
1786
1785
}
@@ -1941,7 +1940,7 @@ static bool copy_from_read_buf(const struct tty_struct *tty,
1941
1940
size_t n ;
1942
1941
bool is_eof ;
1943
1942
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 );
1945
1944
1946
1945
n = min (head - ldata -> read_tail , N_TTY_BUF_SIZE - tail );
1947
1946
n = min (* nr , n );
@@ -2004,7 +2003,7 @@ static bool canon_copy_from_read_buf(const struct tty_struct *tty,
2004
2003
canon_head = smp_load_acquire (& ldata -> canon_head );
2005
2004
n = min (* nr , canon_head - ldata -> read_tail );
2006
2005
2007
- tail = ldata -> read_tail & ( N_TTY_BUF_SIZE - 1 );
2006
+ tail = MASK ( ldata -> read_tail );
2008
2007
size = min_t (size_t , tail + n , N_TTY_BUF_SIZE );
2009
2008
2010
2009
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)
2466
2465
nr = head - tail ;
2467
2466
/* Skip EOF-chars.. */
2468
2467
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 ) &&
2470
2469
read_buf (ldata , tail ) == __DISABLED_CHAR )
2471
2470
nr -- ;
2472
2471
tail ++ ;
0 commit comments