Re: [PATCH] media: avoid skipping MEDIA_PAD_FL_MUST_CONNECT logic

From: Sakari Ailus
Date: Fri May 31 2019 - 06:33:43 EST


Hi Nikita,

On Fri, May 31, 2019 at 11:06:37AM +0300, Nikita Yushchenko wrote:
> In the current code, __media_pipeline_start() skips check of
> MEDIA_PAD_FL_MUST_CONNECT logic for entity not providing link_validate()
> op.
>
> Fix that by checking for existence of link_validate() at different code
> location.
>
> Signed-off-by: Nikita Yushchenko <nikita.yoush@xxxxxxxxxxxxxxxxxx>
> ---
> drivers/media/mc/mc-entity.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/media/mc/mc-entity.c b/drivers/media/mc/mc-entity.c
> index a998a2e0ea1d..8b4912be30d1 100644
> --- a/drivers/media/mc/mc-entity.c
> +++ b/drivers/media/mc/mc-entity.c
> @@ -449,9 +449,6 @@ __must_check int __media_pipeline_start(struct media_entity *entity,
> if (entity->stream_count > 1)
> continue;
>
> - if (!entity->ops || !entity->ops->link_validate)
> - continue;
> -
> bitmap_zero(active, entity->num_pads);
> bitmap_fill(has_no_links, entity->num_pads);
>
> @@ -479,6 +476,9 @@ __must_check int __media_pipeline_start(struct media_entity *entity,
> !(link->flags & MEDIA_LNK_FL_ENABLED))
> continue;
>
> + if (!entity->ops || !entity->ops->link_validate)
> + continue;
> +
> ret = entity->ops->link_validate(link);
> if (ret < 0 && ret != -ENOIOCTLCMD) {
> dev_dbg(entity->graph_obj.mdev->dev,

Thanks for the patch. This generally hasn't been an issue as drivers do
implement link_validate function. But it still is a bug in the code.

The link validation function does not change during the loop. How about
caching it locally and implementing a static nop variant you call in case
there's nothing to theck, so there's no need to check for entity->ops and
the entity->ops->link_validate separately on every iteration?

--
Kind regards,

Sakari Ailus