summaryrefslogtreecommitdiff
path: root/drivers/media/usb/cx231xx/cx231xx-cards.c
diff options
context:
space:
mode:
authorJavier Martinez Canillas <javier@osg.samsung.com>2015-12-11 20:57:08 -0200
committerMauro Carvalho Chehab <mchehab@osg.samsung.com>2016-01-11 12:19:15 -0200
commit9832e155f1ed3030fdfaa19e72c06472dc2ecb1d (patch)
treefe787b9bd8804b7094ba797897e77ed60077a5e3 /drivers/media/usb/cx231xx/cx231xx-cards.c
parent821ed3662913faca0653c201fa9e36fbab81f17c (diff)
[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 'drivers/media/usb/cx231xx/cx231xx-cards.c')
-rw-r--r--drivers/media/usb/cx231xx/cx231xx-cards.c32
1 files changed, 16 insertions, 16 deletions
diff --git a/drivers/media/usb/cx231xx/cx231xx-cards.c b/drivers/media/usb/cx231xx/cx231xx-cards.c
index 0e1efc59ff58..de0026b5265c 100644
--- a/drivers/media/usb/cx231xx/cx231xx-cards.c
+++ b/drivers/media/usb/cx231xx/cx231xx-cards.c
@@ -1172,6 +1172,7 @@ static void cx231xx_unregister_media_device(struct cx231xx *dev)
#ifdef CONFIG_MEDIA_CONTROLLER
if (dev->media_dev) {
media_device_unregister(dev->media_dev);
+ media_device_cleanup(dev->media_dev);
kfree(dev->media_dev);
dev->media_dev = NULL;
}
@@ -1205,12 +1206,11 @@ void cx231xx_release_resources(struct cx231xx *dev)
clear_bit(dev->devno, &cx231xx_devused);
}
-static void cx231xx_media_device_register(struct cx231xx *dev,
- struct usb_device *udev)
+static void cx231xx_media_device_init(struct cx231xx *dev,
+ struct usb_device *udev)
{
#ifdef CONFIG_MEDIA_CONTROLLER
struct media_device *mdev;
- int ret;
mdev = kzalloc(sizeof(*mdev), GFP_KERNEL);
if (!mdev)
@@ -1224,14 +1224,7 @@ static void cx231xx_media_device_register(struct cx231xx *dev,
mdev->hw_revision = le16_to_cpu(udev->descriptor.bcdDevice);
mdev->driver_version = LINUX_VERSION_CODE;
- ret = media_device_register(mdev);
- if (ret) {
- dev_err(dev->dev,
- "Couldn't create a media device. Error: %d\n",
- ret);
- kfree(mdev);
- return;
- }
+ media_device_init(mdev);
dev->media_dev = mdev;
#endif
@@ -1669,8 +1662,8 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
/* save our data pointer in this interface device */
usb_set_intfdata(interface, dev);
- /* Register the media controller */
- cx231xx_media_device_register(dev, udev);
+ /* Initialize the media controller */
+ cx231xx_media_device_init(dev, udev);
/* Create v4l2 device */
#ifdef CONFIG_MEDIA_CONTROLLER
@@ -1742,11 +1735,18 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
request_modules(dev);
retval = cx231xx_create_media_graph(dev);
- if (retval < 0) {
- cx231xx_release_resources(dev);
- }
+ if (retval < 0)
+ goto done;
+
+#ifdef CONFIG_MEDIA_CONTROLLER
+ retval = media_device_register(dev->media_dev);
+#endif
+done:
+ if (retval < 0)
+ cx231xx_release_resources(dev);
return retval;
+
err_video_alt:
/* cx231xx_uninit_dev: */
cx231xx_close_extension(dev);