[PATCH v3 15/22] media: au0828 handle media_init and media_register window

From: Shuah Khan
Date: Thu Feb 11 2016 - 18:47:40 EST


Media device initialization and registration
steps are split. There is a window between
media device init and media device register
during usb probe.

au0828 bridge driver and snd-usb-audio could
try to initialize the media device, if they
simply checked, whether the device has been
registered. They also need to check whether
the device has been initialized.

Change the au0828-core to check if media device
is already initialized during initialization step
and check if media device is already registered
during the registration step.

Signed-off-by: Shuah Khan <shuahkh@xxxxxxxxxxxxxxx>
---
drivers/media/usb/au0828/au0828-core.c | 26 ++++++++++++++++++++++++--
1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/drivers/media/usb/au0828/au0828-core.c b/drivers/media/usb/au0828/au0828-core.c
index a740bea..99f8022 100644
--- a/drivers/media/usb/au0828/au0828-core.c
+++ b/drivers/media/usb/au0828/au0828-core.c
@@ -228,7 +228,8 @@ static int au0828_media_device_init(struct au0828_dev *dev,
if (!mdev)
return -ENOMEM;

- if (!media_devnode_is_registered(&mdev->devnode)) {
+ /* check if media device is already initialized */
+ if (!mdev->dev) {
mdev->dev = &udev->dev;

if (udev->product)
@@ -328,6 +329,27 @@ static int au0828_create_media_graph(struct au0828_dev *dev)
return 0;
}

+static int au0828_media_device_register(struct au0828_dev *dev,
+ struct usb_device *udev)
+{
+#ifdef CONFIG_MEDIA_CONTROLLER
+ int ret;
+
+ if (dev->media_dev &&
+ !media_devnode_is_registered(&dev->media_dev->devnode)) {
+
+ /* register media device */
+ ret = media_device_register(dev->media_dev);
+ if (ret) {
+ dev_err(&udev->dev,
+ "Media Device Register Error: %d\n", ret);
+ return ret;
+ }
+ }
+#endif
+ return 0;
+}
+
static int au0828_usb_probe(struct usb_interface *interface,
const struct usb_device_id *id)
{
@@ -455,7 +477,7 @@ static int au0828_usb_probe(struct usb_interface *interface,
}

#ifdef CONFIG_MEDIA_CONTROLLER
- retval = media_device_register(dev->media_dev);
+ retval = au0828_media_device_register(dev, usbdev);
#endif

done:
--
2.5.0