[PATCH 10/11] staging: comedi: comedi_buf: clarify __comedi_buf_write_alloc()

H Hartley Sweeten hsweeten at visionengravers.com
Fri Dec 21 16:42:49 UTC 2012


Clarify the check to make sure the number of bytes to allocate is
available.

Signed-off-by: H Hartley Sweeten <hsweeten at visionengravers.com>
Cc: Ian Abbott <abbobbi at mev.co.uk>
Cc: Greg Kroah-Hartman <gregkh at linuxfoundation.org>
---
 drivers/staging/comedi/comedi_buf.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/comedi/comedi_buf.c b/drivers/staging/comedi/comedi_buf.c
index 1ec5aaa..5be9930 100644
--- a/drivers/staging/comedi/comedi_buf.c
+++ b/drivers/staging/comedi/comedi_buf.c
@@ -182,13 +182,10 @@ static unsigned int __comedi_buf_write_alloc(struct comedi_async *async,
 					     int strict)
 {
 	unsigned int free_end = async->buf_read_count + async->prealloc_bufsz;
+	int available = free_end - async->buf_write_alloc_count;
 
-	if ((int)(async->buf_write_alloc_count + nbytes - free_end) > 0) {
-		if (strict)
-			nbytes = 0;
-		else
-			nbytes = free_end - async->buf_write_alloc_count;
-	}
+	if (nbytes > available)
+		nbytes = strict ? 0 : available;
 
 	async->buf_write_alloc_count += nbytes;
 	/* barrier insures the read of buf_read_count above occurs before
-- 
1.8.0




More information about the devel mailing list