Re: [PATCH 09/11] staging: comedi: comedi_buf: clarify comedi_buf_read_alloc()

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

 



On 02/01/2013 18:10, H Hartley Sweeten wrote:
On Wednesday, January 02, 2013 6:52 AM, Ian Abbott wrote:
On 2012-12-21 16:42, H Hartley Sweeten wrote:
Clarify the check to make sure the number of bytes to allocate is
available.

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 | 8 ++++----
   1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/comedi/comedi_buf.c b/drivers/staging/comedi/comedi_buf.c
index 246f577..1ec5aaa 100644
--- a/drivers/staging/comedi/comedi_buf.c
+++ b/drivers/staging/comedi/comedi_buf.c
@@ -298,10 +298,10 @@ 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;
-	}
+	int available = async->munge_count - async->buf_read_alloc_count;

Minor nit-pick: that should be an unsigned int.

Will the munge_count always be larger, or equal, to the buf_read_alloc_count?
The original code had the (int) cast so I wasn't sure. If so, then yes the variable
should be an unsigned int.

Well the value it is being compared to (nbytes) is an unsigned int, so the int value (available) will be converted to unsigned int before the comparison anyway. So making 'available' an unsigned int to begin with shouldn't break anything that isn't already broke!

--
-=( Ian Abbott @ MEV Ltd.    E-mail: <abbotti@xxxxxxxxx>        )=-
-=( Tel: +44 (0)161 477 1898   FAX: +44 (0)161 718 3587         )=-


_______________________________________________
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