Sort the enumeration result. This makes e.g. matching formats at both ends
of the link much easier.

Signed-off-by: Sakari Ailus <[email protected]>
---
 src/v4l2subdev.c |   14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/src/v4l2subdev.c b/src/v4l2subdev.c
index 946c030..d553216 100644
--- a/src/v4l2subdev.c
+++ b/src/v4l2subdev.c
@@ -65,6 +65,19 @@ void v4l2_subdev_close(struct media_entity *entity)
        }
 }
 
+static int mbus_code_sort(const void *p1, const void *p2)
+{
+       const unsigned int *c1 = p1, *c2 = p2;
+
+       if (*c1 < *c2)
+               return -1;
+
+       if (*c1 > *c2)
+               return 1;
+
+       return 0;
+}
+
 struct v4l2_subdev_mbus_codes *
 v4l2_subdev_enum_mbus_code(struct media_entity *entity, unsigned int pad)
 {
@@ -100,6 +113,7 @@ v4l2_subdev_enum_mbus_code(struct media_entity *entity, 
unsigned int pad)
        }
 
        codes->ncode = c.index;
+       qsort(codes->code, codes->ncode, sizeof(*codes->code), &mbus_code_sort);
 
        v4l2_subdev_close(entity);
        return codes;
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to