From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Sakari Ailus <sakari.ailus@iki.fi>
Cc: linux-media@vger.kernel.org, linux-sh@vger.kernel.org,
Hans Verkuil <hverkuil@xs4all.nl>,
Katsuya MATSUBARA <matsu@igel.co.jp>,
Sylwester Nawrocki <sylvester.nawrocki@gmail.com>
Subject: Re: [PATCH v3 1/5] media: Add support for circular graph traversal
Date: Wed, 31 Jul 2013 15:07:26 +0000 [thread overview]
Message-ID: <4169977.nJNdNMYhKG@avalon> (raw)
In-Reply-To: <20130725135446.GI12281@valkosipuli.retiisi.org.uk>
Hi Sakari,
Thank you for the review.
On Thursday 25 July 2013 16:54:46 Sakari Ailus wrote:
> On Thu, Jul 25, 2013 at 03:00:09PM +0200, Laurent Pinchart wrote:
> > From: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
> >
> > The graph traversal API (media_entity_graph_walk_*) doesn't support
> > cyclic graphs and will fail to correctly walk a graph when circular
> > links exist. Support circular graph traversal by checking whether an
> > entity has already been visited before pushing it to the stack.
> >
> > Signed-off-by: Laurent Pinchart
> > <laurent.pinchart+renesas@ideasonboard.com>
> > ---
> >
> > drivers/media/media-entity.c | 14 +++++++++++---
> > include/media/media-entity.h | 3 +++
> > 2 files changed, 14 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> > index cb30ffb..2c286c3 100644
> > --- a/drivers/media/media-entity.c
> > +++ b/drivers/media/media-entity.c
> > @@ -20,6 +20,7 @@
> > * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
> > USA
> > */
> > +#include <linux/bitmap.h>
> > #include <linux/module.h>
> > #include <linux/slab.h>
> > #include <media/media-entity.h>
> > @@ -121,7 +122,6 @@ static struct media_entity *stack_pop(struct
> > media_entity_graph *graph)>
> > return entity;
> > }
> >
> > -#define stack_peek(en) ((en)->stack[(en)->top - 1].entity)
> > #define link_top(en) ((en)->stack[(en)->top].link)
> > #define stack_top(en) ((en)->stack[(en)->top].entity)
> >
> > @@ -140,6 +140,12 @@ void media_entity_graph_walk_start(struct
> > media_entity_graph *graph,>
> > {
> > graph->top = 0;
> > graph->stack[graph->top].entity = NULL;
> > + bitmap_zero(graph->entities, MEDIA_ENTITY_ENUM_MAX_ID);
> > +
> > + if (WARN_ON(entity->id >= MEDIA_ENTITY_ENUM_MAX_ID))
> > + return;
> > +
> > + __set_bit(entity->id, graph->entities);
> > stack_push(graph, entity);
> > }
> > EXPORT_SYMBOL_GPL(media_entity_graph_walk_start);
> > @@ -180,9 +186,11 @@ media_entity_graph_walk_next(struct
> > media_entity_graph *graph)>
> > /* Get the entity in the other end of the link . */
> > next = media_entity_other(entity, link);
> >
> > + if (WARN_ON(next->id >= MEDIA_ENTITY_ENUM_MAX_ID))
> > + return NULL;
>
> Walking the graph will take the mutex anyway, so I don't think this can
> happen.
Can't it happen if a driver registers more than MEDIA_ENTITY_ENUM_MAX_ID
entities ?
> > - /* Was it the entity we came here from? */
> > - if (next = stack_peek(graph)) {
> > + /* Has the entity already been visited? */
> > + if (__test_and_set_bit(next->id, graph->entities)) {
> > link_top(graph)++;
> > continue;
> > }
> > diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> > index 06bacf9..0b39662 100644
> > --- a/include/media/media-entity.h
> > +++ b/include/media/media-entity.h
> > @@ -23,6 +23,7 @@
> > #ifndef _MEDIA_ENTITY_H
> > #define _MEDIA_ENTITY_H
> >
> > +#include <linux/bitops.h>
> > #include <linux/list.h>
> > #include <linux/media.h>
> >
> > @@ -113,12 +114,14 @@ static inline u32 media_entity_subtype(struct
> > media_entity *entity)>
> > }
> >
> > #define MEDIA_ENTITY_ENUM_MAX_DEPTH 16
> > +#define MEDIA_ENTITY_ENUM_MAX_ID 64
> >
> > struct media_entity_graph {
> > struct {
> > struct media_entity *entity;
> > int link;
> > } stack[MEDIA_ENTITY_ENUM_MAX_DEPTH];
> >
> > + unsigned long entities[BITS_TO_LONGS(MEDIA_ENTITY_ENUM_MAX_ID)];
>
> How about using DECLARE_BITMAP() instead?
Good idea, I'll fix that.
> > int top;
> >
> > };
--
Regards,
Laurent Pinchart
next prev parent reply other threads:[~2013-07-31 15:07 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-25 12:59 [PATCH v3 0/5] Renesas VSP1 driver Laurent Pinchart
2013-07-25 12:59 ` [PATCH v3 1/5] media: Add support for circular graph traversal Laurent Pinchart
2013-07-25 13:54 ` Sakari Ailus
2013-07-31 15:07 ` Laurent Pinchart [this message]
2013-07-25 12:59 ` [PATCH v3 4/5] v4l: Add V4L2_PIX_FMT_NV16M and V4L2_PIX_FMT_NV61M formats Laurent Pinchart
2013-07-30 11:09 ` Sakari Ailus
2013-07-30 11:16 ` Laurent Pinchart
2013-07-30 11:32 ` Sakari Ailus
2013-07-25 12:59 ` [PATCH v3 3/5] v4l: Add media format codes for ARGB8888 and AYUV8888 on 32-bit busses Laurent Pinchart
2013-07-25 12:59 ` [PATCH v3 2/5] v4l: Fix V4L2_MBUS_FMT_YUV10_1X30 media bus pixel code value Laurent Pinchart
2013-07-30 10:57 ` Sakari Ailus
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=4169977.nJNdNMYhKG@avalon \
--to=laurent.pinchart@ideasonboard.com \
--cc=hverkuil@xs4all.nl \
--cc=linux-media@vger.kernel.org \
--cc=linux-sh@vger.kernel.org \
--cc=matsu@igel.co.jp \
--cc=sakari.ailus@iki.fi \
--cc=sylvester.nawrocki@gmail.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;
as well as URLs for NNTP newsgroup(s).