Re: [PATCH 4/7] media: ov9650: add a sanity check

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

 



On 8/22/19 21:39, Mauro Carvalho Chehab wrote:
> As pointed by cppcheck:
> 
> 	[drivers/media/i2c/ov9650.c:706]: (error) Shifting by a negative value is undefined behaviour
> 	[drivers/media/i2c/ov9650.c:707]: (error) Shifting by a negative value is undefined behaviour
> 	[drivers/media/i2c/ov9650.c:721]: (error) Shifting by a negative value is undefined behaviour
> 
> Prevent mangling with gains with invalid values
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@xxxxxxxxxx>
> ---
>  drivers/media/i2c/ov9650.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/media/i2c/ov9650.c b/drivers/media/i2c/ov9650.c
> index 8b56011446a9..cb49fda902fd 100644
> --- a/drivers/media/i2c/ov9650.c
> +++ b/drivers/media/i2c/ov9650.c
> @@ -703,6 +703,11 @@ static int ov965x_set_gain(struct ov965x *ov965x, int auto_gain)
>  		for (m = 6; m >= 0; m--)
>  			if (gain >= (1 << m) * 16)
>  				break;
> +
> +		/* Sanity check: don't adjust the gain with a negative val */

s/val/value ?

> +		if (m < 0)
> +			return -EINVAL;

This will never happen as min value of V4L2_CID_GAIN control is 16
(gain is always >= 16 and m is always >= 0).
But if it suppresses the warning I'm fine with it.

Reviewed-by: Sylwester Nawrocki <s.nawrocki@xxxxxxxxxxx>



[Index of Archives]     [Linux Input]     [Video for Linux]     [Gstreamer Embedded]     [Mplayer Users]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux