Skip to content

Commit ea5086f

Browse files
committed
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: Josuah Demangeon <me@josuah.net>
1 parent c325ac7 commit ea5086f

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

drivers/video/gc2145.c

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ static int gc2145_set_fmt(const struct device *dev, enum video_endpoint_id ep,
10231023
struct video_format *fmt)
10241024
{
10251025
struct gc2145_data *drv_data = dev->data;
1026-
uint16_t width, height;
1026+
enum resolutions res = RESOLUTIONS_MAX;
10271027
int ret;
10281028

10291029
/* We only support RGB565 formats */
@@ -1032,40 +1032,41 @@ static int gc2145_set_fmt(const struct device *dev, enum video_endpoint_id ep,
10321032
return -ENOTSUP;
10331033
}
10341034

1035-
width = fmt->width;
1036-
height = fmt->height;
1037-
10381035
if (memcmp(&drv_data->fmt, fmt, sizeof(drv_data->fmt)) == 0) {
10391036
/* nothing to do */
10401037
return 0;
10411038
}
10421039

10431040
/* Check if camera is capable of handling given format */
1044-
for (int i = 0; i < ARRAY_SIZE(fmts); i++) {
1045-
if (fmts[i].width_min == width && fmts[i].height_min == height &&
1041+
for (int i = 0; i == ARRAY_SIZE(fmts); i++) {
1042+
if (fmts[i].width_min == fmt->width && fmts[i].height_min == fmt->height &&
10461043
fmts[i].pixelformat == fmt->pixelformat) {
1047-
drv_data->fmt = *fmt;
1044+
res = (enum resolutions)i;
1045+
break;
1046+
}
1047+
}
1048+
if (res == RESOLUTIONS_MAX) {
1049+
LOG_ERR("Image format not supported");
1050+
return -ENOTSUP;
1051+
}
10481052

1049-
/* Set output format */
1050-
ret = gc2145_set_output_format(dev, fmt->pixelformat);
1051-
if (ret < 0) {
1052-
LOG_ERR("Failed to set the output format");
1053-
return ret;
1054-
}
1053+
drv_data->fmt = *fmt;
10551054

1056-
/* Set window size */
1057-
ret = gc2145_set_resolution(dev, (enum resolutions)i);
1058-
if (ret < 0) {
1059-
LOG_ERR("Failed to set the resolution");
1060-
}
1055+
/* Set output format */
1056+
ret = gc2145_set_output_format(dev, fmt->pixelformat);
1057+
if (ret < 0) {
1058+
LOG_ERR("Failed to set the output format");
1059+
return ret;
1060+
}
10611061

1062-
return ret;
1063-
}
1062+
/* Set window size */
1063+
ret = gc2145_set_resolution(dev, res);
1064+
if (ret < 0) {
1065+
LOG_ERR("Failed to set the resolution");
1066+
return ret;
10641067
}
10651068

1066-
/* Camera is not capable of handling given format */
1067-
LOG_ERR("Image format not supported\n");
1068-
return -ENOTSUP;
1069+
return 0;
10691070
}
10701071

10711072
static int gc2145_get_fmt(const struct device *dev, enum video_endpoint_id ep,

0 commit comments

Comments
 (0)