diff --git a/drivers/video/gc2145.c b/drivers/video/gc2145.c index 592fa74f691c765..7cf55af84c239f7 100644 --- a/drivers/video/gc2145.c +++ b/drivers/video/gc2145.c @@ -1041,31 +1041,34 @@ static int gc2145_set_fmt(const struct device *dev, enum video_endpoint_id ep, } /* Check if camera is capable of handling given format */ - for (int i = 0; i < ARRAY_SIZE(fmts); i++) { + for (int i = 0;; i++) { + if (i == ARRAY_SIZE(fmts)) { + LOG_ERR("Image format not supported\n"); + return -ENOTSUP; + } if (fmts[i].width_min == width && fmts[i].height_min == height && fmts[i].pixelformat == fmt->pixelformat) { - drv_data->fmt = *fmt; + break; + } + } - /* Set output format */ - ret = gc2145_set_output_format(dev, fmt->pixelformat); - if (ret < 0) { - LOG_ERR("Failed to set the output format"); - return ret; - } + drv_data->fmt = *fmt; - /* Set window size */ - ret = gc2145_set_resolution(dev, (enum resolutions)i); - if (ret < 0) { - LOG_ERR("Failed to set the resolution"); - } + /* Set output format */ + ret = gc2145_set_output_format(dev, fmt->pixelformat); + if (ret < 0) { + LOG_ERR("Failed to set the output format"); + return ret; + } - return ret; - } + /* Set window size */ + ret = gc2145_set_resolution(dev, fmt->width, fmt->height); + if (ret < 0) { + LOG_ERR("Failed to set the resolution"); + return ret; } - /* Camera is not capable of handling given format */ - LOG_ERR("Image format not supported\n"); - return -ENOTSUP; + return 0; } static int gc2145_get_fmt(const struct device *dev, enum video_endpoint_id ep,