From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Daniel Scally <djrscally@gmail.com>
Cc: linux-media@vger.kernel.org, sakari.ailus@linux.intel.com,
paul.elder@ideasonboard.com
Subject: Re: [PATCH 1/2] media: media-entity.h: Add iterator for entity data links
Date: Wed, 22 Jun 2022 12:16:23 +0300 [thread overview]
Message-ID: <YrLd5wN4C5Sb68YY@pendragon.ideasonboard.com> (raw)
In-Reply-To: <20220621163457.766496-2-djrscally@gmail.com>
Hi Daniel,
Thank you for the patch.
On Tue, Jun 21, 2022 at 05:34:56PM +0100, Daniel Scally wrote:
> 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 --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)
We could make this more dynamic by passing the link type as an argument,
adding more iteration macros for different link types in the future
would then be easier. Up to you.
> +{
> + 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;
This could be simplified to
if (!pos)
pos = list_entry(&entity->links, struct media_link, list);
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;
> +}
This is a bit big for an inline function, could we move the
implementation to the .c file ?
> +
> +#define for_each_media_entity_data_link(entity, pos) \
s/pos/link/ ?
> + for (pos = __media_entity_next_data_link(entity, NULL); \
> + pos; \
> + pos = __media_entity_next_data_link(entity, pos))
> +
I'm afraid this needs documentation :-)
(https://lore.kernel.org/linux-media/20220301161156.1119557-13-tomi.valkeinen@ideasonboard.com/
can be used as an example)
> /**
> * gobj_to_entity - returns the struct &media_entity pointer from the
> * @gobj contained on it.
--
Regards,
Laurent Pinchart
next prev parent reply other threads:[~2022-06-22 9:16 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-21 16:34 [PATCH 0/2] Add iterator for an entity's data links Daniel Scally
2022-06-21 16:34 ` [PATCH 1/2] media: media-entity.h: Add iterator for entity " Daniel Scally
2022-06-22 9:08 ` Jacopo Mondi
2022-06-22 9:17 ` Laurent Pinchart
2022-06-22 9:22 ` Jacopo Mondi
2022-06-22 9:30 ` Daniel Scally
2022-06-22 9:40 ` Daniel Scally
2022-06-22 9:16 ` Laurent Pinchart [this message]
2022-06-21 16:34 ` [PATCH 2/2] media: entity: Use dedicated data link iterator Daniel Scally
2022-06-22 9:18 ` Laurent Pinchart
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YrLd5wN4C5Sb68YY@pendragon.ideasonboard.com \
--to=laurent.pinchart@ideasonboard.com \
--cc=djrscally@gmail.com \
--cc=linux-media@vger.kernel.org \
--cc=paul.elder@ideasonboard.com \
--cc=sakari.ailus@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox