summaryrefslogtreecommitdiffstats
path: root/drivers/staging/comedi/comedi_buf.c
diff options
context:
space:
mode:
authorH Hartley Sweeten <hsweeten@visionengravers.com>2014-10-30 11:10:50 -0700
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-11-03 16:11:59 -0800
commiteb3a13230b78c3dc580b509e370862c632c90dae (patch)
tree0f336e03d1d67ba81120585e0efa15efb4adaef5 /drivers/staging/comedi/comedi_buf.c
parent2b365fa9d9264faa7ebccf313899d096b228c65a (diff)
downloadop-kernel-dev-eb3a13230b78c3dc580b509e370862c632c90dae.zip
op-kernel-dev-eb3a13230b78c3dc580b509e370862c632c90dae.tar.gz
staging: comedi: comedi_buf: make comedi_buf_write_samples() add samples that fit
This function currently fails if the number of samples to add would overflow the async buffer. Modify it to add the samples that fit so at least some of the sample data is returned to the user. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/staging/comedi/comedi_buf.c')
-rw-r--r--drivers/staging/comedi/comedi_buf.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/drivers/staging/comedi/comedi_buf.c b/drivers/staging/comedi/comedi_buf.c
index 6dd87cb..b43424d 100644
--- a/drivers/staging/comedi/comedi_buf.c
+++ b/drivers/staging/comedi/comedi_buf.c
@@ -484,12 +484,16 @@ unsigned int comedi_buf_write_samples(struct comedi_subdevice *s,
unsigned int max_samples;
unsigned int nbytes;
- /* make sure there is enought room in the buffer for all the samples */
+ /*
+ * Make sure there is enough room in the buffer for all the samples.
+ * If not, clamp the nsamples to the number that will fit, flag the
+ * buffer overrun and add the samples that fit.
+ */
max_samples = comedi_buf_write_n_available(s) / bytes_per_sample(s);
if (nsamples > max_samples) {
dev_warn(s->device->class_dev, "buffer overrun\n");
s->async->events |= COMEDI_CB_OVERFLOW;
- return 0;
+ nsamples = max_samples;
}
if (nsamples == 0)
OpenPOWER on IntegriCloud