Skip to content

Commit 81f5725

Browse files
josuahmmahadevan108
authored andcommitted
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: Josuah Demangeon <[email protected]>
1 parent 61c5346 commit 81f5725

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

drivers/video/gc2145.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,24 +1040,25 @@ static int gc2145_set_fmt(const struct device *dev, enum video_endpoint_id ep,
10401040
return 0;
10411041
}
10421042

1043-
drv_data->fmt = *fmt;
1044-
1045-
/* Set output format */
1046-
ret = gc2145_set_output_format(dev, fmt->pixelformat);
1047-
if (ret < 0) {
1048-
LOG_ERR("Failed to set the output format");
1049-
return ret;
1050-
}
1051-
10521043
/* Check if camera is capable of handling given format */
10531044
for (int i = 0; i < ARRAY_SIZE(fmts); i++) {
10541045
if (fmts[i].width_min == width && fmts[i].height_min == height &&
10551046
fmts[i].pixelformat == fmt->pixelformat) {
1047+
drv_data->fmt = *fmt;
1048+
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+
}
1055+
10561056
/* Set window size */
10571057
ret = gc2145_set_resolution(dev, (enum resolutions)i);
10581058
if (ret < 0) {
10591059
LOG_ERR("Failed to set the resolution");
10601060
}
1061+
10611062
return ret;
10621063
}
10631064
}

0 commit comments

Comments
 (0)