diff mbox series

[v3,12/31] media: entity: Add an iterator helper for connected pads

Message ID 20190305185150.20776-13-jacopo+renesas@jmondi.org (mailing list archive)
State New
Delegated to: Kieran Bingham
Headers show
Series v4l: add support for multiplexed streams | expand

Commit Message

Jacopo Mondi March 5, 2019, 6:51 p.m. UTC
From: Sakari Ailus <sakari.ailus@linux.intel.com>

Add a helper macro for iterating over pads that are connected through
enabled routes. This can be used to find all the connected pads within an
entity, for instance starting from the pad which has been obtained during
the graph walk.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>

- Make __media_entity_next_routed_pad() return NULL and adjust the
  iterator to handle that
Signed-off-by: Jacopo Mondi <jacopo+renesas@jmondi.org>
---
 include/media/media-entity.h | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

Comments

Sakari Ailus March 7, 2019, 10:09 a.m. UTC | #1
Hi Jacopo,

On Tue, Mar 05, 2019 at 07:51:31PM +0100, Jacopo Mondi wrote:
> From: Sakari Ailus <sakari.ailus@linux.intel.com>
> 
> Add a helper macro for iterating over pads that are connected through
> enabled routes. This can be used to find all the connected pads within an
> entity, for instance starting from the pad which has been obtained during
> the graph walk.
> 
> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
> 
> - Make __media_entity_next_routed_pad() return NULL and adjust the
>   iterator to handle that
> Signed-off-by: Jacopo Mondi <jacopo+renesas@jmondi.org>
> ---
>  include/media/media-entity.h | 27 +++++++++++++++++++++++++++
>  1 file changed, 27 insertions(+)
> 
> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> index 205561545d7e..82f0bdf2a6d1 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -936,6 +936,33 @@ __must_check int media_graph_walk_init(
>  bool media_entity_has_route(struct media_entity *entity, unsigned int pad0,
>  			    unsigned int pad1);
>  
> +static inline struct media_pad *__media_entity_next_routed_pad(
> +	struct media_pad *start, struct media_pad *iter)
> +{
> +	struct media_entity *entity = start->entity;
> +
> +	while (iter < &entity->pads[entity->num_pads] &&
> +	       !media_entity_has_route(entity, start->index, iter->index))
> +		iter++;
> +
> +	return iter == &entity->pads[entity->num_pads] ? NULL : iter;

Could you use iter <= ...?

It doesn't seem to matter here, but it'd seem safer to change the check.

> +}
> +
> +/**
> + * media_entity_for_each_routed_pad - Iterate over entity pads connected by routes
> + *
> + * @start: The stating pad
> + * @iter: The iterator pad
> + *
> + * Iterate over all pads connected through routes from a given pad
> + * within an entity. The iteration will include the starting pad itself.
> + */
> +#define media_entity_for_each_routed_pad(start, iter)			\
> +	for (iter = __media_entity_next_routed_pad(			\
> +		     start, (start)->entity->pads);			\
> +	     iter != NULL;						\
> +	     iter = __media_entity_next_routed_pad(start, iter + 1))
> +
>  /**
>   * media_graph_walk_cleanup - Release resources used by graph walk.
>   *
Ian Arkver March 7, 2019, 10:27 a.m. UTC | #2
On 07/03/2019 10:09, Sakari Ailus wrote:
> Hi Jacopo,
> 
> On Tue, Mar 05, 2019 at 07:51:31PM +0100, Jacopo Mondi wrote:
>> From: Sakari Ailus <sakari.ailus@linux.intel.com>
>>
>> Add a helper macro for iterating over pads that are connected through
>> enabled routes. This can be used to find all the connected pads within an
>> entity, for instance starting from the pad which has been obtained during
>> the graph walk.
>>
>> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
>> Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
>>
>> - Make __media_entity_next_routed_pad() return NULL and adjust the
>>    iterator to handle that
>> Signed-off-by: Jacopo Mondi <jacopo+renesas@jmondi.org>
>> ---
>>   include/media/media-entity.h | 27 +++++++++++++++++++++++++++
>>   1 file changed, 27 insertions(+)
>>
>> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
>> index 205561545d7e..82f0bdf2a6d1 100644
>> --- a/include/media/media-entity.h
>> +++ b/include/media/media-entity.h
>> @@ -936,6 +936,33 @@ __must_check int media_graph_walk_init(
>>   bool media_entity_has_route(struct media_entity *entity, unsigned int pad0,
>>   			    unsigned int pad1);
>>   
>> +static inline struct media_pad *__media_entity_next_routed_pad(
>> +	struct media_pad *start, struct media_pad *iter)
>> +{
>> +	struct media_entity *entity = start->entity;
>> +
>> +	while (iter < &entity->pads[entity->num_pads] &&
>> +	       !media_entity_has_route(entity, start->index, iter->index))
>> +		iter++;
>> +
>> +	return iter == &entity->pads[entity->num_pads] ? NULL : iter;
> 
> Could you use iter <= ...?
> 
> It doesn't seem to matter here, but it'd seem safer to change the check.
> 

How about something like...

for (; iter < &entity->pads[entity->num_pads]; iter++)
     if (media_entity_has_route(entity, start->index, iter->index))
         return iter;

return NULL;

Regards,
Ian

>> +}
>> +
>> +/**
>> + * media_entity_for_each_routed_pad - Iterate over entity pads connected by routes
>> + *
>> + * @start: The stating pad
>> + * @iter: The iterator pad
>> + *
>> + * Iterate over all pads connected through routes from a given pad
>> + * within an entity. The iteration will include the starting pad itself.
>> + */
>> +#define media_entity_for_each_routed_pad(start, iter)			\
>> +	for (iter = __media_entity_next_routed_pad(			\
>> +		     start, (start)->entity->pads);			\
>> +	     iter != NULL;						\
>> +	     iter = __media_entity_next_routed_pad(start, iter + 1))
>> +
>>   /**
>>    * media_graph_walk_cleanup - Release resources used by graph walk.
>>    *
>
Sakari Ailus March 7, 2019, 12:38 p.m. UTC | #3
On Thu, Mar 07, 2019 at 10:27:36AM +0000, Ian Arkver wrote:
> On 07/03/2019 10:09, Sakari Ailus wrote:
> > Hi Jacopo,
> > 
> > On Tue, Mar 05, 2019 at 07:51:31PM +0100, Jacopo Mondi wrote:
> > > From: Sakari Ailus <sakari.ailus@linux.intel.com>
> > > 
> > > Add a helper macro for iterating over pads that are connected through
> > > enabled routes. This can be used to find all the connected pads within an
> > > entity, for instance starting from the pad which has been obtained during
> > > the graph walk.
> > > 
> > > Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> > > Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
> > > 
> > > - Make __media_entity_next_routed_pad() return NULL and adjust the
> > >    iterator to handle that
> > > Signed-off-by: Jacopo Mondi <jacopo+renesas@jmondi.org>
> > > ---
> > >   include/media/media-entity.h | 27 +++++++++++++++++++++++++++
> > >   1 file changed, 27 insertions(+)
> > > 
> > > diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> > > index 205561545d7e..82f0bdf2a6d1 100644
> > > --- a/include/media/media-entity.h
> > > +++ b/include/media/media-entity.h
> > > @@ -936,6 +936,33 @@ __must_check int media_graph_walk_init(
> > >   bool media_entity_has_route(struct media_entity *entity, unsigned int pad0,
> > >   			    unsigned int pad1);
> > > +static inline struct media_pad *__media_entity_next_routed_pad(
> > > +	struct media_pad *start, struct media_pad *iter)
> > > +{
> > > +	struct media_entity *entity = start->entity;
> > > +
> > > +	while (iter < &entity->pads[entity->num_pads] &&
> > > +	       !media_entity_has_route(entity, start->index, iter->index))
> > > +		iter++;
> > > +
> > > +	return iter == &entity->pads[entity->num_pads] ? NULL : iter;
> > 
> > Could you use iter <= ...?
> > 
> > It doesn't seem to matter here, but it'd seem safer to change the check.
> > 
> 
> How about something like...
> 
> for (; iter < &entity->pads[entity->num_pads]; iter++)
>     if (media_entity_has_route(entity, start->index, iter->index))
>         return iter;
> 
> return NULL;

Even better!
Jacopo Mondi March 7, 2019, 8:18 p.m. UTC | #4
Hi Ian, Sakari,

On Thu, Mar 07, 2019 at 10:27:36AM +0000, Ian Arkver wrote:
> On 07/03/2019 10:09, Sakari Ailus wrote:
> > Hi Jacopo,
> >
> > On Tue, Mar 05, 2019 at 07:51:31PM +0100, Jacopo Mondi wrote:
> > > From: Sakari Ailus <sakari.ailus@linux.intel.com>
> > >
> > > Add a helper macro for iterating over pads that are connected through
> > > enabled routes. This can be used to find all the connected pads within an
> > > entity, for instance starting from the pad which has been obtained during
> > > the graph walk.
> > >
> > > Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> > > Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
> > >
> > > - Make __media_entity_next_routed_pad() return NULL and adjust the
> > >    iterator to handle that
> > > Signed-off-by: Jacopo Mondi <jacopo+renesas@jmondi.org>
> > > ---
> > >   include/media/media-entity.h | 27 +++++++++++++++++++++++++++
> > >   1 file changed, 27 insertions(+)
> > >
> > > diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> > > index 205561545d7e..82f0bdf2a6d1 100644
> > > --- a/include/media/media-entity.h
> > > +++ b/include/media/media-entity.h
> > > @@ -936,6 +936,33 @@ __must_check int media_graph_walk_init(
> > >   bool media_entity_has_route(struct media_entity *entity, unsigned int pad0,
> > >   			    unsigned int pad1);
> > > +static inline struct media_pad *__media_entity_next_routed_pad(
> > > +	struct media_pad *start, struct media_pad *iter)
> > > +{
> > > +	struct media_entity *entity = start->entity;
> > > +
> > > +	while (iter < &entity->pads[entity->num_pads] &&
> > > +	       !media_entity_has_route(entity, start->index, iter->index))
> > > +		iter++;
> > > +
> > > +	return iter == &entity->pads[entity->num_pads] ? NULL : iter;
> >
> > Could you use iter <= ...?
> >
> > It doesn't seem to matter here, but it'd seem safer to change the check.
> >
>
> How about something like...
>
> for (; iter < &entity->pads[entity->num_pads]; iter++)
>     if (media_entity_has_route(entity, start->index, iter->index))
>         return iter;
>
> return NULL;
>

Great, thank you both, I'll take this in!


> Regards,
> Ian
>
> > > +}
> > > +
> > > +/**
> > > + * media_entity_for_each_routed_pad - Iterate over entity pads connected by routes
> > > + *
> > > + * @start: The stating pad
> > > + * @iter: The iterator pad
> > > + *
> > > + * Iterate over all pads connected through routes from a given pad
> > > + * within an entity. The iteration will include the starting pad itself.
> > > + */
> > > +#define media_entity_for_each_routed_pad(start, iter)			\
> > > +	for (iter = __media_entity_next_routed_pad(			\
> > > +		     start, (start)->entity->pads);			\
> > > +	     iter != NULL;						\
> > > +	     iter = __media_entity_next_routed_pad(start, iter + 1))
> > > +
> > >   /**
> > >    * media_graph_walk_cleanup - Release resources used by graph walk.
> > >    *
> >
diff mbox series

Patch

diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index 205561545d7e..82f0bdf2a6d1 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -936,6 +936,33 @@  __must_check int media_graph_walk_init(
 bool media_entity_has_route(struct media_entity *entity, unsigned int pad0,
 			    unsigned int pad1);
 
+static inline struct media_pad *__media_entity_next_routed_pad(
+	struct media_pad *start, struct media_pad *iter)
+{
+	struct media_entity *entity = start->entity;
+
+	while (iter < &entity->pads[entity->num_pads] &&
+	       !media_entity_has_route(entity, start->index, iter->index))
+		iter++;
+
+	return iter == &entity->pads[entity->num_pads] ? NULL : iter;
+}
+
+/**
+ * media_entity_for_each_routed_pad - Iterate over entity pads connected by routes
+ *
+ * @start: The stating pad
+ * @iter: The iterator pad
+ *
+ * Iterate over all pads connected through routes from a given pad
+ * within an entity. The iteration will include the starting pad itself.
+ */
+#define media_entity_for_each_routed_pad(start, iter)			\
+	for (iter = __media_entity_next_routed_pad(			\
+		     start, (start)->entity->pads);			\
+	     iter != NULL;						\
+	     iter = __media_entity_next_routed_pad(start, iter + 1))
+
 /**
  * media_graph_walk_cleanup - Release resources used by graph walk.
  *