summaryrefslogtreecommitdiffstats
path: root/include/media
diff options
context:
space:
mode:
authorJavier Martinez Canillas <javier@osg.samsung.com>2015-12-11 23:57:08 +0100
committerMauro Carvalho Chehab <mchehab@osg.samsung.com>2016-01-11 15:19:15 +0100
commit9832e155f1ed3030fdfaa19e72c06472dc2ecb1d (patch)
treefe787b9bd8804b7094ba797897e77ed60077a5e3 /include/media
parent[media] media-device: better lock media_device_unregister() (diff)
downloadlinux-9832e155f1ed3030fdfaa19e72c06472dc2ecb1d.tar.xz
linux-9832e155f1ed3030fdfaa19e72c06472dc2ecb1d.zip
[media] media-device: split media initialization and registration
The media device node is registered and so made visible to user-space before entities are registered and links created which means that the media graph obtained by user-space could be only partially enumerated if that happens too early before all the graph has been created. To avoid this race condition, split the media init and registration in separate functions and only register the media device node when all the pending subdevices have been registered, either explicitly by the driver or asynchronously using v4l2_async_register_subdev(). The media_device_register() had a check for drivers not filling dev and model fields but all drivers in mainline set them and not doing it will be a driver bug so change the function return to void and add a BUG_ON() for dev being NULL instead. Also, add a media_device_cleanup() function that will destroy the graph_mutex that is initialized in media_device_init(). [mchehab@osg.samsung.com: Fix compilation if !CONFIG_MEDIA_CONTROLLER and remove two warnings added by this changeset] Suggested-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com> Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Diffstat (limited to 'include/media')
-rw-r--r--include/media/media-device.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/include/media/media-device.h b/include/media/media-device.h
index ebc2f3a239eb..e01bbc427fcd 100644
--- a/include/media/media-device.h
+++ b/include/media/media-device.h
@@ -338,6 +338,32 @@ struct media_device {
#define to_media_device(node) container_of(node, struct media_device, devnode)
/**
+ * media_device_init() - Initializes a media device element
+ *
+ * @mdev: pointer to struct &media_device
+ *
+ * This function initializes the media device prior to its registration.
+ * The media device initialization and registration is split in two functions
+ * to avoid race conditions and make the media device available to user-space
+ * before the media graph has been completed.
+ *
+ * So drivers need to first initialize the media device, register any entity
+ * within the media device, create pad to pad links and then finally register
+ * the media device by calling media_device_register() as a final step.
+ */
+void media_device_init(struct media_device *mdev);
+
+/**
+ * media_device_cleanup() - Cleanups a media device element
+ *
+ * @mdev: pointer to struct &media_device
+ *
+ * This function that will destroy the graph_mutex that is
+ * initialized in media_device_init().
+ */
+void media_device_cleanup(struct media_device *mdev);
+
+/**
* __media_device_register() - Registers a media device element
*
* @mdev: pointer to struct &media_device