[PATCH 09/18] staging: comedi: comedi_buf: make comedi_buf_read_samples() work for single samples

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



A number of drivers currently use comedi_buf_get() to read single samples
from the the async buffer. This works but the drivers have to handle the
COMEDI_CB_BLOCK and COMEDI_CB_EOS events. Converting those drivers to use
comedi_buf_read_samples() moves the handling of those events into the core.

Add a check to comedi_buf_read_samples() so that the single sample is read
from the buffer only if there is a full sample in the buffer. This allows
comedi_buf_read_samples() to mimic the action of comedi_buf_get() with the
added benifit of handling the events.

Signed-off-by: H Hartley Sweeten <hsweeten@xxxxxxxxxxxxxxxxxxx>
Cc: Ian Abbott <abbotti@xxxxxxxxx>
Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
 drivers/staging/comedi/comedi_buf.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/staging/comedi/comedi_buf.c b/drivers/staging/comedi/comedi_buf.c
index 4cf02cb..6b6143b 100644
--- a/drivers/staging/comedi/comedi_buf.c
+++ b/drivers/staging/comedi/comedi_buf.c
@@ -564,6 +564,7 @@ unsigned int comedi_buf_read_samples(struct comedi_subdevice *s,
 				     void *data, unsigned int nsamples)
 {
 	unsigned long long nbytes = nsamples * bytes_per_sample(s);
+	unsigned int n = comedi_buf_read_n_available(s);
 
 	if (nbytes > s->async->prealloc_bufsz)
 		nbytes = s->async->prealloc_bufsz;
@@ -571,6 +572,10 @@ unsigned int comedi_buf_read_samples(struct comedi_subdevice *s,
 	if (nbytes == 0)
 		return 0;
 
+	/* single sample reads must return a full sample */
+	if (nsamples == 1 && n < nbytes)
+		return 0;
+
 	nbytes = comedi_buf_read_alloc(s, nbytes);
 	comedi_buf_memcpy_from(s, 0, data, nbytes);
 	comedi_buf_read_free(s, nbytes);
-- 
2.0.3

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel




[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux