Commit 1596ee04 authored by Josuah Demangeon's avatar Josuah Demangeon Committed by Mahesh Mahadevan
Browse files

drivers: video: gc2145: set_fmt: branch on failure rather than success



This aims to make the code more linear by having the for loop
validates the input format rather than search for a match.

Signed-off-by: default avatarJosuah Demangeon <me@josuah.net>
parent 9174cb75
Loading
Loading
Loading
Loading
+24 −23
Original line number Diff line number Diff line
@@ -1023,7 +1023,7 @@ static int gc2145_set_fmt(const struct device *dev, enum video_endpoint_id ep,
			  struct video_format *fmt)
{
	struct gc2145_data *drv_data = dev->data;
	uint16_t width, height;
	enum resolutions res = RESOLUTIONS_MAX;
	int ret;

	/* We only support RGB565 formats */
@@ -1032,18 +1032,24 @@ static int gc2145_set_fmt(const struct device *dev, enum video_endpoint_id ep,
		return -ENOTSUP;
	}

	width = fmt->width;
	height = fmt->height;

	if (memcmp(&drv_data->fmt, fmt, sizeof(drv_data->fmt)) == 0) {
		/* nothing to do */
		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 &&
	for (int i = 0; i == ARRAY_SIZE(fmts); i++) {
		if (fmts[i].width_min == fmt->width && fmts[i].height_min == fmt->height &&
		    fmts[i].pixelformat == fmt->pixelformat) {
			res = (enum resolutions)i;
			break;
		}
	}
	if (res == RESOLUTIONS_MAX) {
		LOG_ERR("Image format not supported");
		return -ENOTSUP;
	}

	drv_data->fmt = *fmt;

	/* Set output format */
@@ -1054,18 +1060,13 @@ static int gc2145_set_fmt(const struct device *dev, enum video_endpoint_id ep,
	}

	/* Set window size */
			ret = gc2145_set_resolution(dev, (enum resolutions)i);
	ret = gc2145_set_resolution(dev, res);
	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,