[PATCH v2 02/11] staging: comedi: comedi_buf: cleanup comedi_buf_write_n_available()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



For aesthetic reasons, cleanup this function a bit.

Change the (async == NULL) test to simply (!async).

Add a comment about why the available number of bytes is modified
by the modulus operator (%). Only space for full samples is returned.

Cleanup the multi-line comment about the barrier.

Signed-off-by: H Hartley Sweeten <hsweeten@xxxxxxxxxxxxxxxxxxx>
Cc: Ian Abbott <abbobbi@xxxxxxxxx>
Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
 drivers/staging/comedi/comedi_buf.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/comedi/comedi_buf.c b/drivers/staging/comedi/comedi_buf.c
index fe2dcae..a6b22c5 100644
--- a/drivers/staging/comedi/comedi_buf.c
+++ b/drivers/staging/comedi/comedi_buf.c
@@ -177,17 +177,22 @@ unsigned int comedi_buf_write_n_available(struct comedi_async *async)
 	unsigned int free_end;
 	unsigned int nbytes;
 
-	if (async == NULL)
+	if (!async)
 		return 0;
 
 	free_end = async->buf_read_count + async->prealloc_bufsz;
 	nbytes = free_end - async->buf_write_alloc_count;
+
+	/* don't allow partial samples */
 	nbytes -= nbytes % bytes_per_sample(async->subdevice);
-	/* barrier insures the read of buf_read_count in this
-	   query occurs before any following writes to the buffer which
-	   might be based on the return value from this query.
+
+	/*
+	 * barrier insures the read of buf_read_count above occurs
+	 * before any following writes to the buffer which might
+	 * be based on the return value from this query.
 	 */
 	smp_mb();
+
 	return nbytes;
 }
 
-- 
1.8.0

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/devel


[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux