media: entity: Add lockdep check to media graph walk
authorSakari Ailus <sakari.ailus@linux.intel.com>
Fri, 12 Mar 2021 09:05:44 +0000 (10:05 +0100)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Tue, 6 Apr 2021 12:35:14 +0000 (14:35 +0200)
It was always assumed that walking the media graph would require holding
the media_device graph_mutex but this was not documented nor checked for.

Add a lockdep check to graph walk init and iter, and document the need for
acquiring the graph_mutex.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
drivers/media/mc/mc-entity.c
include/media/media-entity.h

index 12b45e6..678b997 100644 (file)
@@ -340,6 +340,7 @@ static void media_graph_walk_iter(struct media_graph *graph)
        stack_push(graph, next);
        dev_dbg(entity->graph_obj.mdev->dev, "walk: pushing '%s' on stack\n",
                next->name);
+       lockdep_assert_held(&entity->graph_obj.mdev->graph_mutex);
 }
 
 struct media_entity *media_graph_walk_next(struct media_graph *graph)
index a90e2bf..09737b4 100644 (file)
@@ -885,6 +885,11 @@ int media_entity_get_fwnode_pad(struct media_entity *entity,
  *
  * @graph: Media graph structure that will be used to walk the graph
  * @mdev: Pointer to the &media_device that contains the object
+ *
+ * The caller is required to hold the media_device graph_mutex during the graph
+ * walk until the graph state is released.
+ *
+ * Returns zero on success or a negative error code otherwise.
  */
 __must_check int media_graph_walk_init(
        struct media_graph *graph, struct media_device *mdev);