diff options
author | Hans Verkuil <hverkuil@xs4all.nl> | 2011-01-08 09:36:04 -0300 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2011-03-22 16:37:57 -0300 |
commit | 73cb42068cff419e72456940c713ceb5efa68c2a (patch) | |
tree | 2e2cfa9f87b584774a7dc496ec6b46431bd7ce56 /drivers/media/video/v4l2-fh.c | |
parent | fc5602be7ca5b55174c5d6595089718779b28dfa (diff) |
[media] v4l2-fh: add v4l2_fh_open and v4l2_fh_release helper functions
Add two new functions: v4l2_fh_open allocates and initializes a struct v4l2_fh
based on a struct file pointer and v4l2_fh_release releases and frees a struct
v4l2_fh.
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/v4l2-fh.c')
-rw-r--r-- | drivers/media/video/v4l2-fh.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/drivers/media/video/v4l2-fh.c b/drivers/media/video/v4l2-fh.c index 78a1608a09d6..27242e5ca431 100644 --- a/drivers/media/video/v4l2-fh.c +++ b/drivers/media/video/v4l2-fh.c @@ -23,6 +23,7 @@ */ #include <linux/bitops.h> +#include <linux/slab.h> #include <media/v4l2-dev.h> #include <media/v4l2-fh.h> #include <media/v4l2-event.h> @@ -60,6 +61,20 @@ void v4l2_fh_add(struct v4l2_fh *fh) } EXPORT_SYMBOL_GPL(v4l2_fh_add); +int v4l2_fh_open(struct file *filp) +{ + struct video_device *vdev = video_devdata(filp); + struct v4l2_fh *fh = kzalloc(sizeof(*fh), GFP_KERNEL); + + filp->private_data = fh; + if (fh == NULL) + return -ENOMEM; + v4l2_fh_init(fh, vdev); + v4l2_fh_add(fh); + return 0; +} +EXPORT_SYMBOL_GPL(v4l2_fh_open); + void v4l2_fh_del(struct v4l2_fh *fh) { unsigned long flags; @@ -81,3 +96,16 @@ void v4l2_fh_exit(struct v4l2_fh *fh) v4l2_event_free(fh); } EXPORT_SYMBOL_GPL(v4l2_fh_exit); + +int v4l2_fh_release(struct file *filp) +{ + struct v4l2_fh *fh = filp->private_data; + + if (fh) { + v4l2_fh_del(fh); + v4l2_fh_exit(fh); + kfree(fh); + } + return 0; +} +EXPORT_SYMBOL_GPL(v4l2_fh_release); |