aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/tty/n_tty.c
diff options
context:
space:
mode:
authorChristian Riesch <christian.riesch@omicron.at>2014-11-12 23:53:26 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-11-26 22:35:48 -0500
commit8bfbe2de769afda051c56aba5450391670e769fc (patch)
treeb15c341998358b3a8df969d8240e7874980d86d8 /drivers/tty/n_tty.c
parent8ad3b1352693972b737607c7b9c89b56d45fea9b (diff)
n_tty: Fix read_buf race condition, increment read_head after pushing data
Commit 19e2ad6a09f0c06dbca19c98e5f4584269d913dd ("n_tty: Remove overflow tests from receive_buf() path") moved the increment of read_head into the arguments list of read_buf_addr(). Function calls represent a sequence point in C. Therefore read_head is incremented before the character c is placed in the buffer. Since the circular read buffer is a lock-less design since commit 6d76bd2618535c581f1673047b8341fd291abc67 ("n_tty: Make N_TTY ldisc receive path lockless"), this creates a race condition that leads to communication errors. This patch modifies the code to increment read_head _after_ the data is placed in the buffer and thus fixes the race for non-SMP machines. To fix the problem for SMP machines, memory barriers must be added in a separate patch. Signed-off-by: Christian Riesch <christian.riesch@omicron.at> Cc: <stable@vger.kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/tty/n_tty.c')
-rw-r--r--drivers/tty/n_tty.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index 8358daa865e5..9e3b21624c82 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -321,7 +321,8 @@ static void n_tty_check_unthrottle(struct tty_struct *tty)
321 321
322static inline void put_tty_queue(unsigned char c, struct n_tty_data *ldata) 322static inline void put_tty_queue(unsigned char c, struct n_tty_data *ldata)
323{ 323{
324 *read_buf_addr(ldata, ldata->read_head++) = c; 324 *read_buf_addr(ldata, ldata->read_head) = c;
325 ldata->read_head++;
325} 326}
326 327
327/** 328/**