summaryrefslogtreecommitdiff
path: root/drivers/media/usb/au0828
diff options
context:
space:
mode:
authorJavier Martinez Canillas <javier@osg.samsung.com>2015-12-12 01:57:08 +0300
committerMauro Carvalho Chehab <mchehab@osg.samsung.com>2016-01-11 17:19:15 +0300
commit9832e155f1ed3030fdfaa19e72c06472dc2ecb1d (patch)
treefe787b9bd8804b7094ba797897e77ed60077a5e3 /drivers/media/usb/au0828
parent821ed3662913faca0653c201fa9e36fbab81f17c (diff)
downloadlinux-9832e155f1ed3030fdfaa19e72c06472dc2ecb1d.tar.xz
[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/au0828')
-rw-r--r--drivers/media/usb/au0828/au0828-core.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/drivers/media/usb/au0828/au0828-core.c b/drivers/media/usb/au0828/au0828-core.c
index 1b207fa16a55..fbdaeb206565 100644
--- a/drivers/media/usb/au0828/au0828-core.c
+++ b/drivers/media/usb/au0828/au0828-core.c
@@ -136,6 +136,7 @@ static void au0828_unregister_media_device(struct au0828_dev *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;
}
@@ -216,12 +217,11 @@ static void au0828_usb_disconnect(struct usb_interface *interface)
au0828_usb_release(dev);
}
-static void au0828_media_device_register(struct au0828_dev *dev,
- struct usb_device *udev)
+static void au0828_media_device_init(struct au0828_dev *dev,
+ struct usb_device *udev)
{
#ifdef CONFIG_MEDIA_CONTROLLER
struct media_device *mdev;
- int ret;
mdev = kzalloc(sizeof(*mdev), GFP_KERNEL);
if (!mdev)
@@ -239,14 +239,7 @@ static void au0828_media_device_register(struct au0828_dev *dev,
mdev->hw_revision = le16_to_cpu(udev->descriptor.bcdDevice);
mdev->driver_version = LINUX_VERSION_CODE;
- ret = media_device_register(mdev);
- if (ret) {
- pr_err(
- "Couldn't create a media device. Error: %d\n",
- ret);
- kfree(mdev);
- return;
- }
+ media_device_init(mdev);
dev->media_dev = mdev;
#endif
@@ -374,8 +367,8 @@ static int au0828_usb_probe(struct usb_interface *interface,
dev->boardnr = id->driver_info;
dev->board = au0828_boards[dev->boardnr];
- /* Register the media controller */
- au0828_media_device_register(dev, usbdev);
+ /* Initialize the media controller */
+ au0828_media_device_init(dev, usbdev);
#ifdef CONFIG_VIDEO_AU0828_V4L2
dev->v4l2_dev.release = au0828_usb_v4l2_release;
@@ -446,9 +439,17 @@ static int au0828_usb_probe(struct usb_interface *interface,
if (retval) {
pr_err("%s() au0282_dev_register failed to create graph\n",
__func__);
- au0828_usb_disconnect(interface);
+ goto done;
}
+#ifdef CONFIG_MEDIA_CONTROLLER
+ retval = media_device_register(dev->media_dev);
+#endif
+
+done:
+ if (retval < 0)
+ au0828_usb_disconnect(interface);
+
return retval;
}