return count;
 }
 
-unsigned int comedi_buf_write_n_allocated(struct comedi_async *async)
+unsigned int comedi_buf_write_n_allocated(struct comedi_subdevice *s)
 {
+       struct comedi_async *async = s->async;
+
        return async->buf_write_alloc_count - async->buf_write_count;
 }
 
                                   unsigned int nbytes)
 {
        struct comedi_async *async = s->async;
-       unsigned int allocated = comedi_buf_write_n_allocated(async);
+       unsigned int allocated = comedi_buf_write_n_allocated(s);
 
        if (nbytes > allocated)
                nbytes = allocated;
 
                poll_wait(file, &s->async->wait_head, wait);
                comedi_buf_write_alloc(s, s->async->prealloc_bufsz);
                if (!s->busy || !comedi_is_subdevice_running(s) ||
-                   comedi_buf_write_n_allocated(s->async) >= bps)
+                   comedi_buf_write_n_allocated(s) >= bps)
                        mask |= POLLOUT | POLLWRNORM;
        }
 
                if (async->buf_write_ptr + m > async->prealloc_bufsz)
                        m = async->prealloc_bufsz - async->buf_write_ptr;
                comedi_buf_write_alloc(s, async->prealloc_bufsz);
-               if (m > comedi_buf_write_n_allocated(async))
-                       m = comedi_buf_write_n_allocated(async);
+               if (m > comedi_buf_write_n_allocated(s))
+                       m = comedi_buf_write_n_allocated(s);
                if (m < n)
                        n = m;
 
 
 int comedi_buf_map_put(struct comedi_buf_map *bm);
 struct comedi_buf_map *comedi_buf_map_from_subdev_get(
                struct comedi_subdevice *s);
-unsigned int comedi_buf_write_n_allocated(struct comedi_async *async);
+unsigned int comedi_buf_write_n_allocated(struct comedi_subdevice *s);
 void comedi_device_cancel_all(struct comedi_device *dev);
 
 extern unsigned int comedi_default_buf_size_kb;