aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Verkuil <hverkuil@xs4all.nl>2011-01-08 07:36:04 -0500
committerMauro Carvalho Chehab <mchehab@redhat.com>2011-03-22 15:37:57 -0400
commit73cb42068cff419e72456940c713ceb5efa68c2a (patch)
tree2e2cfa9f87b584774a7dc496ec6b46431bd7ce56
parentfc5602be7ca5b55174c5d6595089718779b28dfa (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>
-rw-r--r--drivers/media/video/v4l2-fh.c28
-rw-r--r--include/media/v4l2-fh.h15
2 files changed, 43 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 @@
23 */ 23 */
24 24
25#include <linux/bitops.h> 25#include <linux/bitops.h>
26#include <linux/slab.h>
26#include <media/v4l2-dev.h> 27#include <media/v4l2-dev.h>
27#include <media/v4l2-fh.h> 28#include <media/v4l2-fh.h>
28#include <media/v4l2-event.h> 29#include <media/v4l2-event.h>
@@ -60,6 +61,20 @@ void v4l2_fh_add(struct v4l2_fh *fh)
60} 61}
61EXPORT_SYMBOL_GPL(v4l2_fh_add); 62EXPORT_SYMBOL_GPL(v4l2_fh_add);
62 63
64int v4l2_fh_open(struct file *filp)
65{
66 struct video_device *vdev = video_devdata(filp);
67 struct v4l2_fh *fh = kzalloc(sizeof(*fh), GFP_KERNEL);
68
69 filp->private_data = fh;
70 if (fh == NULL)
71 return -ENOMEM;
72 v4l2_fh_init(fh, vdev);
73 v4l2_fh_add(fh);
74 return 0;
75}
76EXPORT_SYMBOL_GPL(v4l2_fh_open);
77
63void v4l2_fh_del(struct v4l2_fh *fh) 78void v4l2_fh_del(struct v4l2_fh *fh)
64{ 79{
65 unsigned long flags; 80 unsigned long flags;
@@ -81,3 +96,16 @@ void v4l2_fh_exit(struct v4l2_fh *fh)
81 v4l2_event_free(fh); 96 v4l2_event_free(fh);
82} 97}
83EXPORT_SYMBOL_GPL(v4l2_fh_exit); 98EXPORT_SYMBOL_GPL(v4l2_fh_exit);
99
100int v4l2_fh_release(struct file *filp)
101{
102 struct v4l2_fh *fh = filp->private_data;
103
104 if (fh) {
105 v4l2_fh_del(fh);
106 v4l2_fh_exit(fh);
107 kfree(fh);
108 }
109 return 0;
110}
111EXPORT_SYMBOL_GPL(v4l2_fh_release);
diff --git a/include/media/v4l2-fh.h b/include/media/v4l2-fh.h
index 5fc5ba96e1d2..5657881cd44e 100644
--- a/include/media/v4l2-fh.h
+++ b/include/media/v4l2-fh.h
@@ -51,8 +51,16 @@ int v4l2_fh_init(struct v4l2_fh *fh, struct video_device *vdev);
51 */ 51 */
52void v4l2_fh_add(struct v4l2_fh *fh); 52void v4l2_fh_add(struct v4l2_fh *fh);
53/* 53/*
54 * Can be used as the open() op of v4l2_file_operations.
55 * It allocates a v4l2_fh and inits and adds it to the video_device associated
56 * with the file pointer.
57 */
58int v4l2_fh_open(struct file *filp);
59/*
54 * Remove file handle from the list of file handles. Must be called in 60 * Remove file handle from the list of file handles. Must be called in
55 * v4l2_file_operations->release() handler if the driver uses v4l2_fh. 61 * v4l2_file_operations->release() handler if the driver uses v4l2_fh.
62 * On error filp->private_data will be NULL, otherwise it will point to
63 * the v4l2_fh struct.
56 */ 64 */
57void v4l2_fh_del(struct v4l2_fh *fh); 65void v4l2_fh_del(struct v4l2_fh *fh);
58/* 66/*
@@ -62,5 +70,12 @@ void v4l2_fh_del(struct v4l2_fh *fh);
62 * driver uses v4l2_fh. 70 * driver uses v4l2_fh.
63 */ 71 */
64void v4l2_fh_exit(struct v4l2_fh *fh); 72void v4l2_fh_exit(struct v4l2_fh *fh);
73/*
74 * Can be used as the release() op of v4l2_file_operations.
75 * It deletes and exits the v4l2_fh associated with the file pointer and
76 * frees it. It will do nothing if filp->private_data (the pointer to the
77 * v4l2_fh struct) is NULL. This function always returns 0.
78 */
79int v4l2_fh_release(struct file *filp);
65 80
66#endif /* V4L2_EVENT_H */ 81#endif /* V4L2_EVENT_H */