Commit 81f57258 authored by Josuah Demangeon's avatar Josuah Demangeon Committed by Mahesh Mahadevan
Browse files

drivers: video: gc2145: check format compatibility before applying



While applying the format, the pixel format and drv_data->fmt were set
immediately, and the resolution was set only if it had a matching
entry on the "caps".

This commit makes sure the requested format matches the caps before
applying the format as well as drv_data->fmt. This does not guards
against partial failure (i.e. only pixelformat set and not
resolution).

Signed-off-by: default avatarJosuah Demangeon <me@josuah.net>
parent 61c53460
Loading
Loading
Loading
Loading
+10 −9
Original line number Diff line number Diff line
@@ -1040,6 +1040,10 @@ static int gc2145_set_fmt(const struct device *dev, enum video_endpoint_id ep,
		return 0;
	}

	/* Check if camera is capable of handling given format */
	for (int i = 0; i < ARRAY_SIZE(fmts); i++) {
		if (fmts[i].width_min == width && fmts[i].height_min == height &&
		    fmts[i].pixelformat == fmt->pixelformat) {
			drv_data->fmt = *fmt;

			/* Set output format */
@@ -1049,15 +1053,12 @@ static int gc2145_set_fmt(const struct device *dev, enum video_endpoint_id ep,
				return ret;
			}

	/* Check if camera is capable of handling given format */
	for (int i = 0; i < ARRAY_SIZE(fmts); i++) {
		if (fmts[i].width_min == width && fmts[i].height_min == height &&
		    fmts[i].pixelformat == fmt->pixelformat) {
			/* Set window size */
			ret = gc2145_set_resolution(dev, (enum resolutions)i);
			if (ret < 0) {
				LOG_ERR("Failed to set the resolution");
			}

			return ret;
		}
	}