[PATCH 09/18] staging: comedi: comedi_buf: make comedi_buf_read_samples() work for single samples
Ian Abbott
abbotti at mev.co.uk
Wed Oct 22 16:36:22 UTC 2014
On 20/10/14 19:52, H Hartley Sweeten wrote:
> 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.
Even for more than one sample it would be better if
comedi_buf_read_samples() only read a whole number of samples from the
buffer, e.g. by rounding down the value from
comedi_buf_read_n_available(). Then you wouldn't need to treat single
samples as a special case.
>
> Signed-off-by: H Hartley Sweeten <hsweeten at visionengravers.com>
> Cc: Ian Abbott <abbotti at mev.co.uk>
> Cc: Greg Kroah-Hartman <gregkh at linuxfoundation.org>
> ---
> 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);
>
--
-=( Ian Abbott @ MEV Ltd. E-mail: <abbotti at mev.co.uk> )=-
-=( Web: http://www.mev.co.uk/ )=-
More information about the devel
mailing list