diff mbox series

media: gspca: ov534-ov772x: Fix off-by-one error in set_frame_rate()

Message ID 20241028080256.3537188-1-ruanjinjie@huawei.com
State Accepted
Commit d2842dec577900031826dc44e9bf0c66416d7173
Headers show
Series media: gspca: ov534-ov772x: Fix off-by-one error in set_frame_rate() | expand

Commit Message

Jinjie Ruan Oct. 28, 2024, 8:02 a.m. UTC
In set_frame_rate(), select a rate in rate_0 or rate_1 by checking
sd->frame_rate >= r->fps in a loop, but the loop condition terminates when
the index reaches zero, which fails to check the last elememt in rate_0 or
rate_1.

Check for >= 0 so that the last one in rate_0 or rate_1 is also checked.

Fixes: 189d92af707e ("V4L/DVB (13422): gspca - ov534: ov772x changes from Richard Kaswy.")
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
 drivers/media/usb/gspca/ov534.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Chen Ridong Oct. 31, 2024, 2:55 a.m. UTC | #1
On 2024/10/28 16:02, Jinjie Ruan wrote:
> In set_frame_rate(), select a rate in rate_0 or rate_1 by checking
> sd->frame_rate >= r->fps in a loop, but the loop condition terminates when
> the index reaches zero, which fails to check the last elememt in rate_0 or
> rate_1.
> 
> Check for >= 0 so that the last one in rate_0 or rate_1 is also checked.
> 
> Fixes: 189d92af707e ("V4L/DVB (13422): gspca - ov534: ov772x changes from Richard Kaswy.")
> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
> ---
>  drivers/media/usb/gspca/ov534.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/media/usb/gspca/ov534.c b/drivers/media/usb/gspca/ov534.c
> index 8b6a57f170d0..bdff64a29a33 100644
> --- a/drivers/media/usb/gspca/ov534.c
> +++ b/drivers/media/usb/gspca/ov534.c
> @@ -847,7 +847,7 @@ static void set_frame_rate(struct gspca_dev *gspca_dev)
>  		r = rate_1;
>  		i = ARRAY_SIZE(rate_1);
>  	}
> -	while (--i > 0) {
> +	while (--i >= 0) {
>  		if (sd->frame_rate >= r->fps)
>  			break;
>  		r++;

It looks fine to me.

Thanks,
Ridong
diff mbox series

Patch

diff --git a/drivers/media/usb/gspca/ov534.c b/drivers/media/usb/gspca/ov534.c
index 8b6a57f170d0..bdff64a29a33 100644
--- a/drivers/media/usb/gspca/ov534.c
+++ b/drivers/media/usb/gspca/ov534.c
@@ -847,7 +847,7 @@  static void set_frame_rate(struct gspca_dev *gspca_dev)
 		r = rate_1;
 		i = ARRAY_SIZE(rate_1);
 	}
-	while (--i > 0) {
+	while (--i >= 0) {
 		if (sd->frame_rate >= r->fps)
 			break;
 		r++;