Skip to content

Commit

Permalink
[media] vivi: embed struct video_device instead of allocating it
Browse files Browse the repository at this point in the history
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
  • Loading branch information
Hans Verkuil authored and Mauro Carvalho Chehab committed Jul 6, 2012
1 parent 4e1d2ac commit 70bd97a
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions drivers/media/video/vivi.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ struct vivi_dev {
struct list_head vivi_devlist;
struct v4l2_device v4l2_dev;
struct v4l2_ctrl_handler ctrl_handler;
struct video_device vdev;

/* controls */
struct v4l2_ctrl *brightness;
Expand All @@ -213,9 +214,6 @@ struct vivi_dev {
spinlock_t slock;
struct mutex mutex;

/* various device info */
struct video_device *vfd;

struct vivi_dmaqueue vidq;

/* Several counters */
Expand Down Expand Up @@ -1326,7 +1324,7 @@ static struct video_device vivi_template = {
.name = "vivi",
.fops = &vivi_fops,
.ioctl_ops = &vivi_ioctl_ops,
.release = video_device_release,
.release = video_device_release_empty,
};

/* -----------------------------------------------------------------
Expand All @@ -1344,8 +1342,8 @@ static int vivi_release(void)
dev = list_entry(list, struct vivi_dev, vivi_devlist);

v4l2_info(&dev->v4l2_dev, "unregistering %s\n",
video_device_node_name(dev->vfd));
video_unregister_device(dev->vfd);
video_device_node_name(&dev->vdev));
video_unregister_device(&dev->vdev);
v4l2_device_unregister(&dev->v4l2_dev);
v4l2_ctrl_handler_free(&dev->ctrl_handler);
kfree(dev);
Expand Down Expand Up @@ -1430,11 +1428,7 @@ static int __init vivi_create_instance(int inst)
INIT_LIST_HEAD(&dev->vidq.active);
init_waitqueue_head(&dev->vidq.wq);

ret = -ENOMEM;
vfd = video_device_alloc();
if (!vfd)
goto unreg_dev;

vfd = &dev->vdev;
*vfd = vivi_template;
vfd->debug = debug;
vfd->v4l2_dev = &dev->v4l2_dev;
Expand All @@ -1445,26 +1439,22 @@ static int __init vivi_create_instance(int inst)
* all fops and v4l2 ioctls.
*/
vfd->lock = &dev->mutex;
video_set_drvdata(vfd, dev);

ret = video_register_device(vfd, VFL_TYPE_GRABBER, video_nr);
if (ret < 0)
goto rel_vdev;

video_set_drvdata(vfd, dev);
goto unreg_dev;

/* Now that everything is fine, let's add it to device list */
list_add_tail(&dev->vivi_devlist, &vivi_devlist);

if (video_nr != -1)
video_nr++;

dev->vfd = vfd;
v4l2_info(&dev->v4l2_dev, "V4L2 device registered as %s\n",
video_device_node_name(vfd));
return 0;

rel_vdev:
video_device_release(vfd);
unreg_dev:
v4l2_ctrl_handler_free(hdl);
v4l2_device_unregister(&dev->v4l2_dev);
Expand Down

0 comments on commit 70bd97a

Please sign in to comment.