Skip to content

Commit

Permalink
media: entity: Add iterator for entity data links
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Laurent Pinchart <[email protected]>
Signed-off-by: Sakari Ailus <[email protected]>
Signed-off-by: Mauro Carvalho Chehab <[email protected]>
  • Loading branch information
djrscally authored and mchehab committed Jul 15, 2022
1 parent 3193cee commit 1ed3d64
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
16 changes: 16 additions & 0 deletions drivers/media/mc/mc-entity.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/

#include <linux/bitmap.h>
#include <linux/list.h>
#include <linux/property.h>
#include <linux/slab.h>
#include <media/media-entity.h>
Expand Down Expand Up @@ -1051,3 +1052,18 @@ struct media_link *media_create_ancillary_link(struct media_entity *primary,
return link;
}
EXPORT_SYMBOL_GPL(media_create_ancillary_link);

struct media_link *__media_entity_next_link(struct media_entity *entity,
struct media_link *link,
unsigned long link_type)
{
link = link ? list_next_entry(link, list)
: list_first_entry(&entity->links, typeof(*link), list);

list_for_each_entry_from(link, &entity->links, list)
if ((link->flags & MEDIA_LNK_FL_LINK_TYPE) == link_type)
return link;

return NULL;
}
EXPORT_SYMBOL_GPL(__media_entity_next_link);
30 changes: 30 additions & 0 deletions include/media/media-entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -1140,4 +1140,34 @@ struct media_link *
media_create_ancillary_link(struct media_entity *primary,
struct media_entity *ancillary);

/**
* __media_entity_next_link() - Iterate through a &media_entity's links
*
* @entity: pointer to the &media_entity
* @link: pointer to a &media_link to hold the iterated values
* @link_type: one of the MEDIA_LNK_FL_LINK_TYPE flags
*
* Return the next link against an entity matching a specific link type. This
* allows iteration through an entity's links whilst guaranteeing all of the
* returned links are of the given type.
*/
struct media_link *__media_entity_next_link(struct media_entity *entity,
struct media_link *link,
unsigned long link_type);

/**
* for_each_media_entity_data_link() - Iterate through an entity's data links
*
* @entity: pointer to the &media_entity
* @link: pointer to a &media_link to hold the iterated values
*
* Iterate over a &media_entity's data links
*/
#define for_each_media_entity_data_link(entity, link) \
for (link = __media_entity_next_link(entity, NULL, \
MEDIA_LNK_FL_DATA_LINK); \
link; \
link = __media_entity_next_link(entity, link, \
MEDIA_LNK_FL_DATA_LINK))

#endif

0 comments on commit 1ed3d64

Please sign in to comment.