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

Ian Abbott abbotti at mev.co.uk
Wed Jan 2 13:51:58 UTC 2013


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 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 | 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.

> +
> +	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 */
>


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



More information about the devel mailing list