Re: [PATCH] [media] v4l2-common: fix overflow in v4l_bound_align_image()
From: Sakari Ailus
Date: Wed Sep 10 2014 - 08:30:22 EST
Hi Maciej,
Thanks for the patch!
On Tue, Sep 09, 2014 at 05:16:41PM +0200, Maciej Matraszek wrote:
> diff --git a/drivers/media/v4l2-core/v4l2-common.c b/drivers/media/v4l2-core/v4l2-common.c
> index ccaa38f65cf1..506cf8b7763b 100644
> --- a/drivers/media/v4l2-core/v4l2-common.c
> +++ b/drivers/media/v4l2-core/v4l2-common.c
> @@ -435,16 +435,13 @@ static unsigned int clamp_align(unsigned int x, unsigned int min,
> /* Bits that must be zero to be aligned */
> unsigned int mask = ~((1 << align) - 1);
>
> + /* Clamp to aligned min and max */
> + x = clamp_t(unsigned int, x, (min + ~mask) & mask, max & mask);
I think you could use just clamp() since all the arguments are unsigned int.
With that considered,
Acked-by: Sakari Ailus <sakari.ailus@xxxxxxxxxxxxxxx>
> +
> /* Round to nearest aligned value */
> if (align)
> x = (x + (1 << (align - 1))) & mask;
>
> - /* Clamp to aligned value of min and max */
> - if (x < min)
> - x = (min + ~mask) & mask;
> - else if (x > max)
> - x = max & mask;
> -
> return x;
> }
>
--
Kind regards,
Sakari Ailus
e-mail: sakari.ailus@xxxxxx XMPP: sailus@xxxxxxxxxxxxxx
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/