]> git.karo-electronics.de Git - linux-beck.git/commitdiff
staging: comedi: comedi_buf: clarify comedi_buf_read_alloc()
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Wed, 9 Jan 2013 20:30:49 +0000 (13:30 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 18 Jan 2013 00:53:59 +0000 (16:53 -0800)
Clarify the check to make sure the number of bytes to allocate is
available.

Reword the comment about the need for the smp_rmb().

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/comedi_buf.c

index 06dd544ec2c54b8c9c8509db5ce60c2138797941..971f7394a1f0b978b66bc2782cbe1d2327a6e703 100644 (file)
@@ -291,14 +291,20 @@ EXPORT_SYMBOL(comedi_buf_read_n_available);
 /* allocates a chunk for the reader from filled (and munged) buffer space */
 unsigned comedi_buf_read_alloc(struct comedi_async *async, unsigned nbytes)
 {
-       if ((int)(async->buf_read_alloc_count + nbytes - async->munge_count) >
-           0) {
-               nbytes = async->munge_count - async->buf_read_alloc_count;
-       }
+       unsigned int available;
+
+       available = async->munge_count - async->buf_read_alloc_count;
+       if (nbytes > available)
+               nbytes = available;
+
        async->buf_read_alloc_count += nbytes;
-       /* barrier insures read of munge_count occurs before we actually read
-          data out of buffer */
+
+       /*
+        * ensure the async buffer 'counts' are read before we
+        * attempt to read data from the read-alloc'ed buffer space
+        */
        smp_rmb();
+
        return nbytes;
 }
 EXPORT_SYMBOL(comedi_buf_read_alloc);