Be more careful about using all the write-allocated buffer space
authorFrank Mori Hess <fmhess@speakeasy.net>
Tue, 1 May 2007 20:16:51 +0000 (20:16 +0000)
committerFrank Mori Hess <fmhess@speakeasy.net>
Tue, 1 May 2007 20:16:51 +0000 (20:16 +0000)
available, in the cases where it was allocated previously but
never used.

comedi/comedi_fops.c
include/linux/comedidev.h

index cdea1bf0120a3cde950c867acb9adc28069b25db..c54b8ba1e7195ce61145cd37f86aef89f5b4d544 100644 (file)
@@ -1394,7 +1394,6 @@ static ssize_t comedi_write(struct file *file,const char *buf,size_t nbytes,loff
 
        if(s->busy != file)
                return -EACCES;
-
        add_wait_queue(&dev->write_wait,&wait);
        while(nbytes>0 && !retval){
                current->state=TASK_INTERRUPTIBLE;
@@ -1405,7 +1404,9 @@ static ssize_t comedi_write(struct file *file,const char *buf,size_t nbytes,loff
                if(async->buf_write_ptr + m > async->prealloc_bufsz){
                        m = async->prealloc_bufsz - async->buf_write_ptr;
                }
-               m = comedi_buf_write_alloc(async, m);
+               comedi_buf_write_alloc(async, async->prealloc_bufsz);
+               if(m > comedi_buf_write_n_allocated(async))
+                       m = comedi_buf_write_n_allocated(async);
 
                if(m < n) n = m;
 
@@ -1828,7 +1829,7 @@ void comedi_event(comedi_device *dev,comedi_subdevice *s, unsigned int mask)
        mask = s->async->events;
        s->async->events = 0;
 
-       //DPRINTK("comedi_event %x\n",mask);
+       //DPRINTK("comedi_event 0x%x\n",mask);
 
        if( (s->subdev_flags & SDF_RUNNING) == 0)
                return;
index eb1f6205e559acb9731562f21996618b9ed23d9d..b28fe3220a0043aefb6176d59fa0c460795637c2 100644 (file)
@@ -447,6 +447,14 @@ void comedi_buf_memcpy_to( comedi_async *async, unsigned int offset, const void
        unsigned int num_bytes );
 void comedi_buf_memcpy_from( comedi_async *async, unsigned int offset, void *destination,
        unsigned int num_bytes );
+static inline unsigned comedi_buf_write_n_allocated(comedi_async *async)
+{
+       return async->buf_write_alloc_count - async->buf_write_count;
+}
+static inline unsigned comedi_buf_read_n_allocated(comedi_async *async)
+{
+       return async->buf_read_alloc_count - async->buf_read_count;
+}
 
 void comedi_reset_async_buf(comedi_async *async);