diff mbox

[2/4] media: Check for active links on pads with MEDIA_PAD_FL_MUST_CONNECT flag

Message ID 1379541668-23085-3-git-send-email-sakari.ailus@iki.fi (mailing list archive)
State New, archived
Headers show

Commit Message

Sakari Ailus Sept. 18, 2013, 10:01 p.m. UTC
Do not allow streaming if a pad with MEDIA_PAD_FL_MUST_CONNECT flag is not
connected by an active link.

This patch makes it possible to avoid drivers having to check for the most
common case of link state validation: a sink pad that must be connected.

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
Tested-by: Sylwester Nawrocki <sylvester.nawrocki@gmail.com>
---
 drivers/media/media-entity.c |   41 ++++++++++++++++++++++++++++++++++-------
 1 file changed, 34 insertions(+), 7 deletions(-)

Comments

Laurent Pinchart Sept. 20, 2013, 8:54 p.m. UTC | #1
Hi Sakari,

Thank you for the patch.

On Thursday 19 September 2013 01:01:06 Sakari Ailus wrote:
> Do not allow streaming if a pad with MEDIA_PAD_FL_MUST_CONNECT flag is not
> connected by an active link.
> 
> This patch makes it possible to avoid drivers having to check for the most
> common case of link state validation: a sink pad that must be connected.
> 
> Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
> Tested-by: Sylwester Nawrocki <sylvester.nawrocki@gmail.com>
> ---
>  drivers/media/media-entity.c |   41 ++++++++++++++++++++++++++++++++-------
>  1 file changed, 34 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> index 2c286c3..a996e0a 100644
> --- a/drivers/media/media-entity.c
> +++ b/drivers/media/media-entity.c
> @@ -235,6 +235,8 @@ __must_check int media_entity_pipeline_start(struct
> media_entity *entity, media_entity_graph_walk_start(&graph, entity);
> 
>  	while ((entity = media_entity_graph_walk_next(&graph))) {
> +		DECLARE_BITMAP(active, entity->num_pads);
> +		DECLARE_BITMAP(has_no_links, entity->num_pads);
>  		unsigned int i;
> 
>  		entity->stream_count++;
> @@ -248,21 +250,46 @@ __must_check int media_entity_pipeline_start(struct
> media_entity *entity, if (!entity->ops || !entity->ops->link_validate)
>  			continue;
> 
> +		bitmap_zero(active, entity->num_pads);
> +		bitmap_fill(has_no_links, entity->num_pads);
> +
>  		for (i = 0; i < entity->num_links; i++) {
>  			struct media_link *link = &entity->links[i];
> -
> -			/* Is this pad part of an enabled link? */
> -			if (!(link->flags & MEDIA_LNK_FL_ENABLED))
> -				continue;
> -
> -			/* Are we the sink or not? */
> -			if (link->sink->entity != entity)
> +			struct media_pad *pad = link->sink->entity == entity
> +				? link->sink : link->source;

What about aligning the ? to the = ? With that change,

Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> +
> +			/* Mark that a pad is connected by a link. */
> +			bitmap_clear(has_no_links, pad->index, 1);
> +
> +			/*
> +			 * Pads that either do not need to connect or
> +			 * are connected through an enabled link are
> +			 * fine.
> +			 */
> +			if (!(pad->flags & MEDIA_PAD_FL_MUST_CONNECT) ||
> +			    link->flags & MEDIA_LNK_FL_ENABLED)
> +				bitmap_set(active, pad->index, 1);
> +
> +			/*
> +			 * Link validation will only take place for
> +			 * sink ends of the link that are enabled.
> +			 */
> +			if (link->sink != pad ||
> +			    !(link->flags & MEDIA_LNK_FL_ENABLED))
>  				continue;
> 
>  			ret = entity->ops->link_validate(link);
>  			if (ret < 0 && ret != -ENOIOCTLCMD)
>  				goto error;
>  		}
> +
> +		/* Either no links or validated links are fine. */
> +		bitmap_or(active, active, has_no_links, entity->num_pads);
> +
> +		if (!bitmap_full(active, entity->num_pads)) {
> +			ret = -EPIPE;
> +			goto error;
> +		}
>  	}
> 
>  	mutex_unlock(&mdev->graph_mutex);
Sakari Ailus Sept. 23, 2013, 7:57 p.m. UTC | #2
On Fri, Sep 20, 2013 at 10:54:22PM +0200, Laurent Pinchart wrote:
> > @@ -248,21 +250,46 @@ __must_check int media_entity_pipeline_start(struct
> > media_entity *entity, if (!entity->ops || !entity->ops->link_validate)
> >  			continue;
> > 
> > +		bitmap_zero(active, entity->num_pads);
> > +		bitmap_fill(has_no_links, entity->num_pads);
> > +
> >  		for (i = 0; i < entity->num_links; i++) {
> >  			struct media_link *link = &entity->links[i];
> > -
> > -			/* Is this pad part of an enabled link? */
> > -			if (!(link->flags & MEDIA_LNK_FL_ENABLED))
> > -				continue;
> > -
> > -			/* Are we the sink or not? */
> > -			if (link->sink->entity != entity)
> > +			struct media_pad *pad = link->sink->entity == entity
> > +				? link->sink : link->source;
> 
> What about aligning the ? to the = ? With that change,

How about to the beginning of the next operand rather than "="?

(Think of adding parentheses around the rvalue of "=".)

I think it's fine as it was, but if it's to be changed then it should be
aligned to link->sink->entity IMHO. :-)
Laurent Pinchart Oct. 1, 2013, 12:39 p.m. UTC | #3
Hi Sakari,

On Monday 23 September 2013 22:57:02 Sakari Ailus wrote:
> On Fri, Sep 20, 2013 at 10:54:22PM +0200, Laurent Pinchart wrote:
> > > @@ -248,21 +250,46 @@ __must_check int
> > > media_entity_pipeline_start(struct media_entity *entity,
> > >  		if (!entity->ops || !entity->ops->link_validate)
> > >  			continue;
> > > 
> > > +		bitmap_zero(active, entity->num_pads);
> > > +		bitmap_fill(has_no_links, entity->num_pads);
> > > +
> > >  		for (i = 0; i < entity->num_links; i++) {
> > >  			struct media_link *link = &entity->links[i];
> > > -
> > > -			/* Is this pad part of an enabled link? */
> > > -			if (!(link->flags & MEDIA_LNK_FL_ENABLED))
> > > -				continue;
> > > -
> > > -			/* Are we the sink or not? */
> > > -			if (link->sink->entity != entity)
> > > +			struct media_pad *pad = link->sink->entity == entity
> > > +				? link->sink : link->source;
> > 
> > What about aligning the ? to the = ? With that change,
> 
> How about to the beginning of the next operand rather than "="?
> 
> (Think of adding parentheses around the rvalue of "=".)
> 
> I think it's fine as it was, but if it's to be changed then it should be
> aligned to link->sink->entity IMHO. :-)

My preference goes for aligning the ? under the =, but I agree it's not 
logical from an rvalue point of view :-) I would favor aligning the ? under 
the l of link, but enough bikeshedding for now, please pick whichever solution 
you prefer :-)
Sakari Ailus Oct. 1, 2013, 12:52 p.m. UTC | #4
Hi Laurent,

On Tue, Oct 01, 2013 at 02:39:14PM +0200, Laurent Pinchart wrote:
> On Monday 23 September 2013 22:57:02 Sakari Ailus wrote:
> > On Fri, Sep 20, 2013 at 10:54:22PM +0200, Laurent Pinchart wrote:
> > > > @@ -248,21 +250,46 @@ __must_check int
> > > > media_entity_pipeline_start(struct media_entity *entity,
> > > >  		if (!entity->ops || !entity->ops->link_validate)
> > > >  			continue;
> > > > 
> > > > +		bitmap_zero(active, entity->num_pads);
> > > > +		bitmap_fill(has_no_links, entity->num_pads);
> > > > +
> > > >  		for (i = 0; i < entity->num_links; i++) {
> > > >  			struct media_link *link = &entity->links[i];
> > > > -
> > > > -			/* Is this pad part of an enabled link? */
> > > > -			if (!(link->flags & MEDIA_LNK_FL_ENABLED))
> > > > -				continue;
> > > > -
> > > > -			/* Are we the sink or not? */
> > > > -			if (link->sink->entity != entity)
> > > > +			struct media_pad *pad = link->sink->entity == entity
> > > > +				? link->sink : link->source;
> > > 
> > > What about aligning the ? to the = ? With that change,
> > 
> > How about to the beginning of the next operand rather than "="?
> > 
> > (Think of adding parentheses around the rvalue of "=".)
> > 
> > I think it's fine as it was, but if it's to be changed then it should be
> > aligned to link->sink->entity IMHO. :-)
> 
> My preference goes for aligning the ? under the =, but I agree it's not 
> logical from an rvalue point of view :-) I would favor aligning the ? under 
> the l of link, but enough bikeshedding for now, please pick whichever solution 
> you prefer :-)

? goes under l of the link; agreed. I'll resend the set.
diff mbox

Patch

diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 2c286c3..a996e0a 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -235,6 +235,8 @@  __must_check int media_entity_pipeline_start(struct media_entity *entity,
 	media_entity_graph_walk_start(&graph, entity);
 
 	while ((entity = media_entity_graph_walk_next(&graph))) {
+		DECLARE_BITMAP(active, entity->num_pads);
+		DECLARE_BITMAP(has_no_links, entity->num_pads);
 		unsigned int i;
 
 		entity->stream_count++;
@@ -248,21 +250,46 @@  __must_check int media_entity_pipeline_start(struct media_entity *entity,
 		if (!entity->ops || !entity->ops->link_validate)
 			continue;
 
+		bitmap_zero(active, entity->num_pads);
+		bitmap_fill(has_no_links, entity->num_pads);
+
 		for (i = 0; i < entity->num_links; i++) {
 			struct media_link *link = &entity->links[i];
-
-			/* Is this pad part of an enabled link? */
-			if (!(link->flags & MEDIA_LNK_FL_ENABLED))
-				continue;
-
-			/* Are we the sink or not? */
-			if (link->sink->entity != entity)
+			struct media_pad *pad = link->sink->entity == entity
+				? link->sink : link->source;
+
+			/* Mark that a pad is connected by a link. */
+			bitmap_clear(has_no_links, pad->index, 1);
+
+			/*
+			 * Pads that either do not need to connect or
+			 * are connected through an enabled link are
+			 * fine.
+			 */
+			if (!(pad->flags & MEDIA_PAD_FL_MUST_CONNECT) ||
+			    link->flags & MEDIA_LNK_FL_ENABLED)
+				bitmap_set(active, pad->index, 1);
+
+			/*
+			 * Link validation will only take place for
+			 * sink ends of the link that are enabled.
+			 */
+			if (link->sink != pad ||
+			    !(link->flags & MEDIA_LNK_FL_ENABLED))
 				continue;
 
 			ret = entity->ops->link_validate(link);
 			if (ret < 0 && ret != -ENOIOCTLCMD)
 				goto error;
 		}
+
+		/* Either no links or validated links are fine. */
+		bitmap_or(active, active, has_no_links, entity->num_pads);
+
+		if (!bitmap_full(active, entity->num_pads)) {
+			ret = -EPIPE;
+			goto error;
+		}
 	}
 
 	mutex_unlock(&mdev->graph_mutex);