aboutsummaryrefslogtreecommitdiff
path: root/drivers/staging/comedi/comedi_buf.c
diff options
context:
space:
mode:
authorH Hartley Sweeten <hsweeten@visionengravers.com>2013-01-09 13:30:49 -0700
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-01-17 16:53:59 -0800
commit034cbd17922a8b6c64b227360314167c15c1f031 (patch)
tree91011a131484a8f13653f825801dc803d9b0451f /drivers/staging/comedi/comedi_buf.c
parent43f9137df461f6365f76b46f404fd6775eab7d51 (diff)
staging: comedi: comedi_buf: clarify comedi_buf_read_alloc()
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>
Diffstat (limited to 'drivers/staging/comedi/comedi_buf.c')
-rw-r--r--drivers/staging/comedi/comedi_buf.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/drivers/staging/comedi/comedi_buf.c b/drivers/staging/comedi/comedi_buf.c
index 06dd544ec2c..971f7394a1f 100644
--- a/drivers/staging/comedi/comedi_buf.c
+++ b/drivers/staging/comedi/comedi_buf.c
@@ -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);