diff options
author | Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com> | 2013-06-07 11:45:11 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <m.chehab@samsung.com> | 2013-08-18 06:16:48 -0400 |
commit | 5c7b25b90d36942c524d06522ebaf0510a75592a (patch) | |
tree | 979e3f88bf6e507021c28ac3e9236f7d5cc3bfa9 /drivers/media/media-entity.c | |
parent | 3a9677063f00a61b6067a07df3d7ee12eace79b7 (diff) |
[media] media: Add support for circular graph traversal
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>
Acked-by: Sakari Ailus <sakari.ailus@iki.fi>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Diffstat (limited to 'drivers/media/media-entity.c')
-rw-r--r-- | drivers/media/media-entity.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c index cb30ffbd5ba8..2c286c307145 100644 --- a/drivers/media/media-entity.c +++ b/drivers/media/media-entity.c | |||
@@ -20,6 +20,7 @@ | |||
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
21 | */ | 21 | */ |
22 | 22 | ||
23 | #include <linux/bitmap.h> | ||
23 | #include <linux/module.h> | 24 | #include <linux/module.h> |
24 | #include <linux/slab.h> | 25 | #include <linux/slab.h> |
25 | #include <media/media-entity.h> | 26 | #include <media/media-entity.h> |
@@ -121,7 +122,6 @@ static struct media_entity *stack_pop(struct media_entity_graph *graph) | |||
121 | return entity; | 122 | return entity; |
122 | } | 123 | } |
123 | 124 | ||
124 | #define stack_peek(en) ((en)->stack[(en)->top - 1].entity) | ||
125 | #define link_top(en) ((en)->stack[(en)->top].link) | 125 | #define link_top(en) ((en)->stack[(en)->top].link) |
126 | #define stack_top(en) ((en)->stack[(en)->top].entity) | 126 | #define stack_top(en) ((en)->stack[(en)->top].entity) |
127 | 127 | ||
@@ -140,6 +140,12 @@ void media_entity_graph_walk_start(struct media_entity_graph *graph, | |||
140 | { | 140 | { |
141 | graph->top = 0; | 141 | graph->top = 0; |
142 | graph->stack[graph->top].entity = NULL; | 142 | graph->stack[graph->top].entity = NULL; |
143 | bitmap_zero(graph->entities, MEDIA_ENTITY_ENUM_MAX_ID); | ||
144 | |||
145 | if (WARN_ON(entity->id >= MEDIA_ENTITY_ENUM_MAX_ID)) | ||
146 | return; | ||
147 | |||
148 | __set_bit(entity->id, graph->entities); | ||
143 | stack_push(graph, entity); | 149 | stack_push(graph, entity); |
144 | } | 150 | } |
145 | EXPORT_SYMBOL_GPL(media_entity_graph_walk_start); | 151 | EXPORT_SYMBOL_GPL(media_entity_graph_walk_start); |
@@ -180,9 +186,11 @@ media_entity_graph_walk_next(struct media_entity_graph *graph) | |||
180 | 186 | ||
181 | /* Get the entity in the other end of the link . */ | 187 | /* Get the entity in the other end of the link . */ |
182 | next = media_entity_other(entity, link); | 188 | next = media_entity_other(entity, link); |
189 | if (WARN_ON(next->id >= MEDIA_ENTITY_ENUM_MAX_ID)) | ||
190 | return NULL; | ||
183 | 191 | ||
184 | /* Was it the entity we came here from? */ | 192 | /* Has the entity already been visited? */ |
185 | if (next == stack_peek(graph)) { | 193 | if (__test_and_set_bit(next->id, graph->entities)) { |
186 | link_top(graph)++; | 194 | link_top(graph)++; |
187 | continue; | 195 | continue; |
188 | } | 196 | } |