From 6454971074c08e5c643107e6aca493ce08f6f3bf Mon Sep 17 00:00:00 2001 From: Frank Mori Hess Date: Sun, 14 Apr 2002 15:46:36 +0000 Subject: [PATCH] calculate max number of bytes that can be read or written by using buf_int_ptr and buf_user_ptr to avoid any possible race with comedi_buf_put*(). --- comedi/comedi_fops.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/comedi/comedi_fops.c b/comedi/comedi_fops.c index da95d598..1bf594c5 100644 --- a/comedi/comedi_fops.c +++ b/comedi/comedi_fops.c @@ -1349,11 +1349,10 @@ static ssize_t comedi_write_v22(struct file *file,const char *buf,size_t nbytes, n=nbytes; - m=async->data_len+async->buf_int_count-async->buf_user_count; - - if(async->buf_user_ptr+m > async->data_len){ - m=async->data_len - async->buf_user_ptr; - } + if( async->buf_user_ptr < async->buf_int_ptr) + m = async->buf_int_ptr - async->buf_user_ptr; + else + m = async->data_len - async->buf_user_count; if(mbuf_int_count-async->buf_user_count; + if(async->buf_int_ptr >= async->buf_user_ptr) + m = async->buf_int_ptr - async->buf_user_ptr; + else + m = async->data_len - async->buf_user_ptr; - if(async->buf_user_ptr+m > async->data_len){ - m=async->data_len - async->buf_user_ptr; #if 0 printk("m is %d\n",m); #endif - } if(m