diff mbox series

[1/2] media: media-entity.h: Add iterator for entity data links

Message ID 20220621163457.766496-2-djrscally@gmail.com
State New
Headers show
Series Add iterator for an entity's data links | expand

Commit Message

Daniel Scally June 21, 2022, 4:34 p.m. UTC
Iterating over the links for an entity is a somewhat common need
through the media subsystem, but generally the assumption is that
they will all be data links. To meet that assumption add a new macro
that iterates through an entity's links and skips non-data links.

Signed-off-by: Daniel Scally <djrscally@gmail.com>
---
 include/media/media-entity.h | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
diff mbox series

Patch

diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index a9a1c0ec5d1c..b13f67f33508 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -550,6 +550,32 @@  static inline bool media_entity_enum_intersects(
 				 min(ent_enum1->idx_max, ent_enum2->idx_max));
 }
 
+static inline struct media_link *
+__media_entity_next_data_link(struct media_entity *entity,
+			      struct media_link *pos)
+{
+	if (!pos) {
+		list_for_each_entry(pos, &entity->links, list)
+			if ((pos->flags & MEDIA_LNK_FL_LINK_TYPE) ==
+			    MEDIA_LNK_FL_DATA_LINK)
+				return pos;
+
+		return NULL;
+	}
+
+	list_for_each_entry_continue(pos, &entity->links, list)
+		if ((pos->flags & MEDIA_LNK_FL_LINK_TYPE) ==
+		    MEDIA_LNK_FL_DATA_LINK)
+			return pos;
+
+	return NULL;
+}
+
+#define for_each_media_entity_data_link(entity, pos)		\
+	for (pos = __media_entity_next_data_link(entity, NULL);	\
+	     pos;						\
+	     pos = __media_entity_next_data_link(entity, pos))
+
 /**
  * gobj_to_entity - returns the struct &media_entity pointer from the
  *	@gobj contained on it.