提交 eb3a1323 编写于 作者: H H Hartley Sweeten 提交者: Greg Kroah-Hartman

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: NH Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: NIan Abbott <abbotti@mev.co.uk>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
上级 2b365fa9
...@@ -484,12 +484,16 @@ unsigned int comedi_buf_write_samples(struct comedi_subdevice *s, ...@@ -484,12 +484,16 @@ unsigned int comedi_buf_write_samples(struct comedi_subdevice *s,
unsigned int max_samples; unsigned int max_samples;
unsigned int nbytes; 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); max_samples = comedi_buf_write_n_available(s) / bytes_per_sample(s);
if (nsamples > max_samples) { if (nsamples > max_samples) {
dev_warn(s->device->class_dev, "buffer overrun\n"); dev_warn(s->device->class_dev, "buffer overrun\n");
s->async->events |= COMEDI_CB_OVERFLOW; s->async->events |= COMEDI_CB_OVERFLOW;
return 0; nsamples = max_samples;
} }
if (nsamples == 0) if (nsamples == 0)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册