From 660ac5590ef48f16a18e936d3252f17f8d1783d7 Mon Sep 17 00:00:00 2001 From: Frank Mori Hess Date: Sun, 14 Apr 2002 02:43:16 +0000 Subject: [PATCH] moved increment of buf_int_count to beginning of comedi_buf_put*() to eliminate race with buffer overrun check. Added setting of COMEDI_CB_BLOCK to comedi_buf_put() so it doesn't need to be set in drivers --- include/linux/comedidev.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/include/linux/comedidev.h b/include/linux/comedidev.h index d59dd372..5c46d172 100644 --- a/include/linux/comedidev.h +++ b/include/linux/comedidev.h @@ -307,6 +307,7 @@ static inline int alloc_private(comedi_device *dev,int size) // writes a data point to comedi's buffer, used for input static inline void comedi_buf_put(comedi_async *async, sampl_t x) { + async->buf_int_count += sizeof(sampl_t); *(sampl_t *)(async->data + async->buf_int_ptr) = x; async->buf_int_ptr += sizeof(sampl_t); if(async->buf_int_ptr >= async->data_len){ @@ -317,11 +318,11 @@ static inline void comedi_buf_put(comedi_async *async, sampl_t x) async->cur_chan = 0; async->events |= COMEDI_CB_EOS; } - async->buf_int_count += sizeof(sampl_t); + async->events |= COMEDI_CB_BLOCK; } /* Writes an array of data points to comedi's buffer, used for input. - * Can be more efficient than comedi_buf_put() */ + * Can be more efficient than putting comedi_buf_put() in a loop. */ static inline void comedi_buf_put_array(comedi_async *async, sampl_t* array, unsigned int length) { unsigned int num_bytes; @@ -329,6 +330,7 @@ static inline void comedi_buf_put_array(comedi_async *async, sampl_t* array, uns while((num_bytes = length * sizeof(sampl_t) - xfer_count)) { + async->buf_int_count += num_bytes; if( async->buf_int_ptr + num_bytes > async->data_len) num_bytes = async->data_len - async->buf_int_ptr; @@ -346,7 +348,6 @@ static inline void comedi_buf_put_array(comedi_async *async, sampl_t* array, uns async->cur_chan %= async->cmd.chanlist_len; async->events |= COMEDI_CB_EOS; } - async->buf_int_count += num_bytes; xfer_count += num_bytes; } async->events |= COMEDI_CB_BLOCK; -- 2.26.2