[PATCH v2 09/18] staging: comedi: comedi_buf: make comedi_buf_read_samples() always return full 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.

Modify comedi_buf_read_samples() so that the async buffer is checked for
the number of full samples available. Use that to clamp the number of
samples that will be read. This makes sure that only full samples are
read from the async buffer making comedi_buf_read_samples() 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 | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/comedi/comedi_buf.c b/drivers/staging/comedi/comedi_buf.c
index 9074da2..fb2e91a 100644
--- a/drivers/staging/comedi/comedi_buf.c
+++ b/drivers/staging/comedi/comedi_buf.c
@@ -566,15 +566,15 @@ unsigned int comedi_buf_read_samples(struct comedi_subdevice *s,
 	unsigned int max_samples;
 	unsigned int nbytes;
 
-	max_samples = s->async->prealloc_bufsz / bytes_per_sample(s);
+	/* clamp nsamples to the number of full samples available */
+	max_samples = comedi_buf_read_n_available(s) / bytes_per_sample(s);
 	if (nsamples > max_samples)
 		nsamples = max_samples;
 
-	nbytes = nsamples * bytes_per_sample(s);
-	if (nbytes == 0)
+	if (nsamples == 0)
 		return 0;
 
-	nbytes = comedi_buf_read_alloc(s, nbytes);
+	nbytes = comedi_buf_read_alloc(s, nsamples * bytes_per_sample(s));
 	comedi_buf_memcpy_from(s, 0, data, nbytes);
 	comedi_buf_read_free(s, nbytes);
 	comedi_inc_scan_progress(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