]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
media: stm32: dcmipp: avoid duplicated format on enum in bytecap
authorAlain Volmat <alain.volmat@foss.st.com>
Thu, 12 Dec 2024 09:17:34 +0000 (10:17 +0100)
committerHans Verkuil <hverkuil@xs4all.nl>
Thu, 12 Dec 2024 12:22:26 +0000 (13:22 +0100)
Avoid duplication of enumerated pixelformat on the bytecap
video capture device.  Indeed, since the bytecap format list
contains both CSI & parallel 16bits formats, ensure that same
pixelformat are not reported twice when performing enumeration
of supported formats.

Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
drivers/media/platform/st/stm32/stm32-dcmipp/dcmipp-bytecap.c

index da80e1aa37ca3851c393abd70e0206cf25f87726..1c1b6b48918ee26f245d4cf99086473c44e74123 100644 (file)
@@ -268,34 +268,34 @@ static int dcmipp_bytecap_enum_fmt_vid_cap(struct file *file, void *priv,
 {
        const struct dcmipp_bytecap_pix_map *vpix;
        unsigned int index = f->index;
-       unsigned int i;
+       unsigned int i, prev_pixelformat = 0;
 
-       if (f->mbus_code) {
-               /*
-                * If a media bus code is specified, only enumerate formats
-                * compatible with it.
-                */
-               for (i = 0; i < ARRAY_SIZE(dcmipp_bytecap_pix_map_list); i++) {
-                       vpix = &dcmipp_bytecap_pix_map_list[i];
-                       if (vpix->code != f->mbus_code)
-                               continue;
+       /*
+        * List up all formats (or only ones matching f->mbus_code), taking
+        * care of removing duplicated entries (due to support of both
+        * parallel & csi 16 bits formats
+        */
+       for (i = 0; i < ARRAY_SIZE(dcmipp_bytecap_pix_map_list); i++) {
+               vpix = &dcmipp_bytecap_pix_map_list[i];
+               /* Skip formats not matching requested mbus code */
+               if (f->mbus_code && vpix->code != f->mbus_code)
+                       continue;
 
-                       if (index == 0)
-                               break;
+               /* Skip duplicated pixelformat */
+               if (vpix->pixelformat == prev_pixelformat)
+                       continue;
 
-                       index--;
-               }
+               prev_pixelformat = vpix->pixelformat;
 
-               if (i == ARRAY_SIZE(dcmipp_bytecap_pix_map_list))
-                       return -EINVAL;
-       } else {
-               /* Otherwise, enumerate all formats. */
-               if (f->index >= ARRAY_SIZE(dcmipp_bytecap_pix_map_list))
-                       return -EINVAL;
+               if (index == 0)
+                       break;
 
-               vpix = &dcmipp_bytecap_pix_map_list[f->index];
+               index--;
        }
 
+       if (i == ARRAY_SIZE(dcmipp_bytecap_pix_map_list))
+               return -EINVAL;
+
        f->pixelformat = vpix->pixelformat;
 
        return 0;