@@ -264,7 +264,7 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index,
bool allow_bayer)
{
const struct imx_media_pixfmt *fmt;
- unsigned int i, match_index = 0;
+ unsigned int i, j = 0, match_index = 0;
for (i = 0; i < ARRAY_SIZE(pixel_formats); i++) {
enum codespace_sel fmt_cs_sel;
@@ -278,18 +278,29 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index,
(!allow_bayer && fmt->bayer))
continue;
- if (index == match_index)
+ if (fourcc && index == match_index)
break;
- match_index++;
+ if (!code) {
+ match_index++;
+ continue;
+ }
+
+ for (j = 0; j < ARRAY_SIZE(fmt->codes) && fmt->codes[j]; j++) {
+ if (index == match_index)
+ goto out;
+
+ match_index++;
+ }
}
if (i == ARRAY_SIZE(pixel_formats))
return -EINVAL;
+out:
if (fourcc)
*fourcc = fmt->fourcc;
if (code)
- *code = fmt->codes[0];
+ *code = fmt->codes[j];
return 0;
}