[media] media: au0828 - embed vdev and vbi_dev structs in au0828_dev
authorShuah Khan <shuahkh@osg.samsung.com>
Thu, 26 Feb 2015 22:33:13 +0000 (19:33 -0300)
committerMauro Carvalho Chehab <mchehab@osg.samsung.com>
Tue, 3 Mar 2015 14:19:52 +0000 (11:19 -0300)
Embed video_device structs vdev and vbi_dev in au0828_dev.
With this change, dynamic allocation and error path logic
in au0828_analog_register() is removed as it doesn't need
to allocate and handle allocation errors. Unregister path
doesn't need to free the now static video_device structures,
hence, changed video_device.release in au0828_video_template
to point to video_device_release_empty.

Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
drivers/media/usb/au0828/au0828-video.c
drivers/media/usb/au0828/au0828.h

index 61e525fcdcc3b0377cf03e37cbcc27cb2282d8d9..bf990a931d4ef59de57f85adb7c649242273eaa0 100644 (file)
@@ -891,8 +891,8 @@ void au0828_analog_unregister(struct au0828_dev *dev)
 {
        dprintk(1, "au0828_analog_unregister called\n");
        mutex_lock(&au0828_sysfs_lock);
-       video_unregister_device(dev->vdev);
-       video_unregister_device(dev->vbi_dev);
+       video_unregister_device(&dev->vdev);
+       video_unregister_device(&dev->vbi_dev);
        mutex_unlock(&au0828_sysfs_lock);
 }
 
@@ -1274,7 +1274,7 @@ static int vidioc_enum_input(struct file *file, void *priv,
                input->audioset = 2;
        }
 
-       input->std = dev->vdev->tvnorms;
+       input->std = dev->vdev.tvnorms;
 
        return 0;
 }
@@ -1692,7 +1692,7 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
 
 static const struct video_device au0828_video_template = {
        .fops                       = &au0828_v4l_fops,
-       .release                    = video_device_release,
+       .release                    = video_device_release_empty,
        .ioctl_ops                  = &video_ioctl_ops,
        .tvnorms                    = V4L2_STD_NTSC_M | V4L2_STD_PAL_M,
 };
@@ -1802,52 +1802,36 @@ int au0828_analog_register(struct au0828_dev *dev,
        dev->std = V4L2_STD_NTSC_M;
        au0828_s_input(dev, 0);
 
-       /* allocate and fill v4l2 video struct */
-       dev->vdev = video_device_alloc();
-       if (NULL == dev->vdev) {
-               dprintk(1, "Can't allocate video_device.\n");
-               return -ENOMEM;
-       }
-
-       /* allocate the VBI struct */
-       dev->vbi_dev = video_device_alloc();
-       if (NULL == dev->vbi_dev) {
-               dprintk(1, "Can't allocate vbi_device.\n");
-               ret = -ENOMEM;
-               goto err_vdev;
-       }
-
        mutex_init(&dev->vb_queue_lock);
        mutex_init(&dev->vb_vbi_queue_lock);
 
        /* Fill the video capture device struct */
-       *dev->vdev = au0828_video_template;
-       dev->vdev->v4l2_dev = &dev->v4l2_dev;
-       dev->vdev->lock = &dev->lock;
-       dev->vdev->queue = &dev->vb_vidq;
-       dev->vdev->queue->lock = &dev->vb_queue_lock;
-       strcpy(dev->vdev->name, "au0828a video");
+       dev->vdev = au0828_video_template;
+       dev->vdev.v4l2_dev = &dev->v4l2_dev;
+       dev->vdev.lock = &dev->lock;
+       dev->vdev.queue = &dev->vb_vidq;
+       dev->vdev.queue->lock = &dev->vb_queue_lock;
+       strcpy(dev->vdev.name, "au0828a video");
 
        /* Setup the VBI device */
-       *dev->vbi_dev = au0828_video_template;
-       dev->vbi_dev->v4l2_dev = &dev->v4l2_dev;
-       dev->vbi_dev->lock = &dev->lock;
-       dev->vbi_dev->queue = &dev->vb_vbiq;
-       dev->vbi_dev->queue->lock = &dev->vb_vbi_queue_lock;
-       strcpy(dev->vbi_dev->name, "au0828a vbi");
+       dev->vbi_dev = au0828_video_template;
+       dev->vbi_dev.v4l2_dev = &dev->v4l2_dev;
+       dev->vbi_dev.lock = &dev->lock;
+       dev->vbi_dev.queue = &dev->vb_vbiq;
+       dev->vbi_dev.queue->lock = &dev->vb_vbi_queue_lock;
+       strcpy(dev->vbi_dev.name, "au0828a vbi");
 
        /* initialize videobuf2 stuff */
        retval = au0828_vb2_setup(dev);
        if (retval != 0) {
                dprintk(1, "unable to setup videobuf2 queues (error = %d).\n",
                        retval);
-               ret = -ENODEV;
-               goto err_vbi_dev;
+               return -ENODEV;
        }
 
        /* Register the v4l2 device */
-       video_set_drvdata(dev->vdev, dev);
-       retval = video_register_device(dev->vdev, VFL_TYPE_GRABBER, -1);
+       video_set_drvdata(&dev->vdev, dev);
+       retval = video_register_device(&dev->vdev, VFL_TYPE_GRABBER, -1);
        if (retval != 0) {
                dprintk(1, "unable to register video device (error = %d).\n",
                        retval);
@@ -1856,8 +1840,8 @@ int au0828_analog_register(struct au0828_dev *dev,
        }
 
        /* Register the vbi device */
-       video_set_drvdata(dev->vbi_dev, dev);
-       retval = video_register_device(dev->vbi_dev, VFL_TYPE_VBI, -1);
+       video_set_drvdata(&dev->vbi_dev, dev);
+       retval = video_register_device(&dev->vbi_dev, VFL_TYPE_VBI, -1);
        if (retval != 0) {
                dprintk(1, "unable to register vbi device (error = %d).\n",
                        retval);
@@ -1870,14 +1854,10 @@ int au0828_analog_register(struct au0828_dev *dev,
        return 0;
 
 err_reg_vbi_dev:
-       video_unregister_device(dev->vdev);
+       video_unregister_device(&dev->vdev);
 err_reg_vdev:
        vb2_queue_release(&dev->vb_vidq);
        vb2_queue_release(&dev->vb_vbiq);
-err_vbi_dev:
-       video_device_release(dev->vbi_dev);
-err_vdev:
-       video_device_release(dev->vdev);
        return ret;
 }
 
index eb1518742ae627f9f192f618fd4bc648e373129b..3b480005ce3be6576fd83348e016af8688b990fc 100644 (file)
@@ -209,8 +209,8 @@ struct au0828_dev {
        struct au0828_rc *ir;
 #endif
 
-       struct video_device *vdev;
-       struct video_device *vbi_dev;
+       struct video_device vdev;
+       struct video_device vbi_dev;
 
        /* Videobuf2 */
        struct vb2_queue vb_vidq;